aboutsummaryrefslogtreecommitdiff
path: root/corepkgs
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-11-19 17:27:16 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-11-19 17:27:16 +0000
commit9898746ef3732979bf30e9048021b6232ddf15ac (patch)
tree77f1391387f0e28f5495104fed3e4227bbeb4af3 /corepkgs
parentfd7ac09f1073179d9ac439c3e9fb12a1bf00a7d5 (diff)
* nix-env: a tool to manage user environments.
* Replace all directory reading code by a generic readDirectory() function.
Diffstat (limited to 'corepkgs')
-rwxr-xr-xcorepkgs/buildenv/builder.pl72
-rw-r--r--corepkgs/buildenv/default.nix9
2 files changed, 81 insertions, 0 deletions
diff --git a/corepkgs/buildenv/builder.pl b/corepkgs/buildenv/builder.pl
new file mode 100755
index 000000000..144ad3374
--- /dev/null
+++ b/corepkgs/buildenv/builder.pl
@@ -0,0 +1,72 @@
+#! /usr/bin/perl -w
+
+use strict;
+use Cwd;
+
+my $selfdir = $ENV{"out"};
+mkdir "$selfdir", 0755 || die "error creating $selfdir";
+
+# For each activated package, create symlinks.
+
+sub createLinks {
+ my $srcdir = shift;
+ my $dstdir = shift;
+
+ my @srcfiles = glob("$srcdir/*");
+
+ foreach my $srcfile (@srcfiles) {
+ my $basename = $srcfile;
+ $basename =~ s/^.*\///g; # strip directory
+ my $dstfile = "$dstdir/$basename";
+ if ($srcfile =~ /\/envpkgs$/) {
+ } elsif (-d $srcfile) {
+ # !!! hack for resolving name clashes
+ if (!-e $dstfile) {
+ mkdir $dstfile, 0755 ||
+ die "error creating directory $dstfile";
+ }
+ -d $dstfile or die "$dstfile is not a directory";
+ createLinks($srcfile, $dstfile);
+ } elsif (-l $dstfile) {
+ my $target = readlink($dstfile);
+ die "collission between $srcfile and $target";
+ } else {
+# print "linking $dstfile to $srcfile\n";
+ symlink($srcfile, $dstfile) ||
+ die "error creating link $dstfile";
+ }
+ }
+}
+
+my %done;
+
+sub addPkg {
+ my $pkgdir = shift;
+
+ return if (defined $done{$pkgdir});
+ $done{$pkgdir} = 1;
+
+# print "merging $pkgdir\n";
+
+ createLinks("$pkgdir", "$selfdir");
+
+# if (-f "$pkgdir/envpkgs") {
+# my $envpkgs = `cat $pkgdir/envpkgs`;
+# chomp $envpkgs;
+# my @envpkgs = split / +/, $envpkgs;
+# foreach my $envpkg (@envpkgs) {
+# addPkg($envpkg);
+# }
+# }
+}
+
+my @args = split ' ', $ENV{"derivations"};
+
+while (scalar @args > 0) {
+ my $drvpath = shift @args;
+ print "adding $drvpath\n";
+ addPkg($drvpath);
+}
+
+symlink($ENV{"manifest"}, "$selfdir/manifest") or die "cannot create manifest";
+
diff --git a/corepkgs/buildenv/default.nix b/corepkgs/buildenv/default.nix
new file mode 100644
index 000000000..9bc704d8d
--- /dev/null
+++ b/corepkgs/buildenv/default.nix
@@ -0,0 +1,9 @@
+{system, derivations, manifest}:
+
+derivation {
+ name = "user-environment";
+ system = system;
+ builder = ./builder.pl;
+ derivations = derivations;
+ manifest = manifest;
+}