Repository navigation
Open
Description
Describe the bug
A derivation named *.drv may only have a single text-hashed out output. The evaluator enforces this (primops.cc:1849); the store does not.
A builder can write an x.drv with two .drv outputs, out and r.drv, and both ^out^out and ^r.drv^out build. The same derivation written in Nix fails to evaluate.
Which side is intended?
This came up while discussing fanning out dynamic derivations: https://lobste.rs/s/md0vco/beer_drv_drv_drv#c_yovs8p
Steps to reproduce
fanout.sh:
export PATH=$busybox/bin
# Placeholders for the inner derivation's outputs, hardcoded here because
# they are rewritten in env/args but not in file contents.
PH_OUT=/1rz4g4znpzjwh1xymhjpm42vipw92pr73vdgl6xs1hycac8kf2n9
PH_R=/15anh2d7wf3i6bs7kfxx19wwffl1jqfsy769yjhwk0q9rb89rlqm
srcs=$(printf '"%s"\n' "$busybox" "$left" "$right" | sort | paste -sd, -)
# Inner derivation "x.drv" with two outputs, each a .drv file.
tr -d '\n' > $out <<ATERM
Derive([("out","","text:sha256",""),("r.drv","","text:sha256","")],[],[$srcs],"$system","$busybox/bin/sh",["-c","$busybox/bin/cp $left $PH_OUT; $busybox/bin/cp $right $PH_R"],[("builder","$busybox/bin/sh"),("name","x.drv"),("out","$PH_OUT"),("outputHashAlgo","sha256"),("outputHashMode","text"),("outputs","out r.drv"),("r.drv","$PH_R"),("system","$system")])
ATERMrepro.nix:
let
pkgs = import <nixpkgs> { };
busybox = pkgs.busybox;
# Content-addressed leaves, so a leaf's .drv can be stored under any name.
leaf = name: msg: derivation {
inherit name;
system = builtins.currentSystem;
builder = "${busybox}/bin/sh";
args = [ "-c" "echo ${msg} > $out" ];
__contentAddressed = true;
outputHashMode = "recursive";
outputHashAlgo = "sha256";
};
drvFile = d: builtins.unsafeDiscardOutputDependency d.drvPath;
# Outputs the two-output derivation "x.drv".
top = derivation {
name = "x.drv.drv";
system = builtins.currentSystem;
builder = "${busybox}/bin/sh";
args = [ ./fanout.sh ];
inherit busybox;
left = drvFile (leaf "x" "left");
right = drvFile (leaf "x.drv-r" "right");
__contentAddressed = true;
outputHashMode = "text";
outputHashAlgo = "sha256";
};
in
{
left = builtins.outputOf (builtins.outputOf top.outPath "out") "out";
right = builtins.outputOf (builtins.outputOf top.outPath "r.drv") "out";
# The same output shape, written in Nix.
evaluated = derivation {
name = "x.drv";
outputs = [ "out" "r.drv" ];
system = builtins.currentSystem;
builder = "${busybox}/bin/sh";
args = [ "-c" "" ];
__contentAddressed = true;
outputHashMode = "text";
outputHashAlgo = "sha256";
};
}$ export NIX_CONFIG="extra-experimental-features = nix-command dynamic-derivations ca-derivations"
$ nix build --impure -f repro.nix left right --print-out-paths
/nix/store/s9nk9v17kw4aq4zg4dafrvnh3amwqjmd-x
/nix/store/dxx2rgln8pimkyrwf8n9abykrdvzk11k-x.drv-r
$ nix build --impure -f repro.nix evaluated
error:
… while evaluating derivation 'x.drv'
...
error: derivation names are allowed to end in '.drv' only if they produce a single derivation fileExpected behavior
The evaluator and the store agree on which derivations may output derivations.
Metadata
nix 2.35.2. The check is the same on master (7d83031e0).
Metadata
Metadata
Assignees
Labels
No labels
Activity
fzakaria commentedon Nov 16, 2026
CC @tomberek and @Ericson2314 for dynamic derivation working group.
fzakaria commentedon Nov 16, 2026
Correction: the check only looks at the derivation's own name. A derivation named
pwith outputsa.drvandb.drvevaluates and builds, and the outputs may even depend on each other. So the evaluator doesn't block multiple.drvoutputs, only a.drvname with more than one output.It also accepts
outputHashMode = "flat"for an output nameda.drv; the store then rejects the content at registration:Maybe the rule belongs on output paths ending in
.drvrather than on the derivation name.[-]Evaluator rejects multi-output .drv-producing derivations that the store builds[/-][+]`.drv` output rule checks the derivation name, not the output paths[/+]