diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-10-20T14·42+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-10-20T14·42+0000 |
commit | 2155c0a673ee1d72a9961ec5e4a864b7c797ec44 (patch) | |
tree | d793176f2377644c7fcdc2297593c3543e406712 /scripts/nix-channel.in | |
parent | 88888160d239ed68118ba1d5f94cad0a0ca7521f (diff) |
* Register channels as roots of the garbage collector (in
$(localstatedir)/nix/gcroots/channels). * In setuid installations, create gcroots/tmp and gcroots/channels group-writable.
Diffstat (limited to 'scripts/nix-channel.in')
-rwxr-xr-x | scripts/nix-channel.in | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/scripts/nix-channel.in b/scripts/nix-channel.in index f554380e2841..d05751512d62 100755 --- a/scripts/nix-channel.in +++ b/scripts/nix-channel.in @@ -2,6 +2,8 @@ use strict; +my $rootsDir = "@localstatedir@/nix/gcroots/channels"; + # Figure out the name of the `.nix-channels' file to use. my $home = $ENV{"HOME"}; @@ -79,18 +81,33 @@ sub update { "(import @datadir@/nix/corepkgs/channels/unpack.nix) " . "{inputs = $nixExpr; system = \"@system@\";}"; - # Instantiate and realise it. + # Instantiate the Nix expression. my $storeExpr = `echo '$nixExpr' | @bindir@/nix-instantiate -` or die "cannot instantiate Nix expression"; chomp $storeExpr; - my $outPath = `nix-store -qnfB '$storeExpr'` + # Register the store expression as a root of the garbage + # collector. + my $userName = getpwuid($<); + die "who ARE you? go away" unless defined $userName; + + my $rootFile = "$rootsDir/$userName.gcroot"; + my $tmpRootFile = "$rootsDir/$userName-tmp.gcroot"; + + open ROOT, ">$tmpRootFile" or die "cannot create `$tmpRootFile'"; + print ROOT "$storeExpr"; + close ROOT; + + # Realise the store expression. + my $outPath = `nix-store -qnf '$storeExpr'` or die "cannot realise store expression"; chomp $outPath; # Make it the default Nix expression for `nix-env'. system "@bindir@/nix-env --import '$outPath'"; die "cannot pull set default Nix expression to `$outPath'" if ($? != 0); + + rename $tmpRootFile, $rootFile or die "cannot rename `$tmpRootFile' to `$rootFile'"; } |