fix: flakes now obey --eval-system

This required changing an excessive number of places since flakes code
is a delicious bowl of copy pasta.

I didn't change all of the usage sites since some of them run things on
the local machine and you actually want it to be the real system there.

Nevertheless, we probably should have the daemon do something much
different when it receives a `system` setting:
https://git.lix.systems/lix-project/lix/issues/694

Fixes: https://git.lix.systems/lix-project/lix/issues/692
Fixes: https://git.lix.systems/lix-project/lix/issues/673
Fixes: https://github.com/NixOS/nix/issues/11359
Change-Id: I55e696c09794d2520b60238a84829c98fcad7ccc
This commit is contained in:
Jade Lovelace
2025-02-26 12:05:07 -08:00
parent 596ffc290e
commit 29f5ce07db
11 changed files with 56 additions and 12 deletions
+5
View File
@@ -107,6 +107,11 @@ cat > $flakeDir/flake.nix <<EOF
EOF
nix flake check $flakeDir
# --eval-system should be considered for which the local system is for flake
# purposes, and thus it should fail checking that attr
(! nix flake check --eval-system system-1 $flakeDir)
# likewise with --system
(! nix flake check --system system-1 $flakeDir)
checkRes=$(nix flake check --all-systems --keep-going $flakeDir 2>&1 && fail "nix flake check --all-systems should have failed" || true)
echo "$checkRes" | grepQuiet "packages.system-1.default"
+5
View File
@@ -126,6 +126,11 @@ nix build -o $TEST_ROOT/result git+file://$flake1Dir
nix build -o $flake1Dir/result git+file://$flake1Dir
nix path-info $flake1Dir/result
# Ensure that eval-system affects the chosen attribute
cp -r "$flake1Dir" "$flake1Dir.kittified"
sed -i "s#$system#kitty-kitty#" "$flake1Dir.kittified/flake.nix"
nix build --eval-system kitty-kitty "$flake1Dir.kittified"
# 'getFlake' on an unlocked flakeref should fail in pure mode, but
# succeed in impure mode.
(! nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"$flake1Dir\").packages.$system.default")
+7
View File
@@ -7,6 +7,8 @@ writeSimpleFlake "$flakeDir"
cd "$flakeDir"
# FIXME(jade): the following is rather absurd. we have jq!
# By default: Only show the packages content for the current system and no
# legacyPackages at all
nix flake show --json > show-output.json
@@ -19,6 +21,11 @@ assert show_output.legacyPackages.${builtins.currentSystem} == {};
true
'
# Follow --eval-system for determining the system for flakes
nix flake show --eval-system someOtherSystem --json > show-output.json
drvTitle=$(jq -r '.packages.someOtherSystem.default.name' show-output.json)
[[ $drvTitle == 'simple' ]]
# With `--all-systems`, show the packages for all systems
nix flake show --json --all-systems > show-output.json
nix eval --impure --expr '