From e7ea52d3b336e6336c801eb8f868c0b8dd464910 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 24 Nov 2003 11:11:40 +0000 Subject: [PATCH] * One-click installation :-) The script nix-install-package takes a `Nix package file' (which contains one or more derivations, along with URLs of Nix caches), unpacks it, pulls the caches, and installs the derivations in the user's environment. For best results, associate the command `xterm -e /nix/bin/nix-install-package' with the MIME type `application/x-nix-package' and visit http://losser.st-lab.cs.uu.nl/~eelco/test/. --- scripts/Makefile.am | 7 +- scripts/nix-install-package.in | 37 +++++++++ scripts/nix-pull.in | 140 ++++++++++++++++++--------------- 3 files changed, 117 insertions(+), 67 deletions(-) create mode 100644 scripts/nix-install-package.in diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 35bb926af..94df32b24 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -1,5 +1,6 @@ bin_SCRIPTS = nix-collect-garbage \ - nix-pull nix-push nix-prefetch-url + nix-pull nix-push nix-prefetch-url \ + nix-install-package noinst_SCRIPTS = nix-profile.sh @@ -12,8 +13,8 @@ install-exec-local: include ../substitute.mk -EXTRA_DIST = nix-switch.in nix-collect-garbage.in \ +EXTRA_DIST = nix-collect-garbage.in \ nix-pull.in nix-push.in nix-profile.sh.in \ - nix-prefetch-url.in \ + nix-prefetch-url.in nix-install-package.in \ prebuilts.conf diff --git a/scripts/nix-install-package.in b/scripts/nix-install-package.in new file mode 100644 index 000000000..4988606c3 --- /dev/null +++ b/scripts/nix-install-package.in @@ -0,0 +1,37 @@ +#! /usr/bin/perl -w + +use strict; +use POSIX qw(tmpnam); + +my $pkgfile = $ARGV[0]; +die unless defined $pkgfile; + +my $tmpdir; +do { $tmpdir = tmpnam(); } +until mkdir $tmpdir, 0777; + +# !!! remove tmpdir on exit + +print "unpacking $pkgfile in $tmpdir...\n"; +system "bunzip2 < $pkgfile | (cd $tmpdir && tar xf -)"; +die if $?; + +print "this package contains the following derivations:\n"; +system "nix-env -qsf $tmpdir/default.nix"; +die if $?; + +print "do you wish to install them (y/n)? "; +my $reply = ; +chomp $reply; +exit if (!($reply eq "y")); + +print "pulling caches...\n"; +system "nix-pull `cat $tmpdir/caches`"; +die if $?; + +print "installing package...\n"; +system "nix-env -i $tmpdir/default.nix '*'"; +die if $?; + +print "installing succeeded! (enter to continue)\n"; +; diff --git a/scripts/nix-pull.in b/scripts/nix-pull.in index ad21b6f8a..1453a46ac 100644 --- a/scripts/nix-pull.in +++ b/scripts/nix-pull.in @@ -19,86 +19,98 @@ my @sucs; my $fullexpr = "["; -open CONFFILE, "<$conffile"; -while () { +sub processURL { + my $url = shift; + $url =~ s/\/$//; + print "obtaining list of Nix archives at $url...\n"; - chomp; - if (/^\s*(\S+)\s*(\#.*)?$/) { - my $url = $1; - $url =~ s/\/$//; - - print "obtaining list of Nix archives at $url...\n"; - - system "wget --cache=off '$url'/MANIFEST -O '$manifest' 2> /dev/null"; # !!! escape - if ($?) { die "`wget' failed"; } + system "wget --cache=off '$url'/MANIFEST -O '$manifest' 2> /dev/null"; # !!! escape + if ($?) { die "`wget' failed"; } - open MANIFEST, "<$manifest"; + open MANIFEST, "<$manifest"; - my $inside = 0; + my $inside = 0; - my $storepath; - my $narname; - my $hash; - my @preds; + my $storepath; + my $narname; + my $hash; + my @preds; - while () { - chomp; - s/\#.*$//g; - next if (/^$/); + while () { + chomp; + s/\#.*$//g; + next if (/^$/); - if (!$inside) { - if (/^\{$/) { - $inside = 1; - undef $storepath; - undef $narname; - undef $hash; - @preds = (); + if (!$inside) { + if (/^\{$/) { + $inside = 1; + undef $storepath; + undef $narname; + undef $hash; + @preds = (); } - else { die "bad line: $_"; } - } else { - if (/^\}$/) { - $inside = 0; - my $fullurl = "$url/$narname"; - print "$storepath\n"; + else { die "bad line: $_"; } + } else { + if (/^\}$/) { + $inside = 0; + my $fullurl = "$url/$narname"; +# print "$storepath\n"; - # Construct a Nix expression that fetches and unpacks a - # Nix archive from the network. - my $fetch = - "(import @datadir@/nix/corepkgs/fetchurl) " . - "{url = $fullurl; md5 = \"$hash\"; system = \"@host@\"}"; - my $nixexpr = - "((import @datadir@/nix/corepkgs/nar/unnar.nix) " . - "{narFile = ($fetch); outPath = \"$storepath\"; system = \"@host@\"}) "; - $fullexpr .= $nixexpr; # !!! O(n^2)? + # Construct a Nix expression that fetches and unpacks a + # Nix archive from the network. + my $fetch = + "(import @datadir@/nix/corepkgs/fetchurl) " . + "{url = $fullurl; md5 = \"$hash\"; system = \"@host@\"}"; + my $nixexpr = + "((import @datadir@/nix/corepkgs/nar/unnar.nix) " . + "{narFile = ($fetch); outPath = \"$storepath\"; system = \"@host@\"}) "; + $fullexpr .= $nixexpr; # !!! O(n^2)? - push @srcpaths, $storepath; + push @srcpaths, $storepath; - foreach my $p (@preds) { - push @sucs, $p; - push @sucs, $storepath; - } + foreach my $p (@preds) { + push @sucs, $p; + push @sucs, $storepath; + } - } - elsif (/^\s*StorePath:\s*(\/\S+)\s*$/) { - $storepath = $1; - } - elsif (/^\s*NarName:\s*(\S+)\s*$/) { - $narname = $1; - } - elsif (/^\s*MD5:\s*(\S+)\s*$/) { - $hash = $1; - } - elsif (/^\s*SuccOf:\s*(\/\S+)\s*$/) { - push @preds, $1; - } - else { die "bad line: $_"; } } + elsif (/^\s*StorePath:\s*(\/\S+)\s*$/) { + $storepath = $1; + } + elsif (/^\s*NarName:\s*(\S+)\s*$/) { + $narname = $1; + } + elsif (/^\s*MD5:\s*(\S+)\s*$/) { + $hash = $1; + } + elsif (/^\s*SuccOf:\s*(\/\S+)\s*$/) { + push @preds, $1; + } + else { die "bad line: $_"; } } - - close MANIFEST; } + close MANIFEST; +} + + +# Obtain URLs either from the command line or from a configuration file. +if (scalar @ARGV > 0) { + while (@ARGV) { + my $url = shift @ARGV; + processURL $url; + } +} else { + open CONFFILE, "<$conffile"; + while () { + chomp; + if (/^\s*(\S+)\s*(\#.*)?$/) { + my $url = $1; + processURL $url; + } + } + close CONFFILE; } $fullexpr .= "]";