Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: deterministic evaluation of expressions/derivations #709

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion corepkgs/local.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
corepkgs_FILES = nar.nix buildenv.nix buildenv.pl unpack-channel.nix derivation.nix fetchurl.nix imported-drv-to-derivation.nix
corepkgs_FILES = nar.nix buildenv.nix buildenv.pl unpack-channel.nix derivation.nix fetchurl.nix imported-drv-to-derivation.nix reproducable-derivation.nix

$(foreach file,config.nix $(corepkgs_FILES),$(eval $(call install-data-in,$(d)/$(file),$(datadir)/nix/corepkgs)))

Expand Down
15 changes: 15 additions & 0 deletions corepkgs/reproducable-derivation.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ recording, expressions}:
with import ./config.nix;
derivation {
name = "source-closure";
builder = shell;
args = ["-e" (__toFile "name" ''
#!/bin/bash
${coreutils}/mkdir -p $out/nix-support
${coreutils}/cp ${__toFile "deterministic-recording" recording} $out/nix-support/recording.nix
${coreutils}/cp ${__toFile "expressions" expressions} $out/nix-support/expressions.nix
echo "__playback { sources = { \"$out\" = ./.; }; functions = []; }" > $out/default.nix
echo "(__playback (import ./nix-support/recording.nix) (import ./nix-support/expressions.nix))" >> $out/default.nix
'')];
system = builtins.currentSystem;
}
16 changes: 15 additions & 1 deletion scripts/nix-build.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ my $pure = 0;
my $fromArgs = 0;
my $packages = 0;
my $interactive = 1;
my $playback = 0;

my @instArgs = ();
my @buildArgs = ();
Expand Down Expand Up @@ -124,6 +125,17 @@ for (my $n = 0; $n < scalar @ARGV; $n++) {
$n += 2;
}

elsif ($arg eq "--playback") {
die "$0: '$arg' requires an argument\n" unless $n + 1 < scalar @ARGV;
push @instArgs, ($arg, $ARGV[$n + 1]);
$playback = 1;
$n++;
}

elsif ($arg eq "--record") {
push @instArgs, $arg;
}

elsif ($arg eq "--max-jobs" || $arg eq "-j" || $arg eq "--max-silent-time" || $arg eq "--log-type" || $arg eq "--cores" || $arg eq "--timeout" || $arg eq '--add-root') {
$n++;
die "$0: ‘$arg’ requires an argument\n" unless $n < scalar @ARGV;
Expand Down Expand Up @@ -219,6 +231,7 @@ for (my $n = 0; $n < scalar @ARGV; $n++) {
}

die "$0: ‘-p’ and ‘-E’ are mutually exclusive\n" if $packages && $fromArgs;
die "$0: with --playback you can't supply expressions\n" if $playback && (scalar @exprs > 0 || $packages);

if ($packages) {
push @instArgs, "--expr";
Expand All @@ -243,8 +256,9 @@ foreach my $expr (@exprs) {
$expr = dirname(Cwd::abs_path($script)) . "/" . $expr
if $inShebang && !$packages && $expr !~ /^\//;

my @expression = $playback ? () : ($expr);
# !!! would prefer the perl 5.8.0 pipe open feature here.
my $pid = open(DRVPATHS, "-|") || exec "$Nix::Config::binDir/nix-instantiate", "--add-root", $drvLink, "--indirect", @instArgs, $expr;
my $pid = open(DRVPATHS, "-|") || exec "$Nix::Config::binDir/nix-instantiate", "--add-root", $drvLink, "--indirect", @instArgs, @expression;
while (<DRVPATHS>) {chomp; push @drvPaths, $_;}
if (!close DRVPATHS) {
die "nix-instantiate killed by signal " . ($? & 127) . "\n" if ($? & 127);
Expand Down
4 changes: 2 additions & 2 deletions src/libexpr/common-opts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ bool parseSearchPathArg(Strings::iterator & i,
}


Path lookupFileArg(EvalState & state, string s)
Path lookupFileArg(EvalState & state, string s, string currentPath)
{
if (isUri(s))
return downloadFileCached(s, true);
else if (s.size() > 2 && s.at(0) == '<' && s.at(s.size() - 1) == '>') {
Path p = s.substr(1, s.size() - 2);
return state.findFile(p);
} else
return absPath(s);
return absPath(s, currentPath);
}


Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/common-opts.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Bindings * evalAutoArgs(EvalState & state, std::map<string, string> & in);
bool parseSearchPathArg(Strings::iterator & i,
const Strings::iterator & argsEnd, Strings & searchPath);

Path lookupFileArg(EvalState & state, string s);
Path lookupFileArg(EvalState & state, string s, string currentPath = "");

}
Loading