From fb5dae8694acbabab68aaccbc64796719fcb7b02 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 17 Feb 2005 10:06:12 +0000 Subject: * Fix nix-channel. * Add `--help' flag; fixes NIX-5. * Add `--remove' flag; fixes NIX-6. * Add `--list' flag. --- scripts/nix-channel.in | 76 +++++++++++++++++++++++++++++++++++++------------- scripts/nix-push.in | 12 ++++---- 2 files changed, 63 insertions(+), 25 deletions(-) (limited to 'scripts') diff --git a/scripts/nix-channel.in b/scripts/nix-channel.in index 3c99f454c6f8..d75ed6c817c4 100644 --- a/scripts/nix-channel.in +++ b/scripts/nix-channel.in @@ -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 # channels. sub update { @@ -76,7 +89,7 @@ sub update { chomp $hash; # !!! escaping $nixExpr .= "((import @datadir@/nix/corepkgs/fetchurl) " . - "{url = $fullURL; md5 = \"$hash\"; system = \"@system@\";}) " + "{url = $fullURL; sha1 = \"$hash\"; system = \"@system@\";}) " } $nixExpr .= "]"; @@ -85,33 +98,39 @@ sub update { "(import @datadir@/nix/corepkgs/channels/unpack.nix) " . "{inputs = $nixExpr; system = \"@system@\";}"; - # Instantiate the Nix expression. - 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. + # Figure out a name for the GC root. my $userName = getpwuid($<); die "who ARE you? go away" unless defined $userName; - my $rootFile = "$rootsDir/$userName.gcroot"; - my $tmpRootFile = "$rootsDir/$userName-tmp.gcroot"; + my $rootFile = "$rootsDir/$userName"; - open ROOT, ">$tmpRootFile" or die "cannot create `$tmpRootFile': $!"; - print ROOT "$storeExpr"; - close ROOT; + # Instantiate the Nix expression. + my $storeExpr = `echo '$nixExpr' | @bindir@/nix-instantiate --add-root '$rootFile'.tmp -` + or die "cannot instantiate Nix expression"; + chomp $storeExpr; - # Realise the store expression. - my $outPath = `nix-store -qnf '$storeExpr'` + # Build the resulting derivation. + my $outPath = `nix-store --add-root '$rootFile' -r '$storeExpr'` or die "cannot realise store expression"; chomp $outPath; + unlink "$rootFile.tmp"; + # 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': $!"; + +sub usageError { + print STDERR <; + open SHA1, "$nardir/narbz2-hash" or die "cannot open narbz2-hash"; + my $narbz2Hash = ; chomp $narbz2Hash; $narbz2Hash =~ /^[0-9a-z]{32}$/ or die "invalid hash"; - close MD5; + close SHA1; - open MD5, "$nardir/nar-hash" or die "cannot open nar-hash"; - my $narHash = ; + open SHA1, "$nardir/nar-hash" or die "cannot open nar-hash"; + my $narHash = ; chomp $narHash; $narHash =~ /^[0-9a-z]{32}$/ or die "invalid hash"; - close MD5; + close SHA1; my $narbz2Size = (stat $narfile)[7]; -- cgit 1.4.1