forked from lix-project/lix
* Register channels as roots of the garbage collector (in
$(localstatedir)/nix/gcroots/channels). * In setuid installations, create gcroots/tmp and gcroots/channels group-writable.
This commit is contained in:
parent
88888160d2
commit
2155c0a673
|
@ -16,6 +16,7 @@ install-data-local: init-state
|
||||||
if INIT_STATE
|
if INIT_STATE
|
||||||
if SETUID_HACK
|
if SETUID_HACK
|
||||||
INIT_FLAGS = -g @NIX_GROUP@ -o @NIX_USER@
|
INIT_FLAGS = -g @NIX_GROUP@ -o @NIX_USER@
|
||||||
|
GROUP_WRITABLE = -m 775
|
||||||
endif
|
endif
|
||||||
init-state:
|
init-state:
|
||||||
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix
|
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix
|
||||||
|
@ -23,7 +24,8 @@ init-state:
|
||||||
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/log/nix
|
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/log/nix
|
||||||
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/profiles
|
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/profiles
|
||||||
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/gcroots
|
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/gcroots
|
||||||
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/gcroots/tmp
|
$(INSTALL) $(INIT_FLAGS) $(GROUP_WRITABLE) -d $(DESTDIR)$(localstatedir)/nix/gcroots/tmp
|
||||||
|
$(INSTALL) $(INIT_FLAGS) $(GROUP_WRITABLE) -d $(DESTDIR)$(localstatedir)/nix/gcroots/channels
|
||||||
rm -f $(DESTDIR)$(localstatedir)/nix/gcroots/profiles
|
rm -f $(DESTDIR)$(localstatedir)/nix/gcroots/profiles
|
||||||
ln -s $(localstatedir)/nix/profiles $(DESTDIR)$(localstatedir)/nix/gcroots/profiles
|
ln -s $(localstatedir)/nix/profiles $(DESTDIR)$(localstatedir)/nix/gcroots/profiles
|
||||||
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(prefix)/store
|
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(prefix)/store
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
|
my $rootsDir = "@localstatedir@/nix/gcroots/channels";
|
||||||
|
|
||||||
|
|
||||||
# Figure out the name of the `.nix-channels' file to use.
|
# Figure out the name of the `.nix-channels' file to use.
|
||||||
my $home = $ENV{"HOME"};
|
my $home = $ENV{"HOME"};
|
||||||
|
@ -79,18 +81,33 @@ sub update {
|
||||||
"(import @datadir@/nix/corepkgs/channels/unpack.nix) " .
|
"(import @datadir@/nix/corepkgs/channels/unpack.nix) " .
|
||||||
"{inputs = $nixExpr; system = \"@system@\";}";
|
"{inputs = $nixExpr; system = \"@system@\";}";
|
||||||
|
|
||||||
# Instantiate and realise it.
|
# Instantiate the Nix expression.
|
||||||
my $storeExpr = `echo '$nixExpr' | @bindir@/nix-instantiate -`
|
my $storeExpr = `echo '$nixExpr' | @bindir@/nix-instantiate -`
|
||||||
or die "cannot instantiate Nix expression";
|
or die "cannot instantiate Nix expression";
|
||||||
chomp $storeExpr;
|
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";
|
or die "cannot realise store expression";
|
||||||
chomp $outPath;
|
chomp $outPath;
|
||||||
|
|
||||||
# Make it the default Nix expression for `nix-env'.
|
# Make it the default Nix expression for `nix-env'.
|
||||||
system "@bindir@/nix-env --import '$outPath'";
|
system "@bindir@/nix-env --import '$outPath'";
|
||||||
die "cannot pull set default Nix expression to `$outPath'" if ($? != 0);
|
die "cannot pull set default Nix expression to `$outPath'" if ($? != 0);
|
||||||
|
|
||||||
|
rename $tmpRootFile, $rootFile or die "cannot rename `$tmpRootFile' to `$rootFile'";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue