From 48cea0d01ef48733ab38a73a20611f63aeb1b5cc Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 3 Jan 2012 00:16:29 +0000 Subject: * Refactoring: Get rid of a few subdirectories in corepkgs/, and some other simplifications. * Use to locate the corepkgs. This allows them to be overriden through $NIX_PATH. * Use bash's pipefail option in the NAR builder so that we don't need to create a temporary file. --- corepkgs/Makefile.am | 12 ++- corepkgs/buildenv.nix | 21 +++++ corepkgs/buildenv.pl | 169 +++++++++++++++++++++++++++++++++++++++ corepkgs/buildenv/Makefile.am | 11 --- corepkgs/buildenv/builder.pl.in | 171 ---------------------------------------- corepkgs/buildenv/default.nix | 18 ----- corepkgs/nar.nix | 30 +++++++ corepkgs/nar/Makefile.am | 11 --- corepkgs/nar/nar.nix | 7 -- corepkgs/nar/nar.sh.in | 12 --- 10 files changed, 231 insertions(+), 231 deletions(-) create mode 100644 corepkgs/buildenv.nix create mode 100644 corepkgs/buildenv.pl delete mode 100644 corepkgs/buildenv/Makefile.am delete mode 100755 corepkgs/buildenv/builder.pl.in delete mode 100644 corepkgs/buildenv/default.nix create mode 100644 corepkgs/nar.nix delete mode 100644 corepkgs/nar/Makefile.am delete mode 100644 corepkgs/nar/nar.nix delete mode 100644 corepkgs/nar/nar.sh.in (limited to 'corepkgs') diff --git a/corepkgs/Makefile.am b/corepkgs/Makefile.am index b303a30eba4a..7f43a700e734 100644 --- a/corepkgs/Makefile.am +++ b/corepkgs/Makefile.am @@ -1 +1,11 @@ -SUBDIRS = nar buildenv channels +SUBDIRS = channels + +all-local: config.nix + +install-exec-local: + $(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs + $(INSTALL_DATA) config.nix $(srcdir)/nar.nix $(srcdir)/buildenv.nix $(srcdir)/buildenv.pl $(DESTDIR)$(datadir)/nix/corepkgs + +include ../substitute.mk + +EXTRA_DIST = config.nix.in nar.nix buildenv.nix buildenv.pl diff --git a/corepkgs/buildenv.nix b/corepkgs/buildenv.nix new file mode 100644 index 000000000000..6e2bee10b1e7 --- /dev/null +++ b/corepkgs/buildenv.nix @@ -0,0 +1,21 @@ +with import ; + +{ system, derivations, manifest }: + +derivation { + name = "user-environment"; + system = system; + builder = perl; + args = [ "-w" ./buildenv.pl ]; + + manifest = manifest; + + # !!! grmbl, need structured data for passing this in a clean way. + paths = derivations; + active = map (x: if x ? meta && x.meta ? active then x.meta.active else "true") derivations; + priority = map (x: if x ? meta && x.meta ? priority then x.meta.priority else "5") derivations; + + # Building user environments remotely just causes huge amounts of + # network traffic, so don't do that. + preferLocalBuild = true; +} diff --git a/corepkgs/buildenv.pl b/corepkgs/buildenv.pl new file mode 100644 index 000000000000..52a703c0668f --- /dev/null +++ b/corepkgs/buildenv.pl @@ -0,0 +1,169 @@ +use strict; +use Cwd; +use IO::Handle; + +STDOUT->autoflush(1); + +my $out = $ENV{"out"}; +mkdir "$out", 0755 || die "error creating $out"; + + +my $symlinks = 0; + +my %priorities; + + +# For each activated package, create symlinks. + +sub createLinks { + my $srcDir = shift; + my $dstDir = shift; + my $priority = shift; + + my @srcFiles = glob("$srcDir/*"); + + foreach my $srcFile (@srcFiles) { + my $baseName = $srcFile; + $baseName =~ s/^.*\///g; # strip directory + my $dstFile = "$dstDir/$baseName"; + + # The files below are special-cased so that they don't show up + # in user profiles, either because they are useless, or + # because they would cause pointless collisions (e.g., each + # Python package brings its own + # `$out/lib/pythonX.Y/site-packages/easy-install.pth'.) + # Urgh, hacky... + if ($srcFile =~ /\/propagated-build-inputs$/ || + $srcFile =~ /\/nix-support$/ || + $srcFile =~ /\/perllocal.pod$/ || + $srcFile =~ /\/easy-install.pth$/ || + $srcFile =~ /\/site.py$/ || + $srcFile =~ /\/site.pyc$/ || + $srcFile =~ /\/info\/dir$/ || + $srcFile =~ /\/log$/) + { + # Do nothing. + } + + elsif (-d $srcFile) { + + lstat $dstFile; + + if (-d _) { + createLinks($srcFile, $dstFile, $priority); + } + + elsif (-l _) { + my $target = readlink $dstFile or die; + if (!-d $target) { + die "collission between directory `$srcFile' and non-directory `$target'"; + } + unlink $dstFile or die "error unlinking `$dstFile': $!"; + mkdir $dstFile, 0755 || + die "error creating directory `$dstFile': $!"; + createLinks($target, $dstFile, $priorities{$dstFile}); + createLinks($srcFile, $dstFile, $priority); + } + + else { + symlink($srcFile, $dstFile) || + die "error creating link `$dstFile': $!"; + $priorities{$dstFile} = $priority; + $symlinks++; + } + } + + else { + + if (-l $dstFile) { + my $target = readlink $dstFile; + my $prevPriority = $priorities{$dstFile}; + die ( "Collission between `$srcFile' and `$target'. " + . "Suggested solution: use `nix-env --set-flag " + . "priority NUMBER PKGNAME' to change the priority of " + . "one of the conflicting packages.\n" ) + if $prevPriority == $priority; + next if $prevPriority < $priority; + unlink $dstFile or die; + } + + symlink($srcFile, $dstFile) || + die "error creating link `$dstFile': $!"; + $priorities{$dstFile} = $priority; + $symlinks++; + } + } +} + + +my %done; +my %postponed; + +sub addPkg; +sub addPkg { + my $pkgDir = shift; + my $priority = shift; + + return if (defined $done{$pkgDir}); + $done{$pkgDir} = 1; + +# print "symlinking $pkgDir\n"; + createLinks("$pkgDir", "$out", $priority); + + my $propagatedFN = "$pkgDir/nix-support/propagated-user-env-packages"; + if (-e $propagatedFN) { + open PROP, "<$propagatedFN" or die; + my $propagated = ; + close PROP; + my @propagated = split ' ', $propagated; + foreach my $p (@propagated) { + $postponed{$p} = 1 unless defined $done{$p}; + } + } +} + + +# Convert the stuff we get from the environment back into a coherent +# data type. +my @paths = split ' ', $ENV{"paths"}; +my @active = split ' ', $ENV{"active"}; +my @priority = split ' ', $ENV{"priority"}; + +die if scalar @paths != scalar @active; +die if scalar @paths != scalar @priority; + +my %pkgs; + +for (my $n = 0; $n < scalar @paths; $n++) { + $pkgs{$paths[$n]} = + { active => $active[$n] + , priority => $priority[$n] }; +} + + +# Symlink to the packages that have been installed explicitly by the +# user. +foreach my $pkg (sort (keys %pkgs)) { + #print $pkg, " ", $pkgs{$pkg}->{priority}, "\n"; + addPkg($pkg, $pkgs{$pkg}->{priority}) if $pkgs{$pkg}->{active} ne "false"; +} + + +# Symlink to the packages that have been "propagated" by packages +# installed by the user (i.e., package X declares that it want Y +# installed as well). We do these later because they have a lower +# priority in case of collisions. +my $priorityCounter = 1000; # don't care about collisions +while (scalar(keys %postponed) > 0) { + my @pkgDirs = keys %postponed; + %postponed = (); + foreach my $pkgDir (sort @pkgDirs) { + addPkg($pkgDir, $priorityCounter++); + } +} + + +print STDERR "created $symlinks symlinks in user environment\n"; + + +symlink($ENV{"manifest"}, "$out/manifest.nix") or die "cannot create manifest"; diff --git a/corepkgs/buildenv/Makefile.am b/corepkgs/buildenv/Makefile.am deleted file mode 100644 index eeab538abca7..000000000000 --- a/corepkgs/buildenv/Makefile.am +++ /dev/null @@ -1,11 +0,0 @@ -all-local: builder.pl - -install-exec-local: - $(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs - $(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs/buildenv - $(INSTALL_DATA) $(srcdir)/default.nix $(DESTDIR)$(datadir)/nix/corepkgs/buildenv - $(INSTALL_PROGRAM) builder.pl $(DESTDIR)$(datadir)/nix/corepkgs/buildenv - -include ../../substitute.mk - -EXTRA_DIST = default.nix builder.pl.in diff --git a/corepkgs/buildenv/builder.pl.in b/corepkgs/buildenv/builder.pl.in deleted file mode 100755 index 86abe0ca19ea..000000000000 --- a/corepkgs/buildenv/builder.pl.in +++ /dev/null @@ -1,171 +0,0 @@ -#! @perl@ -w - -use strict; -use Cwd; -use IO::Handle; - -STDOUT->autoflush(1); - -my $out = $ENV{"out"}; -mkdir "$out", 0755 || die "error creating $out"; - - -my $symlinks = 0; - -my %priorities; - - -# For each activated package, create symlinks. - -sub createLinks { - my $srcDir = shift; - my $dstDir = shift; - my $priority = shift; - - my @srcFiles = glob("$srcDir/*"); - - foreach my $srcFile (@srcFiles) { - my $baseName = $srcFile; - $baseName =~ s/^.*\///g; # strip directory - my $dstFile = "$dstDir/$baseName"; - - # The files below are special-cased so that they don't show up - # in user profiles, either because they are useless, or - # because they would cause pointless collisions (e.g., each - # Python package brings its own - # `$out/lib/pythonX.Y/site-packages/easy-install.pth'.) - # Urgh, hacky... - if ($srcFile =~ /\/propagated-build-inputs$/ || - $srcFile =~ /\/nix-support$/ || - $srcFile =~ /\/perllocal.pod$/ || - $srcFile =~ /\/easy-install.pth$/ || - $srcFile =~ /\/site.py$/ || - $srcFile =~ /\/site.pyc$/ || - $srcFile =~ /\/info\/dir$/ || - $srcFile =~ /\/log$/) - { - # Do nothing. - } - - elsif (-d $srcFile) { - - lstat $dstFile; - - if (-d _) { - createLinks($srcFile, $dstFile, $priority); - } - - elsif (-l _) { - my $target = readlink $dstFile or die; - if (!-d $target) { - die "collission between directory `$srcFile' and non-directory `$target'"; - } - unlink $dstFile or die "error unlinking `$dstFile': $!"; - mkdir $dstFile, 0755 || - die "error creating directory `$dstFile': $!"; - createLinks($target, $dstFile, $priorities{$dstFile}); - createLinks($srcFile, $dstFile, $priority); - } - - else { - symlink($srcFile, $dstFile) || - die "error creating link `$dstFile': $!"; - $priorities{$dstFile} = $priority; - $symlinks++; - } - } - - else { - - if (-l $dstFile) { - my $target = readlink $dstFile; - my $prevPriority = $priorities{$dstFile}; - die ( "Collission between `$srcFile' and `$target'. " - . "Suggested solution: use `nix-env --set-flag " - . "priority NUMBER PKGNAME' to change the priority of " - . "one of the conflicting packages.\n" ) - if $prevPriority == $priority; - next if $prevPriority < $priority; - unlink $dstFile or die; - } - - symlink($srcFile, $dstFile) || - die "error creating link `$dstFile': $!"; - $priorities{$dstFile} = $priority; - $symlinks++; - } - } -} - - -my %done; -my %postponed; - -sub addPkg; -sub addPkg { - my $pkgDir = shift; - my $priority = shift; - - return if (defined $done{$pkgDir}); - $done{$pkgDir} = 1; - -# print "symlinking $pkgDir\n"; - createLinks("$pkgDir", "$out", $priority); - - my $propagatedFN = "$pkgDir/nix-support/propagated-user-env-packages"; - if (-e $propagatedFN) { - open PROP, "<$propagatedFN" or die; - my $propagated = ; - close PROP; - my @propagated = split ' ', $propagated; - foreach my $p (@propagated) { - $postponed{$p} = 1 unless defined $done{$p}; - } - } -} - - -# Convert the stuff we get from the environment back into a coherent -# data type. -my @paths = split ' ', $ENV{"paths"}; -my @active = split ' ', $ENV{"active"}; -my @priority = split ' ', $ENV{"priority"}; - -die if scalar @paths != scalar @active; -die if scalar @paths != scalar @priority; - -my %pkgs; - -for (my $n = 0; $n < scalar @paths; $n++) { - $pkgs{$paths[$n]} = - { active => $active[$n] - , priority => $priority[$n] }; -} - - -# Symlink to the packages that have been installed explicitly by the -# user. -foreach my $pkg (sort (keys %pkgs)) { - #print $pkg, " ", $pkgs{$pkg}->{priority}, "\n"; - addPkg($pkg, $pkgs{$pkg}->{priority}) if $pkgs{$pkg}->{active} ne "false"; -} - - -# Symlink to the packages that have been "propagated" by packages -# installed by the user (i.e., package X declares that it want Y -# installed as well). We do these later because they have a lower -# priority in case of collisions. -my $priorityCounter = 1000; # don't care about collisions -while (scalar(keys %postponed) > 0) { - my @pkgDirs = keys %postponed; - %postponed = (); - foreach my $pkgDir (sort @pkgDirs) { - addPkg($pkgDir, $priorityCounter++); - } -} - - -print STDERR "created $symlinks symlinks in user environment\n"; - - -symlink($ENV{"manifest"}, "$out/manifest.nix") or die "cannot create manifest"; diff --git a/corepkgs/buildenv/default.nix b/corepkgs/buildenv/default.nix deleted file mode 100644 index d76f5274099a..000000000000 --- a/corepkgs/buildenv/default.nix +++ /dev/null @@ -1,18 +0,0 @@ -{system, derivations, manifest}: - -derivation { - name = "user-environment"; - system = system; - builder = ./builder.pl; - - manifest = manifest; - - # !!! grmbl, need structured data for passing this in a clean way. - paths = derivations; - active = map (x: if x ? meta && x.meta ? active then x.meta.active else "true") derivations; - priority = map (x: if x ? meta && x.meta ? priority then x.meta.priority else "5") derivations; - - # Building user environments remotely just causes huge amounts of - # network traffic, so don't do that. - preferLocalBuild = true; -} diff --git a/corepkgs/nar.nix b/corepkgs/nar.nix new file mode 100644 index 000000000000..70a4af2f9ddb --- /dev/null +++ b/corepkgs/nar.nix @@ -0,0 +1,30 @@ +with import ; + +let + + builder = builtins.toFile "nar.sh" + '' + export PATH=${nixBinDir}:${coreutils} + + echo "packing ‘$storePath’..." + mkdir $out + dst=$out/tmp.nar.bz2 + + set -o pipefail + nix-store --dump "$storePath" | ${bzip2} > $dst + + nix-hash --flat --type $hashAlgo --base32 $dst > $out/narbz2-hash + + mv $out/tmp.nar.bz2 $out/$(cat $out/narbz2-hash).nar.bz2 + ''; + +in + +{ system, storePath, hashAlgo }: + +derivation { + name = "nar"; + builder = shell; + args = [ "-e" builder ]; + inherit system storePath hashAlgo; +} diff --git a/corepkgs/nar/Makefile.am b/corepkgs/nar/Makefile.am deleted file mode 100644 index 103051e22537..000000000000 --- a/corepkgs/nar/Makefile.am +++ /dev/null @@ -1,11 +0,0 @@ -all-local: nar.sh - -install-exec-local: - $(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs - $(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs/nar - $(INSTALL_DATA) $(srcdir)/nar.nix $(DESTDIR)$(datadir)/nix/corepkgs/nar - $(INSTALL_PROGRAM) nar.sh $(DESTDIR)$(datadir)/nix/corepkgs/nar - -include ../../substitute.mk - -EXTRA_DIST = nar.nix nar.sh.in diff --git a/corepkgs/nar/nar.nix b/corepkgs/nar/nar.nix deleted file mode 100644 index d3d799998f10..000000000000 --- a/corepkgs/nar/nar.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ system, storePath, hashAlgo }: - -derivation { - name = "nar"; - builder = ./nar.sh; - inherit system storePath hashAlgo; -} diff --git a/corepkgs/nar/nar.sh.in b/corepkgs/nar/nar.sh.in deleted file mode 100644 index 1369d3a21fb2..000000000000 --- a/corepkgs/nar/nar.sh.in +++ /dev/null @@ -1,12 +0,0 @@ -#! @shell@ -e - -echo "packing $storePath into $out..." -@coreutils@/mkdir $out -dst=$out/tmp.nar.bz2 -@bindir@/nix-store --dump "$storePath" > tmp - -@bzip2@ < tmp > $dst - -@bindir@/nix-hash --flat --type $hashAlgo --base32 $dst > $out/narbz2-hash - -@coreutils@/mv $out/tmp.nar.bz2 $out/$(@coreutils@/cat $out/narbz2-hash).nar.bz2 -- cgit 1.4.1