2004-03-15 17:23:53 +02:00
|
|
|
#! @perl@ -w
|
2003-11-19 19:27:16 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Cwd;
|
2004-04-06 14:42:28 +03:00
|
|
|
use IO::Handle;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
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;
|
2006-09-25 18:07:45 +03:00
|
|
|
my $ignoreCollisions = 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
|
|
|
|
|
|
|
# Urgh, hacky...
|
2004-04-06 14:42:28 +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.
|
2004-04-06 14:42:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
elsif (-d $srcFile) {
|
|
|
|
|
|
|
|
lstat $dstFile;
|
|
|
|
|
|
|
|
if (-d _) {
|
2006-09-25 18:07:45 +03:00
|
|
|
createLinks($srcFile, $dstFile, $ignoreCollisions);
|
2004-04-06 14:42:28 +03: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': $!";
|
2006-09-25 18:07:45 +03:00
|
|
|
createLinks($target, $dstFile, $ignoreCollisions);
|
|
|
|
createLinks($srcFile, $dstFile, $ignoreCollisions);
|
2003-11-19 19:27:16 +02:00
|
|
|
}
|
2004-04-06 14:42:28 +03:00
|
|
|
|
|
|
|
else {
|
|
|
|
symlink($srcFile, $dstFile) ||
|
|
|
|
die "error creating link `$dstFile': $!";
|
2006-09-25 18:07:45 +03:00
|
|
|
$symlinks++;
|
2004-04-06 14:42:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
elsif (-l $dstFile) {
|
2006-09-25 18:07:45 +03:00
|
|
|
if (!$ignoreCollisions) {
|
|
|
|
my $target = readlink $dstFile;
|
|
|
|
die "collission between `$srcFile' and `$target'";
|
|
|
|
}
|
2004-04-06 14:42:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
symlink($srcFile, $dstFile) ||
|
|
|
|
die "error creating link `$dstFile': $!";
|
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;
|
2006-09-25 18:07:45 +03:00
|
|
|
my $ignoreCollisions = 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";
|
|
|
|
createLinks("$pkgDir", "$out", $ignoreCollisions);
|
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
|
|
|
|
2006-09-25 18:07:45 +03:00
|
|
|
# Symlink to the packages that have been installed explicitly by the user.
|
2007-04-28 01:40:59 +03:00
|
|
|
my @paths = split ' ', $ENV{"derivations"};
|
|
|
|
my @active = split ' ', $ENV{"active"};
|
2003-11-19 19:27:16 +02:00
|
|
|
|
2007-04-28 01:40:59 +03:00
|
|
|
die if scalar @paths != scalar @active;
|
|
|
|
|
|
|
|
for (my $n = 0; $n < scalar @paths; $n++) {
|
|
|
|
my $pkgDir = $paths[$n];
|
|
|
|
my $isActive = $active[$n];
|
|
|
|
addPkg($pkgDir, 0) if $isActive ne "false";
|
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.
|
|
|
|
while (scalar(keys %postponed) > 0) {
|
|
|
|
my @pkgDirs = keys %postponed;
|
|
|
|
%postponed = ();
|
|
|
|
foreach my $pkgDir (sort @pkgDirs) {
|
|
|
|
addPkg($pkgDir, 1);
|
|
|
|
}
|
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";
|
|
|
|
|
|
|
|
|
2004-04-06 14:42:28 +03:00
|
|
|
symlink($ENV{"manifest"}, "$out/manifest") or die "cannot create manifest";
|