home-manager: Feature test for flake support (#6824)

Feature testing flakes / nix-command is more robust over configuration
sniffing. Ultimately, the deciding factor should be if flakes work --
not if the config looks like they will / won't work.

This alternative test both asserts that the `nix` command is enabled,
and that flakes are enabled, without depending on whether or not
flakes are emitted as an experimental feature.

This is both repairing support for Determinate Nix 3, and prepares for
a potential future where Nix itself considers Flakes stable.

Closes #6702
This commit is contained in:
Graham Christensen 2025-04-15 12:48:20 -04:00 committed by GitHub
parent d5cdf55bd9
commit 85c513aa86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -43,13 +43,9 @@ function setWorkDir() {
fi
}
# Checks whether the 'flakes' and 'nix-command' Nix options are enabled.
# Check to see if flakes are functionally available.
function hasFlakeSupport() {
type -p nix > /dev/null \
&& nix show-config 2> /dev/null \
| grep experimental-features \
| grep flakes \
| grep -q nix-command
nix eval --expr 'builtins.getFlake' > /dev/null 2>&1
}
# Escape string for use in Nix files.