forked from lix-project/lix
* Package conflict resolution through priority levels. If there is a
user environment collission between two packages due to overlapping file names, then a package with a higher priority will overwrite the symlinks of a package with a lower priority. E.g., $ nix-env --set-flag priority 5 gcc $ nix-env --set-flag priority 10 binutils gives gcc a higher priority than binutils (higher number = lower priority).
This commit is contained in:
parent
3d05166086
commit
a46db5d013
|
@ -12,13 +12,15 @@ mkdir "$out", 0755 || die "error creating $out";
|
||||||
|
|
||||||
my $symlinks = 0;
|
my $symlinks = 0;
|
||||||
|
|
||||||
|
my %priorities;
|
||||||
|
|
||||||
|
|
||||||
# For each activated package, create symlinks.
|
# For each activated package, create symlinks.
|
||||||
|
|
||||||
sub createLinks {
|
sub createLinks {
|
||||||
my $srcDir = shift;
|
my $srcDir = shift;
|
||||||
my $dstDir = shift;
|
my $dstDir = shift;
|
||||||
my $ignoreCollisions = shift;
|
my $priority = shift;
|
||||||
|
|
||||||
my @srcFiles = glob("$srcDir/*");
|
my @srcFiles = glob("$srcDir/*");
|
||||||
|
|
||||||
|
@ -42,7 +44,7 @@ sub createLinks {
|
||||||
lstat $dstFile;
|
lstat $dstFile;
|
||||||
|
|
||||||
if (-d _) {
|
if (-d _) {
|
||||||
createLinks($srcFile, $dstFile, $ignoreCollisions);
|
createLinks($srcFile, $dstFile, $priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif (-l _) {
|
elsif (-l _) {
|
||||||
|
@ -53,27 +55,35 @@ sub createLinks {
|
||||||
unlink $dstFile or die "error unlinking `$dstFile': $!";
|
unlink $dstFile or die "error unlinking `$dstFile': $!";
|
||||||
mkdir $dstFile, 0755 ||
|
mkdir $dstFile, 0755 ||
|
||||||
die "error creating directory `$dstFile': $!";
|
die "error creating directory `$dstFile': $!";
|
||||||
createLinks($target, $dstFile, $ignoreCollisions);
|
createLinks($target, $dstFile, $priority); # !!! <- priority isn't right
|
||||||
createLinks($srcFile, $dstFile, $ignoreCollisions);
|
createLinks($srcFile, $dstFile, $priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
symlink($srcFile, $dstFile) ||
|
symlink($srcFile, $dstFile) ||
|
||||||
die "error creating link `$dstFile': $!";
|
die "error creating link `$dstFile': $!";
|
||||||
|
$priorities{$dstFile} = $priority;
|
||||||
$symlinks++;
|
$symlinks++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif (-l $dstFile) {
|
else {
|
||||||
if (!$ignoreCollisions) {
|
|
||||||
|
if (-l $dstFile) {
|
||||||
my $target = readlink $dstFile;
|
my $target = readlink $dstFile;
|
||||||
die "collission between `$srcFile' and `$target'";
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
|
||||||
symlink($srcFile, $dstFile) ||
|
symlink($srcFile, $dstFile) ||
|
||||||
die "error creating link `$dstFile': $!";
|
die "error creating link `$dstFile': $!";
|
||||||
|
$priorities{$dstFile} = $priority;
|
||||||
$symlinks++;
|
$symlinks++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,13 +96,13 @@ my %postponed;
|
||||||
sub addPkg;
|
sub addPkg;
|
||||||
sub addPkg {
|
sub addPkg {
|
||||||
my $pkgDir = shift;
|
my $pkgDir = shift;
|
||||||
my $ignoreCollisions = shift;
|
my $priority = shift;
|
||||||
|
|
||||||
return if (defined $done{$pkgDir});
|
return if (defined $done{$pkgDir});
|
||||||
$done{$pkgDir} = 1;
|
$done{$pkgDir} = 1;
|
||||||
|
|
||||||
# print "symlinking $pkgDir\n";
|
# print "symlinking $pkgDir\n";
|
||||||
createLinks("$pkgDir", "$out", $ignoreCollisions);
|
createLinks("$pkgDir", "$out", $priority);
|
||||||
|
|
||||||
my $propagatedFN = "$pkgDir/nix-support/propagated-user-env-packages";
|
my $propagatedFN = "$pkgDir/nix-support/propagated-user-env-packages";
|
||||||
if (-e $propagatedFN) {
|
if (-e $propagatedFN) {
|
||||||
|
@ -107,16 +117,29 @@ sub addPkg {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Symlink to the packages that have been installed explicitly by the user.
|
# Convert the stuff we get from the environment back into a coherent
|
||||||
my @paths = split ' ', $ENV{"derivations"};
|
# data type.
|
||||||
|
my @paths = split ' ', $ENV{"paths"};
|
||||||
my @active = split ' ', $ENV{"active"};
|
my @active = split ' ', $ENV{"active"};
|
||||||
|
my @priority = split ' ', $ENV{"priority"};
|
||||||
|
|
||||||
die if scalar @paths != scalar @active;
|
die if scalar @paths != scalar @active;
|
||||||
|
die if scalar @paths != scalar @priority;
|
||||||
|
|
||||||
|
my %pkgs;
|
||||||
|
|
||||||
for (my $n = 0; $n < scalar @paths; $n++) {
|
for (my $n = 0; $n < scalar @paths; $n++) {
|
||||||
my $pkgDir = $paths[$n];
|
$pkgs{$paths[$n]} =
|
||||||
my $isActive = $active[$n];
|
{ active => $active[$n]
|
||||||
addPkg($pkgDir, 0) if $isActive ne "false";
|
, 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";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,11 +147,12 @@ for (my $n = 0; $n < scalar @paths; $n++) {
|
||||||
# installed by the user (i.e., package X declares that it want Y
|
# 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
|
# installed as well). We do these later because they have a lower
|
||||||
# priority in case of collisions.
|
# priority in case of collisions.
|
||||||
|
my $priorityCounter = 1000; # don't care about collisions
|
||||||
while (scalar(keys %postponed) > 0) {
|
while (scalar(keys %postponed) > 0) {
|
||||||
my @pkgDirs = keys %postponed;
|
my @pkgDirs = keys %postponed;
|
||||||
%postponed = ();
|
%postponed = ();
|
||||||
foreach my $pkgDir (sort @pkgDirs) {
|
foreach my $pkgDir (sort @pkgDirs) {
|
||||||
addPkg($pkgDir, 1);
|
addPkg($pkgDir, $priorityCounter++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,11 @@ derivation {
|
||||||
name = "user-environment";
|
name = "user-environment";
|
||||||
system = system;
|
system = system;
|
||||||
builder = ./builder.pl;
|
builder = ./builder.pl;
|
||||||
derivations = derivations;
|
|
||||||
manifest = manifest;
|
manifest = manifest;
|
||||||
|
|
||||||
# !!! grmbl, need structured data for passing this in a clean way.
|
# !!! 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;
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,9 @@
|
||||||
environments.</para></listitem>
|
environments.</para></listitem>
|
||||||
|
|
||||||
<listitem><para>TODO: <command>nix-env</command>
|
<listitem><para>TODO: <command>nix-env</command>
|
||||||
<option>--set-flag</option>.</para></listitem>
|
<option>--set-flag</option>. Specific flags:
|
||||||
|
<literal>active</literal>,
|
||||||
|
<literal>priority</literal>.</para></listitem>
|
||||||
|
|
||||||
|
|
||||||
<listitem><para><command>nix-env -q</command> now has a flag
|
<listitem><para><command>nix-env -q</command> now has a flag
|
||||||
|
|
Loading…
Reference in a new issue