-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
Description
Describe the bug
The command below computes the attribute target_attribute
from the file some_file.nix
which is great. In nix-build one would have used -A target_attribute
but modern nix lacks this feature sadly.
nix build --file some_file.nix target_attribute -L
Here is the actual issue I'm having:
nix build --file some_file.nix target_attribute -L ""
Selects all attributes in some_file.nix
instead. It does not complain that there were to attribute selectors used, namely:
- target_attribute
- ""
[nixos@nixos:~/cargo]$ nix build target --file /home/nixos/cargo/target/debug/nix/cargo_build_caller.nix --out-link /home/nixos/cargo/target/debug/nix/result_cargo_build -L --json 2> logone --json
[{"drvPath":"/nix/store/jlrg8r0mk0vvqr1vy6xz481nkkf1aln7-create-symlinks.drv","outputs":{"out":"/nix/store/4gkjmbxscgcizxhkl7m4pj14blp4l1fy-create-symlinks"},"startTime":1758229834,"stopTime":1758229835}]
[nixos@nixos:~/cargo]$ nix build target --file /home/nixos/cargo/target/debug/nix/cargo_build_caller.nix --out-link /home/nixos/cargo/target/debug/nix/result_cargo_build -L "" --json 2> logone --json
[{"drvPath":"/nix/store/h2vmn24d46af906m57y0xsy2ps7vyb0q-create-symlinks.drv","outputs":{"out":"/nix/store/n0w4xchhwgn8fm8r165976xljbxvxr0m-create-symlinks"},"startTime":1758230058,"stopTime":1758230058},{"drvPath":"/nix/store/0kncplr5wjn1a4nwihw42c9ssswdnadh-cargo-util-0_2_20-7087e4a73afc7b23.drv","outputs":{"out":"/nix/store/1jmghvpdpnyylpmkcw29rc5xslhsszkp-cargo-util-0_2_20-7087e4a73afc7b23"}},{"drvPath":"/nix/store/19ynnn8slfzgrfi1za06y4in8w58g0gy-cargo-0_88_0-bin-85e09d7d8299b1ad.drv","outputs":{"out":"/nix/store/jyg4ibszx92vgy1kkj40p3k7iyvn3xcy-cargo-0_88_0-bin-85e09d7d8299b1ad"},"startTime":1758230043,"stopTime":1758230057},{"drvPath":"/nix/store/1nzdj74ya3wfisyyh3xqncq4s4z50dys-create-symlinks.drv","outputs":{"out":"/nix/store/6w25lpvv237j7pflim6fkycfd3i2qw73-create-symlinks"},"startTime":1758230058,"stopTime":1758230058},{"drvPath":"/nix/store/3i2plbf5r3c9i3997c7rxlcwif0vfy4r-cargo-0_88_0-27e7993d9cf32df7.drv","outputs":{"out":"/nix/store/kymqq8m2a83iqcb0pzczq7hm89wf3l81-cargo-0_88_0-27e7993d9cf32df7"}},{"drvPath":"/nix/store/41pbal5n27sx3yl47lhl1w6yb8k4k4hc-cargo-platform-0_2_0-c5f768769f22a333.drv","outputs":{"out":"/nix/store/plsnbjpkwgmhx0dnlzfnlakxd8j9p11j-cargo-platform-0_2_0-c5f768769f22a333"}},{"drvPath":"/nix/store/48dggnmjgywz9bnpc0j27iyafimw8lcf-cargo-0_88_0-script_build-cfc654fccb259515.drv","outputs":{"out":"/nix/store/hma4jxcg68l0976m9l94zf38p6ha6vfy-cargo-0_88_0-script_build-cfc654fccb259515"}},{"drvPath":"/nix/store/5g8bd29nhjbxcjqlsjnlymx2cwaipms0-crates-io-0_40_10-cb0425982b906266.drv","outputs":{"out":"/nix/store/73i7swm6w90fnpxwzl64sw78xqxbv15p-crates-io-0_40_10-cb0425982b906266"}},{"drvPath":"/nix/store/cc90k44i9kj42gsqvnk457wv5jaq0qm9-cargo-credential-libsecret-0_4_13-4e698a0b35f72d06.drv","outputs":{"out":"/nix/store/pfqr8ql1p0ka10vf80shzizadrsw8h1g-cargo-credential-libsecret-0_4_13-4e698a0b35f72d06"}},{"drvPath":"/nix/store/ixbgqqa8n8p341vc8ds6svk0v44lh4i0-cargo-util-schemas-0_8_1-bce7b79eff35b46a.drv","outputs":{"out":"/nix/store/kic7w70gy1h7pjhm6a9sa8wnvflyq7gr-cargo-util-schemas-0_8_1-bce7b79eff35b46a"}},{"drvPath":"/nix/store/pc0ivavr7blqjp3rbzv2d3vylkb8k2hh-cargo-0_88_0-script_build_run-f5d51778f22880c0.drv","outputs":{"out":"/nix/store/v5bydm1zqwsa9irnr3qsihyrzpmy2pla-cargo-0_88_0-script_build_run-f5d51778f22880c0"}},{"drvPath":"/nix/store/s4860s8bfchmwik57rscnmafg9ky2am5-rustfix-0_9_0-9f1c66820d29e14a.drv","outputs":{"out":"/nix/store/hpfsnvg3y1dl2h8yyh3cck8fpfzpia2j-rustfix-0_9_0-9f1c66820d29e14a"}},{"drvPath":"/nix/store/y9ivm927qqxxsz9zfwam2l90nxrm9f28-cargo-credential-0_4_8-a5adc6ab9fe103b0.drv","outputs":{"out":"/nix/store/plyif7d6cll5mgpl3rsscgplr8yi9bgl-cargo-credential-0_4_8-a5adc6ab9fe103b0"}}]
Steps To Reproduce
Just create a default.nix with two attributes like:
[nixos@nixos:~/cargo]$ cat default.nix
{pkgs ? import <nixpkgs>{}}:{
c = pkgs.stdenv.mkDerivation {
name="asdf c";
src = ./in;
phases = [ "installPhase" ];
installPhase=''
mkdir -p $out
echo "asdf1" > $out/asdf
'';
};
b = pkgs.stdenv.mkDerivation {
name="asdf b";
src = ./in;
phases = [ "installPhase" ];
installPhase=''
mkdir -p $out
echo "asdf1" > $out/asdf
'';
};
a = pkgs.stdenv.mkDerivation {
name="asdf a";
src = ./in;
phases = [ "installPhase" ];
installPhase=''
mkdir -p $out
echo "asdf1" > $out/asdf
'';
};
}
[nixos@nixos:~/cargo]$ nix build --file default.nix a --json
[{"drvPath":"/nix/store/49m9pmba1cggvc10r5l7ar0dfsg2ahp4-asdf-a.drv","outputs":{"out":"/nix/store/x961gy1494ng506pd0c4ng396xyd0zpz-asdf-a"}}]
[nixos@nixos:~/cargo]$ nix build --file default.nix a --json ""
[{"drvPath":"/nix/store/49m9pmba1cggvc10r5l7ar0dfsg2ahp4-asdf-a.drv","outputs":{"out":"/nix/store/x961gy1494ng506pd0c4ng396xyd0zpz-asdf-a"}},{"drvPath":"/nix/store/49m9pmba1cggvc10r5l7ar0dfsg2ahp4-asdf-a.drv","outputs":{"out":"/nix/store/x961gy1494ng506pd0c4ng396xyd0zpz-asdf-a"}},{"drvPath":"/nix/store/49m9pmba1cggvc10r5l7ar0dfsg2ahp4-asdf-a.drv","outputs":{"out":"/nix/store/x961gy1494ng506pd0c4ng396xyd0zpz-asdf-a"}},{"drvPath":"/nix/store/49m9pmba1cggvc10r5l7ar0dfsg2ahp4-asdf-a.drv","outputs":{"out":"/nix/store/x961gy1494ng506pd0c4ng396xyd0zpz-asdf-a"}},{"drvPath":"/nix/store/h829c0gqcfdxbasis21bdmxy31al9mg0-asdf-c.drv","outputs":{"out":"/nix/store/7g5aaxfiri48p5lhzhx2200qlfxxf5sn-asdf-c"}},{"drvPath":"/nix/store/vl2m1h8xdms8nwzf99rd0pgwr3ikg9gz-asdf-b.drv","outputs":{"out":"/nix/store/2ln6ilcfjlcispxiyhi6k1isz2rzai9r-asdf-b"}}]
Expected behavior
Not exactly sure but I propose that:
- "" causes an error instead of selecting all
- "*" <- if anything, maybe this could select all?
- since
target_attribute
and""
both were given, print an error that says you can only supply one attribute selector at max.
Can I please have my -A
back?
Checklist
nix --version
nix (Nix) 2.28.3
- checked latest Nix manual (source)
- checked open bug issues and pull requests for possible duplicates
Add 👍 to issues you find important.