2012-01-05 21:33:46 +01:00
|
|
|
|
#! @perl@ -w @perlFlags@
|
2003-11-24 12:11:40 +01:00
|
|
|
|
|
2014-08-29 17:48:25 +02:00
|
|
|
|
use utf8;
|
2003-11-24 12:11:40 +01:00
|
|
|
|
use strict;
|
2011-10-10 23:11:08 +02:00
|
|
|
|
use Nix::Config;
|
2012-07-30 23:09:36 +02:00
|
|
|
|
use Nix::Utils;
|
2008-11-20 16:44:59 +01:00
|
|
|
|
|
2014-08-29 17:48:25 +02:00
|
|
|
|
binmode STDERR, ":encoding(utf8)";
|
|
|
|
|
|
2006-09-21 20:54:08 +02:00
|
|
|
|
|
|
|
|
|
# Parse the command line arguments.
|
|
|
|
|
my @args = @ARGV;
|
|
|
|
|
|
|
|
|
|
my $source;
|
|
|
|
|
my $fromURL = 0;
|
|
|
|
|
my @extraNixEnvArgs = ();
|
|
|
|
|
my $interactive = 1;
|
2014-09-16 19:05:00 +02:00
|
|
|
|
my $op = "--install";
|
2006-09-21 20:54:08 +02:00
|
|
|
|
|
|
|
|
|
while (scalar @args) {
|
|
|
|
|
my $arg = shift @args;
|
|
|
|
|
if ($arg eq "--help") {
|
2012-10-03 22:37:06 +02:00
|
|
|
|
exec "man nix-install-package" or die;
|
2006-09-21 20:54:08 +02:00
|
|
|
|
}
|
|
|
|
|
elsif ($arg eq "--url") {
|
|
|
|
|
$fromURL = 1;
|
|
|
|
|
}
|
|
|
|
|
elsif ($arg eq "--profile" || $arg eq "-p") {
|
|
|
|
|
my $profile = shift @args;
|
2014-08-20 17:00:17 +02:00
|
|
|
|
die "$0: ‘--profile’ requires an argument\n" if !defined $profile;
|
2006-09-21 20:54:08 +02:00
|
|
|
|
push @extraNixEnvArgs, "-p", $profile;
|
|
|
|
|
}
|
2014-09-16 19:05:00 +02:00
|
|
|
|
elsif ($arg eq "--set") {
|
|
|
|
|
$op = "--set";
|
|
|
|
|
}
|
2006-09-21 20:54:08 +02:00
|
|
|
|
elsif ($arg eq "--non-interactive") {
|
|
|
|
|
$interactive = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$source = $arg;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-03 22:37:06 +02:00
|
|
|
|
die "$0: please specify a .nixpkg file or URL\n" unless defined $source;
|
2003-11-24 12:11:40 +01:00
|
|
|
|
|
|
|
|
|
|
2005-02-25 16:42:52 +01:00
|
|
|
|
# Re-execute in a terminal, if necessary, so that if we're executed
|
|
|
|
|
# from a web browser, the user gets to see us.
|
2006-09-21 20:54:08 +02:00
|
|
|
|
if ($interactive && !defined $ENV{"NIX_HAVE_TERMINAL"}) {
|
2005-02-25 16:42:52 +01:00
|
|
|
|
$ENV{"NIX_HAVE_TERMINAL"} = "1";
|
2005-03-11 16:27:37 +01:00
|
|
|
|
$ENV{"LD_LIBRARY_PATH"} = "";
|
2006-09-21 20:54:08 +02:00
|
|
|
|
foreach my $term ("xterm", "konsole", "gnome-terminal", "xterm") {
|
2011-10-10 23:11:08 +02:00
|
|
|
|
exec($term, "-e", "$Nix::Config::binDir/nix-install-package", @ARGV);
|
2006-09-21 13:29:14 +02:00
|
|
|
|
}
|
2014-08-20 17:00:17 +02:00
|
|
|
|
die "cannot execute ‘xterm’";
|
2005-02-25 16:42:52 +01:00
|
|
|
|
}
|
2003-11-24 12:11:40 +01:00
|
|
|
|
|
|
|
|
|
|
2014-08-13 23:12:57 +02:00
|
|
|
|
my $tmpDir = mkTempDir("nix-install-package");
|
2006-09-21 20:54:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub barf {
|
|
|
|
|
my $msg = shift;
|
2012-07-30 23:09:36 +02:00
|
|
|
|
print "\nInstallation failed: $msg\n";
|
2006-09-21 20:54:08 +02:00
|
|
|
|
<STDIN> if $interactive;
|
|
|
|
|
exit 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Download the package description, if necessary.
|
|
|
|
|
my $pkgFile = $source;
|
|
|
|
|
if ($fromURL) {
|
|
|
|
|
$pkgFile = "$tmpDir/tmp.nixpkg";
|
2015-01-30 01:56:01 +01:00
|
|
|
|
system("@curl@", "-L", "--silent", $source, "-o", $pkgFile) == 0
|
2006-09-21 20:54:08 +02:00
|
|
|
|
or barf "curl failed: $?";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-25 16:42:52 +01:00
|
|
|
|
# Read and parse the package file.
|
2014-08-20 17:00:17 +02:00
|
|
|
|
open PKGFILE, "<$pkgFile" or barf "cannot open ‘$pkgFile’: $!";
|
2005-02-25 16:42:52 +01:00
|
|
|
|
my $contents = <PKGFILE>;
|
|
|
|
|
close PKGFILE;
|
2003-11-24 12:11:40 +01:00
|
|
|
|
|
2006-09-21 20:54:08 +02:00
|
|
|
|
my $nameRE = "(?: [A-Za-z0-9\+\-\.\_\?\=]+ )"; # see checkStoreName()
|
|
|
|
|
my $systemRE = "(?: [A-Za-z0-9\+\-\_]+ )";
|
|
|
|
|
my $pathRE = "(?: \/ [\/A-Za-z0-9\+\-\.\_\?\=]* )";
|
|
|
|
|
|
|
|
|
|
# Note: $pathRE doesn't check that whether we're looking at a valid
|
|
|
|
|
# store path. We'll let nix-env do that.
|
|
|
|
|
|
|
|
|
|
$contents =~
|
2012-07-30 23:09:36 +02:00
|
|
|
|
/ ^ \s* (\S+) \s+ ($Nix::Utils::urlRE) \s+ ($nameRE) \s+ ($systemRE) \s+ ($pathRE) \s+ ($pathRE) ( \s+ ($Nix::Utils::urlRE) )? /x
|
2006-09-21 20:54:08 +02:00
|
|
|
|
or barf "invalid package contents";
|
2005-02-25 16:42:52 +01:00
|
|
|
|
my $version = $1;
|
|
|
|
|
my $manifestURL = $2;
|
|
|
|
|
my $drvName = $3;
|
|
|
|
|
my $system = $4;
|
|
|
|
|
my $drvPath = $5;
|
|
|
|
|
my $outPath = $6;
|
2012-07-30 22:11:02 +02:00
|
|
|
|
my $binaryCacheURL = $8;
|
2005-02-25 16:42:52 +01:00
|
|
|
|
|
2014-08-20 17:00:17 +02:00
|
|
|
|
barf "invalid package version ‘$version’" unless $version eq "NIXPKG1";
|
2005-02-25 16:42:52 +01:00
|
|
|
|
|
|
|
|
|
|
2006-09-21 20:54:08 +02:00
|
|
|
|
if ($interactive) {
|
|
|
|
|
# Ask confirmation.
|
2014-08-20 17:00:17 +02:00
|
|
|
|
print "Do you want to install ‘$drvName’ (Y/N)? ";
|
2006-09-21 20:54:08 +02:00
|
|
|
|
my $reply = <STDIN>;
|
|
|
|
|
chomp $reply;
|
|
|
|
|
exit if $reply ne "y" && $reply ne "Y";
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-24 12:11:40 +01:00
|
|
|
|
|
2012-07-30 22:11:02 +02:00
|
|
|
|
if (defined $binaryCacheURL) {
|
2009-02-27 15:06:38 +01:00
|
|
|
|
|
2014-08-07 22:41:44 +02:00
|
|
|
|
push @extraNixEnvArgs, "--option", "extra-binary-caches", $binaryCacheURL;
|
2009-02-27 15:06:38 +01:00
|
|
|
|
|
2012-07-30 22:11:02 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
# Store the manifest in the temporary directory so that we don't
|
|
|
|
|
# pollute /nix/var/nix/manifests. This also requires that we
|
|
|
|
|
# don't use the Nix daemon (because otherwise
|
|
|
|
|
# download-using-manifests won't see our NIX_MANIFESTS_DIRS
|
|
|
|
|
# environment variable).
|
|
|
|
|
$ENV{NIX_MANIFESTS_DIR} = $tmpDir;
|
|
|
|
|
$ENV{NIX_REMOTE} = "";
|
|
|
|
|
|
|
|
|
|
print "\nPulling manifests...\n";
|
|
|
|
|
system("$Nix::Config::binDir/nix-pull", $manifestURL) == 0
|
|
|
|
|
or barf "nix-pull failed: $?";
|
|
|
|
|
|
|
|
|
|
}
|
2006-09-21 20:54:08 +02:00
|
|
|
|
|
2003-11-24 12:11:40 +01:00
|
|
|
|
|
2005-02-25 16:42:52 +01:00
|
|
|
|
print "\nInstalling package...\n";
|
2014-09-16 19:05:00 +02:00
|
|
|
|
system("$Nix::Config::binDir/nix-env", $op, $outPath, "--force-name", $drvName, @extraNixEnvArgs) == 0
|
2006-09-21 20:54:08 +02:00
|
|
|
|
or barf "nix-env failed: $?";
|
|
|
|
|
|
2003-11-24 12:11:40 +01:00
|
|
|
|
|
2006-09-21 20:54:08 +02:00
|
|
|
|
if ($interactive) {
|
|
|
|
|
print "\nInstallation succeeded! Press Enter to continue.\n";
|
|
|
|
|
<STDIN>;
|
|
|
|
|
}
|