2003-11-19 17:27:16 +00:00
|
|
|
use strict;
|
|
|
|
use Cwd;
|
2004-04-06 11:42:28 +00:00
|
|
|
use IO::Handle;
|
|
|
|
|
|
|
|
STDOUT->autoflush(1);
|
|
|
|
|
|
|
|
my $out = $ENV{"out"};
|
|
|
|
mkdir "$out", 0755 || die "error creating $out";
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
|
|
|
2006-09-25 15:07:45 +00:00
|
|
|
my $symlinks = 0;
|
|
|
|
|
2007-04-27 23:28:44 +00:00
|
|
|
my %priorities;
|
|
|
|
|
2006-09-25 15:07:45 +00:00
|
|
|
|
2003-11-19 17:27:16 +00:00
|
|
|
# For each activated package, create symlinks.
|
|
|
|
|
|
|
|
sub createLinks {
|
2004-04-06 11:42:28 +00:00
|
|
|
my $srcDir = shift;
|
|
|
|
my $dstDir = shift;
|
2007-04-27 23:28:44 +00:00
|
|
|
my $priority = shift;
|
2004-04-06 11:42:28 +00:00
|
|
|
|
|
|
|
my @srcFiles = glob("$srcDir/*");
|
|
|
|
|
|
|
|
foreach my $srcFile (@srcFiles) {
|
|
|
|
my $baseName = $srcFile;
|
|
|
|
$baseName =~ s/^.*\///g; # strip directory
|
|
|
|
my $dstFile = "$dstDir/$baseName";
|
2006-09-25 15:07:45 +00:00
|
|
|
|
2010-05-03 13:13:38 +00: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 15:07:45 +00:00
|
|
|
# Urgh, hacky...
|
2010-05-03 13:13:38 +00:00
|
|
|
if ($srcFile =~ /\/propagated-build-inputs$/ ||
|
2004-09-19 15:53:37 +00:00
|
|
|
$srcFile =~ /\/nix-support$/ ||
|
2005-03-07 13:27:56 +00:00
|
|
|
$srcFile =~ /\/perllocal.pod$/ ||
|
2010-05-03 13:13:38 +00:00
|
|
|
$srcFile =~ /\/easy-install.pth$/ ||
|
2010-05-05 20:46:41 +00:00
|
|
|
$srcFile =~ /\/site.py$/ ||
|
|
|
|
$srcFile =~ /\/site.pyc$/ ||
|
2005-07-22 20:37:39 +00:00
|
|
|
$srcFile =~ /\/info\/dir$/ ||
|
2004-09-19 15:53:37 +00:00
|
|
|
$srcFile =~ /\/log$/)
|
2004-04-06 11:42:28 +00:00
|
|
|
{
|
2004-10-25 16:54:56 +00:00
|
|
|
# Do nothing.
|
2004-04-06 11:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
elsif (-d $srcFile) {
|
|
|
|
|
|
|
|
lstat $dstFile;
|
|
|
|
|
|
|
|
if (-d _) {
|
2007-04-27 23:28:44 +00:00
|
|
|
createLinks($srcFile, $dstFile, $priority);
|
2004-04-06 11:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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': $!";
|
2007-05-02 19:38:02 +00:00
|
|
|
createLinks($target, $dstFile, $priorities{$dstFile});
|
2007-04-27 23:28:44 +00:00
|
|
|
createLinks($srcFile, $dstFile, $priority);
|
2003-11-19 17:27:16 +00:00
|
|
|
}
|
2004-04-06 11:42:28 +00:00
|
|
|
|
|
|
|
else {
|
|
|
|
symlink($srcFile, $dstFile) ||
|
|
|
|
die "error creating link `$dstFile': $!";
|
2007-04-27 23:28:44 +00:00
|
|
|
$priorities{$dstFile} = $priority;
|
2006-09-25 15:07:45 +00:00
|
|
|
$symlinks++;
|
2004-04-06 11:42:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-27 23:28:44 +00:00
|
|
|
else {
|
|
|
|
|
|
|
|
if (-l $dstFile) {
|
2006-09-25 15:07:45 +00:00
|
|
|
my $target = readlink $dstFile;
|
2007-04-27 23:28:44 +00:00
|
|
|
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;
|
2006-09-25 15:07:45 +00:00
|
|
|
}
|
2007-04-27 23:28:44 +00:00
|
|
|
|
2004-04-06 11:42:28 +00:00
|
|
|
symlink($srcFile, $dstFile) ||
|
|
|
|
die "error creating link `$dstFile': $!";
|
2007-04-27 23:28:44 +00:00
|
|
|
$priorities{$dstFile} = $priority;
|
2006-09-25 15:07:45 +00:00
|
|
|
$symlinks++;
|
2003-11-19 17:27:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-06 11:42:28 +00:00
|
|
|
|
2003-11-19 17:27:16 +00:00
|
|
|
my %done;
|
2006-09-25 15:07:45 +00:00
|
|
|
my %postponed;
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2005-03-07 13:27:56 +00:00
|
|
|
sub addPkg;
|
2003-11-19 17:27:16 +00:00
|
|
|
sub addPkg {
|
2004-04-06 11:42:28 +00:00
|
|
|
my $pkgDir = shift;
|
2007-04-27 23:28:44 +00:00
|
|
|
my $priority = shift;
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2004-04-06 11:42:28 +00:00
|
|
|
return if (defined $done{$pkgDir});
|
|
|
|
$done{$pkgDir} = 1;
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2006-09-25 15:07:45 +00:00
|
|
|
# print "symlinking $pkgDir\n";
|
2007-04-27 23:28:44 +00:00
|
|
|
createLinks("$pkgDir", "$out", $priority);
|
2005-03-07 13:27:56 +00:00
|
|
|
|
2006-09-25 15:11:59 +00:00
|
|
|
my $propagatedFN = "$pkgDir/nix-support/propagated-user-env-packages";
|
2005-03-07 13:27:56 +00: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 15:07:45 +00:00
|
|
|
$postponed{$p} = 1 unless defined $done{$p};
|
2005-03-07 13:27:56 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-19 17:27:16 +00:00
|
|
|
}
|
|
|
|
|
2004-04-06 11:42:28 +00:00
|
|
|
|
2007-04-27 23:28:44 +00:00
|
|
|
# Convert the stuff we get from the environment back into a coherent
|
|
|
|
# data type.
|
|
|
|
my @paths = split ' ', $ENV{"paths"};
|
2007-04-27 22:40:59 +00:00
|
|
|
my @active = split ' ', $ENV{"active"};
|
2007-04-27 23:28:44 +00:00
|
|
|
my @priority = split ' ', $ENV{"priority"};
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2007-04-27 22:40:59 +00:00
|
|
|
die if scalar @paths != scalar @active;
|
2007-04-27 23:28:44 +00:00
|
|
|
die if scalar @paths != scalar @priority;
|
|
|
|
|
|
|
|
my %pkgs;
|
2007-04-27 22:40:59 +00:00
|
|
|
|
|
|
|
for (my $n = 0; $n < scalar @paths; $n++) {
|
2007-04-27 23:28:44 +00:00
|
|
|
$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";
|
2006-09-25 15:07:45 +00: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-27 23:28:44 +00:00
|
|
|
my $priorityCounter = 1000; # don't care about collisions
|
2006-09-25 15:07:45 +00:00
|
|
|
while (scalar(keys %postponed) > 0) {
|
|
|
|
my @pkgDirs = keys %postponed;
|
|
|
|
%postponed = ();
|
|
|
|
foreach my $pkgDir (sort @pkgDirs) {
|
2007-04-27 23:28:44 +00:00
|
|
|
addPkg($pkgDir, $priorityCounter++);
|
2006-09-25 15:07:45 +00:00
|
|
|
}
|
2003-11-19 17:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-25 15:07:45 +00:00
|
|
|
print STDERR "created $symlinks symlinks in user environment\n";
|
|
|
|
|
|
|
|
|
2010-04-21 15:08:58 +00:00
|
|
|
symlink($ENV{"manifest"}, "$out/manifest.nix") or die "cannot create manifest";
|