Skip to content

Commit dbabbf2

Browse files
authored
Merge pull request #474 from nix-community/fix/generate-hardware-config
fix: `--generate-hardware-config` doesn't work with non-existent folders
2 parents ee813cc + bef18c7 commit dbabbf2

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/nixos-anywhere.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ parseArgs() {
201201
abort "Unknown hardware config backend: $2"
202202
;;
203203
esac
204-
hardwareConfigPath="$(realpath "$3")"
204+
hardwareConfigPath=$3
205205
shift
206206
shift
207207
;;
@@ -569,6 +569,8 @@ generateHardwareConfig() {
569569
570570
# to make sure nix knows about the new file
571571
if command -v git >/dev/null; then
572+
# handle relative paths
573+
hardwareConfigPath="$(realpath "$hardwareConfigPath")"
572574
pushd "$(dirname "$hardwareConfigPath")"
573575
if git rev-parse --is-inside-work-tree >/dev/null; then
574576
git add --intent-to-add --force -- "$hardwareConfigPath"

tests/from-nixos-generate-config.nix

+9-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
};
1717
testScript = ''
1818
start_all()
19+
installer.fail("test -f /tmp/hw/config.nix")
1920
installer.succeed("echo super-secret > /tmp/disk-1.key")
2021
output = installer.succeed("""
2122
nixos-anywhere \
@@ -25,7 +26,7 @@
2526
--disk-encryption-keys /tmp/disk-1.key /tmp/disk-1.key \
2627
--disk-encryption-keys /tmp/disk-2.key <(echo another-secret) \
2728
--phases kexec,disko \
28-
--generate-hardware-config nixos-generate-config /tmp/config.nix \
29+
--generate-hardware-config nixos-generate-config /tmp/hw/config.nix \
2930
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
3031
root@installed >&2
3132
echo "disk-1.key: '$(ssh -i /root/.ssh/install_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
@@ -34,12 +35,14 @@
3435
root@installed cat /tmp/disk-2.key)'"
3536
""")
3637
37-
installer.succeed("cat /tmp/config.nix >&2")
38-
installer.succeed("nix-instantiate --parse /tmp/config.nix")
38+
installer.succeed("cat /tmp/hw/config.nix >&2")
39+
installer.succeed("nix-instantiate --parse /tmp/hw/config.nix")
3940
4041
assert "disk-1.key: 'super-secret'" in output, f"output does not contain expected values: {output}"
4142
assert "disk-2.key: 'another-secret'" in output, f"output does not contain expected values: {output}"
4243
44+
installer.fail("test -f /test/hw/config.json")
45+
4346
output = installer.succeed("""
4447
nixos-anywhere \
4548
-i /root/.ssh/install_key \
@@ -48,7 +51,7 @@
4851
--disk-encryption-keys /tmp/disk-1.key /tmp/disk-1.key \
4952
--disk-encryption-keys /tmp/disk-2.key <(echo another-secret) \
5053
--phases kexec,disko \
51-
--generate-hardware-config nixos-facter /tmp/config.json \
54+
--generate-hardware-config nixos-facter /tmp/hw/config.json \
5255
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
5356
installed >&2
5457
echo "disk-1.key: '$(ssh -i /root/.ssh/install_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
@@ -57,8 +60,8 @@
5760
root@installed cat /tmp/disk-2.key)'"
5861
""")
5962
60-
installer.succeed("cat /tmp/config.json >&2")
61-
installer.succeed("jq < /tmp/config.json")
63+
installer.succeed("cat /tmp/hw/config.json >&2")
64+
installer.succeed("jq < /tmp/hw/config.json")
6265
6366
assert "disk-1.key: 'super-secret'" in output, f"output does not contain expected values: {output}"
6467
assert "disk-2.key: 'another-secret'" in output, f"output does not contain expected values: {output}"

0 commit comments

Comments
 (0)