* Fix nix-channel.
* Add `--help' flag; fixes NIX-5. * Add `--remove' flag; fixes NIX-6. * Add `--list' flag.
This commit is contained in:
parent
202d5bbda5
commit
fb5dae8694
|
@ -48,6 +48,19 @@ sub addChannel {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Remove a channel from the file $channelsList;
|
||||||
|
sub removeChannel {
|
||||||
|
my $url = shift;
|
||||||
|
my @left = ();
|
||||||
|
readChannels;
|
||||||
|
foreach my $url2 (@channels) {
|
||||||
|
push @left, $url2 if $url ne $url2;
|
||||||
|
}
|
||||||
|
@channels = @left;
|
||||||
|
writeChannels;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Fetch Nix expressions and pull cache manifests from the subscribed
|
# Fetch Nix expressions and pull cache manifests from the subscribed
|
||||||
# channels.
|
# channels.
|
||||||
sub update {
|
sub update {
|
||||||
|
@ -76,7 +89,7 @@ sub update {
|
||||||
chomp $hash;
|
chomp $hash;
|
||||||
# !!! escaping
|
# !!! escaping
|
||||||
$nixExpr .= "((import @datadir@/nix/corepkgs/fetchurl) " .
|
$nixExpr .= "((import @datadir@/nix/corepkgs/fetchurl) " .
|
||||||
"{url = $fullURL; md5 = \"$hash\"; system = \"@system@\";}) "
|
"{url = $fullURL; sha1 = \"$hash\"; system = \"@system@\";}) "
|
||||||
}
|
}
|
||||||
|
|
||||||
$nixExpr .= "]";
|
$nixExpr .= "]";
|
||||||
|
@ -85,33 +98,39 @@ 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 the Nix expression.
|
# Figure out a name for the GC root.
|
||||||
my $storeExpr = `echo '$nixExpr' | @bindir@/nix-instantiate -`
|
|
||||||
or die "cannot instantiate Nix expression";
|
|
||||||
chomp $storeExpr;
|
|
||||||
|
|
||||||
# Register the store expression as a root of the garbage
|
|
||||||
# collector.
|
|
||||||
my $userName = getpwuid($<);
|
my $userName = getpwuid($<);
|
||||||
die "who ARE you? go away" unless defined $userName;
|
die "who ARE you? go away" unless defined $userName;
|
||||||
|
|
||||||
my $rootFile = "$rootsDir/$userName.gcroot";
|
my $rootFile = "$rootsDir/$userName";
|
||||||
my $tmpRootFile = "$rootsDir/$userName-tmp.gcroot";
|
|
||||||
|
|
||||||
open ROOT, ">$tmpRootFile" or die "cannot create `$tmpRootFile': $!";
|
# Instantiate the Nix expression.
|
||||||
print ROOT "$storeExpr";
|
my $storeExpr = `echo '$nixExpr' | @bindir@/nix-instantiate --add-root '$rootFile'.tmp -`
|
||||||
close ROOT;
|
or die "cannot instantiate Nix expression";
|
||||||
|
chomp $storeExpr;
|
||||||
|
|
||||||
# Realise the store expression.
|
# Build the resulting derivation.
|
||||||
my $outPath = `nix-store -qnf '$storeExpr'`
|
my $outPath = `nix-store --add-root '$rootFile' -r '$storeExpr'`
|
||||||
or die "cannot realise store expression";
|
or die "cannot realise store expression";
|
||||||
chomp $outPath;
|
chomp $outPath;
|
||||||
|
|
||||||
|
unlink "$rootFile.tmp";
|
||||||
|
|
||||||
# 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': $!";
|
|
||||||
|
sub usageError {
|
||||||
|
print STDERR <<EOF;
|
||||||
|
Usage:
|
||||||
|
nix-channel --add URL
|
||||||
|
nix-channel --remove URL
|
||||||
|
nix-channel --list
|
||||||
|
nix-channel --update
|
||||||
|
EOF
|
||||||
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,18 +138,37 @@ while (scalar @ARGV) {
|
||||||
my $arg = shift @ARGV;
|
my $arg = shift @ARGV;
|
||||||
|
|
||||||
if ($arg eq "--add") {
|
if ($arg eq "--add") {
|
||||||
die "syntax: nix-channel --add URL" if (scalar @ARGV != 1);
|
usageError if scalar @ARGV != 1;
|
||||||
addChannel (shift @ARGV);
|
addChannel (shift @ARGV);
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($arg eq "--remove") {
|
||||||
|
usageError if scalar @ARGV != 1;
|
||||||
|
removeChannel (shift @ARGV);
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($arg eq "--list") {
|
||||||
|
usageError if scalar @ARGV != 0;
|
||||||
|
readChannels;
|
||||||
|
foreach my $url (@channels) {
|
||||||
|
print "$url\n";
|
||||||
|
}
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
|
||||||
elsif ($arg eq "--update") {
|
elsif ($arg eq "--update") {
|
||||||
die "syntax: nix-channel --update" if (scalar @ARGV != 0);
|
usageError if scalar @ARGV != 0;
|
||||||
update;
|
update;
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
elsif ($arg eq "--help") {
|
||||||
|
usageError;
|
||||||
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
die "unknown argument `$arg'";
|
die "unknown argument `$arg'; try `--help'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,17 +154,17 @@ for (my $n = 0; $n < scalar @storePaths; $n++) {
|
||||||
(-f $narfile) or die "narfile for $storePath not found";
|
(-f $narfile) or die "narfile for $storePath not found";
|
||||||
push @nararchives, $narfile;
|
push @nararchives, $narfile;
|
||||||
|
|
||||||
open MD5, "$nardir/narbz2-hash" or die "cannot open narbz2-hash";
|
open SHA1, "$nardir/narbz2-hash" or die "cannot open narbz2-hash";
|
||||||
my $narbz2Hash = <MD5>;
|
my $narbz2Hash = <SHA1>;
|
||||||
chomp $narbz2Hash;
|
chomp $narbz2Hash;
|
||||||
$narbz2Hash =~ /^[0-9a-z]{32}$/ or die "invalid hash";
|
$narbz2Hash =~ /^[0-9a-z]{32}$/ or die "invalid hash";
|
||||||
close MD5;
|
close SHA1;
|
||||||
|
|
||||||
open MD5, "$nardir/nar-hash" or die "cannot open nar-hash";
|
open SHA1, "$nardir/nar-hash" or die "cannot open nar-hash";
|
||||||
my $narHash = <MD5>;
|
my $narHash = <SHA1>;
|
||||||
chomp $narHash;
|
chomp $narHash;
|
||||||
$narHash =~ /^[0-9a-z]{32}$/ or die "invalid hash";
|
$narHash =~ /^[0-9a-z]{32}$/ or die "invalid hash";
|
||||||
close MD5;
|
close SHA1;
|
||||||
|
|
||||||
my $narbz2Size = (stat $narfile)[7];
|
my $narbz2Size = (stat $narfile)[7];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue