2003-11-19 19:27:16 +02:00
|
|
|
|
use strict;
|
|
|
|
|
use Cwd;
|
2004-04-06 14:42:28 +03:00
|
|
|
|
use IO::Handle;
|
2014-08-20 18:00:17 +03:00
|
|
|
|
use utf8;
|
2004-04-06 14:42:28 +03:00
|
|
|
|
|
|
|
|
|
STDOUT->autoflush(1);
|
|
|
|
|
|
|
|
|
|
my $out = $ENV{"out"};
|
|
|
|
|
mkdir "$out", 0755 || die "error creating $out";
|
2003-11-19 19:27:16 +02:00
|
|
|
|
|
|
|
|
|
|
2006-09-25 18:07:45 +03:00
|
|
|
|
my $symlinks = 0;
|
|
|
|
|
|
2007-04-28 02:28:44 +03:00
|
|
|
|
my %priorities;
|
|
|
|
|
|
2006-09-25 18:07:45 +03:00
|
|
|
|
|
2003-11-19 19:27:16 +02:00
|
|
|
|
# For each activated package, create symlinks.
|
|
|
|
|
|
|
|
|
|
sub createLinks {
|
2004-04-06 14:42:28 +03:00
|
|
|
|
my $srcDir = shift;
|
|
|
|
|
my $dstDir = shift;
|
2007-04-28 02:28:44 +03:00
|
|
|
|
my $priority = shift;
|
2004-04-06 14:42:28 +03:00
|
|
|
|
|
|
|
|
|
my @srcFiles = glob("$srcDir/*");
|
|
|
|
|
|
|
|
|
|
foreach my $srcFile (@srcFiles) {
|
|
|
|
|
my $baseName = $srcFile;
|
|
|
|
|
$baseName =~ s/^.*\///g; # strip directory
|
|
|
|
|
my $dstFile = "$dstDir/$baseName";
|
2006-09-25 18:07:45 +03:00
|
|
|
|
|
2010-05-03 16:13:38 +03:00
|
|
|
|
# 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'.)
|
2006-09-25 18:07:45 +03:00
|
|
|
|
# Urgh, hacky...
|
2010-05-03 16:13:38 +03:00
|
|
|
|
if ($srcFile =~ /\/propagated-build-inputs$/ ||
|
2004-09-19 18:53:37 +03:00
|
|
|
|
$srcFile =~ /\/nix-support$/ ||
|
2005-03-07 15:27:56 +02:00
|
|
|
|
$srcFile =~ /\/perllocal.pod$/ ||
|
2005-07-22 23:37:39 +03:00
|
|
|
|
$srcFile =~ /\/info\/dir$/ ||
|
2004-09-19 18:53:37 +03:00
|
|
|
|
$srcFile =~ /\/log$/)
|
2004-04-06 14:42:28 +03:00
|
|
|
|
{
|
2004-10-25 19:54:56 +03:00
|
|
|
|
# Do nothing.
|
2012-12-04 15:20:36 +02:00
|
|
|
|
}
|
2004-04-06 14:42:28 +03:00
|
|
|
|
|
|
|
|
|
elsif (-d $srcFile) {
|
|
|
|
|
|
|
|
|
|
lstat $dstFile;
|
2012-12-04 15:20:36 +02:00
|
|
|
|
|
2004-04-06 14:42:28 +03:00
|
|
|
|
if (-d _) {
|
2007-04-28 02:28:44 +03:00
|
|
|
|
createLinks($srcFile, $dstFile, $priority);
|
2004-04-06 14:42:28 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elsif (-l _) {
|
|
|
|
|
my $target = readlink $dstFile or die;
|
|
|
|
|
if (!-d $target) {
|
2014-08-20 18:00:17 +03:00
|
|
|
|
die "collision between directory ‘$srcFile’ and non-directory ‘$target’";
|
2004-04-06 14:42:28 +03:00
|
|
|
|
}
|
2014-08-20 18:00:17 +03:00
|
|
|
|
unlink $dstFile or die "error unlinking ‘$dstFile’: $!";
|
2012-12-04 15:20:36 +02:00
|
|
|
|
mkdir $dstFile, 0755 ||
|
2014-08-20 18:00:17 +03:00
|
|
|
|
die "error creating directory ‘$dstFile’: $!";
|
2007-05-02 22:38:02 +03:00
|
|
|
|
createLinks($target, $dstFile, $priorities{$dstFile});
|
2007-04-28 02:28:44 +03:00
|
|
|
|
createLinks($srcFile, $dstFile, $priority);
|
2003-11-19 19:27:16 +02:00
|
|
|
|
}
|
2004-04-06 14:42:28 +03:00
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
symlink($srcFile, $dstFile) ||
|
2014-08-20 18:00:17 +03:00
|
|
|
|
die "error creating link ‘$dstFile’: $!";
|
2007-04-28 02:28:44 +03:00
|
|
|
|
$priorities{$dstFile} = $priority;
|
2006-09-25 18:07:45 +03:00
|
|
|
|
$symlinks++;
|
2004-04-06 14:42:28 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-28 02:28:44 +03:00
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
if (-l $dstFile) {
|
2006-09-25 18:07:45 +03:00
|
|
|
|
my $target = readlink $dstFile;
|
2007-04-28 02:28:44 +03:00
|
|
|
|
my $prevPriority = $priorities{$dstFile};
|
2014-08-20 18:00:17 +03:00
|
|
|
|
die("collision between ‘$srcFile’ and ‘$target’; " .
|
|
|
|
|
"use ‘nix-env --set-flag priority NUMBER PKGNAME’ " .
|
|
|
|
|
"to change the priority of one of the conflicting packages\n")
|
2007-04-28 02:28:44 +03:00
|
|
|
|
if $prevPriority == $priority;
|
|
|
|
|
next if $prevPriority < $priority;
|
|
|
|
|
unlink $dstFile or die;
|
2006-09-25 18:07:45 +03:00
|
|
|
|
}
|
2012-12-04 15:20:36 +02:00
|
|
|
|
|
2004-04-06 14:42:28 +03:00
|
|
|
|
symlink($srcFile, $dstFile) ||
|
2014-08-20 18:00:17 +03:00
|
|
|
|
die "error creating link ‘$dstFile’: $!";
|
2007-04-28 02:28:44 +03:00
|
|
|
|
$priorities{$dstFile} = $priority;
|
2006-09-25 18:07:45 +03:00
|
|
|
|
$symlinks++;
|
2003-11-19 19:27:16 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-06 14:42:28 +03:00
|
|
|
|
|
2003-11-19 19:27:16 +02:00
|
|
|
|
my %done;
|
2006-09-25 18:07:45 +03:00
|
|
|
|
my %postponed;
|
2003-11-19 19:27:16 +02:00
|
|
|
|
|
2005-03-07 15:27:56 +02:00
|
|
|
|
sub addPkg;
|
2003-11-19 19:27:16 +02:00
|
|
|
|
sub addPkg {
|
2004-04-06 14:42:28 +03:00
|
|
|
|
my $pkgDir = shift;
|
2007-04-28 02:28:44 +03:00
|
|
|
|
my $priority = shift;
|
2003-11-19 19:27:16 +02:00
|
|
|
|
|
2004-04-06 14:42:28 +03:00
|
|
|
|
return if (defined $done{$pkgDir});
|
|
|
|
|
$done{$pkgDir} = 1;
|
2003-11-19 19:27:16 +02:00
|
|
|
|
|
2006-09-25 18:07:45 +03:00
|
|
|
|
# print "symlinking $pkgDir\n";
|
2007-04-28 02:28:44 +03:00
|
|
|
|
createLinks("$pkgDir", "$out", $priority);
|
2005-03-07 15:27:56 +02:00
|
|
|
|
|
2006-09-25 18:11:59 +03:00
|
|
|
|
my $propagatedFN = "$pkgDir/nix-support/propagated-user-env-packages";
|
2005-03-07 15:27:56 +02:00
|
|
|
|
if (-e $propagatedFN) {
|
|
|
|
|
open PROP, "<$propagatedFN" or die;
|
|
|
|
|
my $propagated = <PROP>;
|
|
|
|
|
close PROP;
|
|
|
|
|
my @propagated = split ' ', $propagated;
|
|
|
|
|
foreach my $p (@propagated) {
|
2006-09-25 18:07:45 +03:00
|
|
|
|
$postponed{$p} = 1 unless defined $done{$p};
|
2005-03-07 15:27:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-11-19 19:27:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2004-04-06 14:42:28 +03:00
|
|
|
|
|
2007-04-28 02:28:44 +03:00
|
|
|
|
# Convert the stuff we get from the environment back into a coherent
|
|
|
|
|
# data type.
|
2012-12-04 15:45:32 +02:00
|
|
|
|
my @pkgs;
|
2012-12-04 15:20:36 +02:00
|
|
|
|
my @derivations = split ' ', $ENV{"derivations"};
|
|
|
|
|
while (scalar @derivations) {
|
|
|
|
|
my $active = shift @derivations;
|
|
|
|
|
my $priority = shift @derivations;
|
|
|
|
|
my $outputs = shift @derivations;
|
|
|
|
|
for (my $n = 0; $n < $outputs; $n++) {
|
|
|
|
|
my $path = shift @derivations;
|
2012-12-04 15:45:32 +02:00
|
|
|
|
push @pkgs,
|
|
|
|
|
{ path => $path
|
|
|
|
|
, active => $active ne "false"
|
2012-12-04 15:20:36 +02:00
|
|
|
|
, priority => int($priority) };
|
|
|
|
|
}
|
2007-04-28 02:28:44 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Symlink to the packages that have been installed explicitly by the
|
2012-12-04 15:45:32 +02:00
|
|
|
|
# user. Process in priority order to reduce unnecessary
|
|
|
|
|
# symlink/unlink steps.
|
|
|
|
|
@pkgs = sort { $a->{priority} <=> $b->{priority} || $a->{path} cmp $b->{path} } @pkgs;
|
|
|
|
|
foreach my $pkg (@pkgs) {
|
2007-04-28 02:28:44 +03:00
|
|
|
|
#print $pkg, " ", $pkgs{$pkg}->{priority}, "\n";
|
2012-12-04 15:45:32 +02:00
|
|
|
|
addPkg($pkg->{path}, $pkg->{priority}) if $pkg->{active};
|
2006-09-25 18:07:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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.
|
2007-04-28 02:28:44 +03:00
|
|
|
|
my $priorityCounter = 1000; # don't care about collisions
|
2006-09-25 18:07:45 +03:00
|
|
|
|
while (scalar(keys %postponed) > 0) {
|
|
|
|
|
my @pkgDirs = keys %postponed;
|
|
|
|
|
%postponed = ();
|
|
|
|
|
foreach my $pkgDir (sort @pkgDirs) {
|
2007-04-28 02:28:44 +03:00
|
|
|
|
addPkg($pkgDir, $priorityCounter++);
|
2006-09-25 18:07:45 +03:00
|
|
|
|
}
|
2003-11-19 19:27:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-25 18:07:45 +03:00
|
|
|
|
print STDERR "created $symlinks symlinks in user environment\n";
|
|
|
|
|
|
|
|
|
|
|
2010-04-21 18:08:58 +03:00
|
|
|
|
symlink($ENV{"manifest"}, "$out/manifest.nix") or die "cannot create manifest";
|