Skip to content

Commit 8a49b35

Browse files
sabifyMic92
authored andcommitted
feat: take into effect system-features
1 parent 2cbfde7 commit 8a49b35

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

src/nixos-anywhere.sh

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,16 +1036,44 @@ main() {
10361036
sshConnection="root@${sshHost}"
10371037
fi
10381038
1039-
# Get substituters from the machine and add them to the installer
1040-
if [[ ${machineSubstituters} == "y" && -n ${flake} ]]; then
1041-
substituters=$(nix --extra-experimental-features 'nix-command flakes' eval --apply toString "${flake}"#"${flakeAttr}".nix.settings.substituters)
1042-
trustedPublicKeys=$(nix --extra-experimental-features 'nix-command flakes' eval --apply toString "${flake}"#"${flakeAttr}".nix.settings.trusted-public-keys)
1043-
1044-
runSsh sh <<SSH || true
1039+
# Get substituters and system-features from the machine and add them to the installer
1040+
if [[ -n ${flake} ]]; then
1041+
# Consolidate all nix settings evaluation into a single call
1042+
nixConfContent=$(nix --extra-experimental-features 'nix-command flakes' eval --raw --apply "
1043+
config:
1044+
let
1045+
settings = config.nix.settings or {};
1046+
hostPlatform = config.nixpkgs.hostPlatform or null;
1047+
gccArch = if hostPlatform != null then hostPlatform.gcc.arch or null else null;
1048+
1049+
# Combine system-features with platform-specific feature
1050+
baseFeatures = settings.system-features or [];
1051+
allFeatures = baseFeatures ++ (if gccArch != null then [\"gccarch-\${gccArch}\"] else []);
1052+
# Deduplicate using listToAttrs trick
1053+
uniqueFeatures = builtins.attrNames (builtins.listToAttrs (map (f: { name = f; value = true; }) allFeatures));
1054+
1055+
substituters = builtins.toString (settings.substituters or []);
1056+
trustedPublicKeys = builtins.toString (settings.trusted-public-keys or []);
1057+
systemFeatures = builtins.toString uniqueFeatures;
1058+
1059+
# Helper function for optional config lines
1060+
optionalLine = cond: line: if cond then line + \"\n\" else \"\";
1061+
1062+
# Build nix.conf content
1063+
useSubstituters = \"${machineSubstituters}\" == \"y\";
1064+
in
1065+
optionalLine (useSubstituters && substituters != \"\") \"extra-substituters = \${substituters}\"
1066+
+ optionalLine (useSubstituters && trustedPublicKeys != \"\") \"extra-trusted-public-keys = \${trustedPublicKeys}\"
1067+
+ optionalLine (systemFeatures != \"\") \"system-features = \${systemFeatures}\"
1068+
" "${flake}#${flakeAttr}")
1069+
1070+
# Write to nix.conf if we have any content
1071+
if [[ -n ${nixConfContent} ]]; then
1072+
runSsh sh <<SSH || true
10451073
mkdir -p ~/.config/nix
1046-
echo "extra-substituters = ${substituters}" >> ~/.config/nix/nix.conf
1047-
echo "extra-trusted-public-keys = ${trustedPublicKeys}" >> ~/.config/nix/nix.conf
1074+
echo "${nixConfContent}" >> ~/.config/nix/nix.conf
10481075
SSH
1076+
fi
10491077
fi
10501078
10511079
if [[ ${phases[disko]} == 1 ]]; then

0 commit comments

Comments
 (0)