Skip to content

terraform: error: Have you forgotten to run nixos-anywhere with --generate-hardware-config nixos-generate-config ./hardware-configuration.nix? #588

@kaptcha0

Description

@kaptcha0

Prerequisites

  • I have updated to the latest version using nix run --refresh github:nix-community/nixos-anywhere
  • I have reproduced the issue with the --debug flag
  • I have searched existing issues to make sure this isn't a duplicate

Bug Description

I'm trying to use the terraform all-in-one module (or the install module for that matter), but I get the following error:

error: Have you forgotten to run nixos-anywhere with `--generate-hardware-config nixos-generate-config ./hardware-configuration.nix`?

Steps to Reproduce

  1. Follow an example from terraform/all-in-one.

Debug Logs

Here are the debug logs from the `tofu apply` command
stall.module.deploy["k3s-server-0"].module.partitioner-build.data.external.nix
module.nixos-install.module.deploy["k3s-agent-0"].module.partitioner-build.data.external.nix-build: Reading...
module.nixos-install.module.deploy["k3s-agent-0"].module.system-build.data.external.nix-build: Reading...
╷
│ Error: External Program Execution Failed
│
│   with module.nixos-install.module.deploy["k3s-agent-0"].module.system-build.data.external.nix-build,
│   on .terraform/modules/nixos-install.deploy/terraform/nix-build/main.tf line 7, in data "external" "nix-build":
│    7:   program = ["${path.module}/nix-build.sh"]
│
│ The data source received an unexpected error while attempting to execute the program.
│
│ Program: .terraform/modules/nixos-install.deploy/terraform/nix-build/nix-build.sh
│ Error Message: + '[' '{"options":{}}' '!=' '{"options":{}}' ']'
│ + options=
│ + [[ {"terraform":{"hostname":"k3s-server-0","user":"terraform"}} == {} ]]
│ + [[ null != null ]]
│ ++ echo
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install#nixosConfigurations.generic.config.system.build.toplevel
│ ++ cut -d '#' -f 2
│ + rest=nixosConfigurations.generic.config.system.build.toplevel
│ + config_path=nixosConfigurations.generic
│ + config_attribute=config.system.build.toplevel
│ ++ echo
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install#nixosConfigurations.generic.config.system.build.toplevel
│ ++ cut -d '#' -f 1
│ + flake_rel=/home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install
│ ++ nix flake prefetch
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install --json
│ +
│ prefetch_result='{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ echo'{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ jq -r .storePath
│ + store_path=/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source
│ ++ echo'{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ jq -r .hash
│ + nar_hash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=
│ +
│ flake_url='path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='
│ + nix_expr='(builtins.getFlake
'\'''\''path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='\'''\'').nixosConfigurations.generic.extendModules
│ { specialArgs = builtins.fromJSON
'\'''\''{"terraform":{"hostname":"k3s-server-0","user":"terraform"}}'\'''\''; }'
│ ++ nix build --no-link --json --expr '(builtins.getFlake
'\'''\''path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='\'''\'').nixosConfigurations.generic.extendModules
│ { specialArgs = builtins.fromJSON
'\'''\''{"terraform":{"hostname":"k3s-server-0","user":"terraform"}}'\'''\''; }'
│ config.system.build.toplevel
│ error:
│        … while calling the 'seq' builtin
│          at /nix/store/4vsv6wrnqrynrlnclblrz1f3xq49s7v1-source/lib/modules.nix:361:18:
│           360|         options = checked options;
│           361|         config = checked (removeAttrs config [ "_module" ]);|                  ^
│           362|         _module = checked (config._module);
│
│        … while evaluating a branch condition
│          at /nix/store/4vsv6wrnqrynrlnclblrz1f3xq49s7v1-source/lib/modules.nix:297:9:
│           296|       checkUnmatched =
│           297|         if config._module.check && config._module.freeformType == null && merged.unmatchedDefns != [ ] then|         ^
│           298|           let
│
│        (stack trace truncated; use '--show-trace' to show the full, detailed trace)
│
│        error: Have you forgotten to run nixos-anywhere with `--generate-hardware-config nixos-generate-config ./hardware-configuration.nix`?
│ + out=
│
│ State: exit status 1
╵
╷
│ Error: External Program Execution Failed
│
│   with module.nixos-install.module.deploy["k3s-server-0"].module.system-build.data.external.nix-build,
│   on .terraform/modules/nixos-install.deploy/terraform/nix-build/main.tf line 7, in data "external" "nix-build":
│    7:   program = ["${path.module}/nix-build.sh"]
│
│ The data source received an unexpected error while attempting to execute the program.
│
│ Program: .terraform/modules/nixos-install.deploy/terraform/nix-build/nix-build.sh
│ Error Message: + '[' '{"options":{}}' '!=' '{"options":{}}' ']'
│ + options=
│ + [[ {"terraform":{"hostname":"k3s-server-0","user":"terraform"}} == {} ]]
│ + [[ null != null ]]
│ ++ echo
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install#nixosConfigurations.generic.config.system.build.toplevel
│ ++ cut -d '#' -f 2
│ + rest=nixosConfigurations.generic.config.system.build.toplevel
│ + config_path=nixosConfigurations.generic
│ + config_attribute=config.system.build.toplevel
│ ++ echo
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install#nixosConfigurations.generic.config.system.build.toplevel
│ ++ cut -d '#' -f 1
│ + flake_rel=/home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install
│ ++ nix flake prefetch
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install --json
│ +
│ prefetch_result='{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ echo'{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ jq -r .storePath
│ + store_path=/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source
│ ++ echo'{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ jq -r .hash
│ + nar_hash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=
│ +
│ flake_url='path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='
│ + nix_expr='(builtins.getFlake
'\'''\''path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='\'''\'').nixosConfigurations.generic.extendModules
│ { specialArgs = builtins.fromJSON
'\'''\''{"terraform":{"hostname":"k3s-server-0","user":"terraform"}}'\'''\''; }'
│ ++ nix build --no-link --json --expr '(builtins.getFlake
'\'''\''path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='\'''\'').nixosConfigurations.generic.extendModules
│ { specialArgs = builtins.fromJSON
'\'''\''{"terraform":{"hostname":"k3s-server-0","user":"terraform"}}'\'''\''; }'
│ config.system.build.toplevel
│ error:
│        … while calling the 'seq' builtin
│          at /nix/store/4vsv6wrnqrynrlnclblrz1f3xq49s7v1-source/lib/modules.nix:361:18:
│           360|         options = checked options;
│           361|         config = checked (removeAttrs config [ "_module" ]);|                  ^
│           362|         _module = checked (config._module);
│
│        … while evaluating a branch condition
│          at /nix/store/4vsv6wrnqrynrlnclblrz1f3xq49s7v1-source/lib/modules.nix:297:9:
│           296|       checkUnmatched =
│           297|         if config._module.check && config._module.freeformType == null && merged.unmatchedDefns != [ ] then|         ^
│           298|           let
│
│        (stack trace truncated; use '--show-trace' to show the full, detailed trace)
│
│        error: Have you forgotten to run nixos-anywhere with `--generate-hardware-config nixos-generate-config ./hardware-configuration.nix`?
│ + out=
│
│ State: exit status 1
╵
╷
│ Error: External Program Execution Failed
│
│   with module.nixos-install.module.deploy["k3s-agent-1"].module.partitioner-build.data.external.nix-build,
│   on .terraform/modules/nixos-install.deploy/terraform/nix-build/main.tf line 7, in data "external" "nix-build":
│    7:   program = ["${path.module}/nix-build.sh"]
│
│ The data source received an unexpected error while attempting to execute the program.
│
│ Program: .terraform/modules/nixos-install.deploy/terraform/nix-build/nix-build.sh
│ Error Message: + '[' '{"options":{}}' '!=' '{"options":{}}' ']'
│ + options=
│ + [[ {"terraform":{"hostname":"k3s-server-0","user":"terraform"}} == {} ]]
│ + [[ null != null ]]
│ ++ echo
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install#nixosConfigurations.generic.config.system.build.diskoScript
│ ++ cut -d '#' -f 2
│ + rest=nixosConfigurations.generic.config.system.build.diskoScript
│ + config_path=nixosConfigurations.generic
│ + config_attribute=config.system.build.diskoScript
│ ++ echo
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install#nixosConfigurations.generic.config.system.build.diskoScript
│ ++ cut -d '#' -f 1
│ + flake_rel=/home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install
│ ++ nix flake prefetch
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install --json
│ +
│ prefetch_result='{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ echo'{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ jq -r .storePath
│ + store_path=/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source
│ ++ echo'{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ jq -r .hash
│ + nar_hash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=
│ +
│ flake_url='path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='
│ + nix_expr='(builtins.getFlake
'\'''\''path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='\'''\'').nixosConfigurations.generic.extendModules
│ { specialArgs = builtins.fromJSON
'\'''\''{"terraform":{"hostname":"k3s-server-0","user":"terraform"}}'\'''\''; }'
│ ++ nix build --no-link --json --expr '(builtins.getFlake
'\'''\''path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='\'''\'').nixosConfigurations.generic.extendModules
│ { specialArgs = builtins.fromJSON
'\'''\''{"terraform":{"hostname":"k3s-server-0","user":"terraform"}}'\'''\''; }'
│ config.system.build.diskoScript
│ error:
│        … while calling the 'seq' builtin
│          at /nix/store/4vsv6wrnqrynrlnclblrz1f3xq49s7v1-source/lib/modules.nix:361:18:
│           360|         options = checked options;
│           361|         config = checked (removeAttrs config [ "_module" ]);|                  ^
│           362|         _module = checked (config._module);
│
│        … while evaluating a branch condition
│          at /nix/store/4vsv6wrnqrynrlnclblrz1f3xq49s7v1-source/lib/modules.nix:297:9:
│           296|       checkUnmatched =
│           297|         if config._module.check && config._module.freeformType == null && merged.unmatchedDefns != [ ] then|         ^
│           298|           let
│
│        (stack trace truncated; use '--show-trace' to show the full, detailed trace)
│
│        error: Have you forgotten to run nixos-anywhere with `--generate-hardware-config nixos-generate-config ./hardware-configuration.nix`?
│ + out=
│
│ State: exit status 1
╵
╷
│ Error: External Program Execution Failed
│
│   with module.nixos-install.module.deploy["k3s-agent-0"].module.partitioner-build.data.external.nix-build,
│   on .terraform/modules/nixos-install.deploy/terraform/nix-build/main.tf line 7, in data "external" "nix-build":
│    7:   program = ["${path.module}/nix-build.sh"]
│
│ The data source received an unexpected error while attempting to execute the program.
│
│ Program: .terraform/modules/nixos-install.deploy/terraform/nix-build/nix-build.sh
│ Error Message: + '[' '{"options":{}}' '!=' '{"options":{}}' ']'
│ + options=
│ + [[ {"terraform":{"hostname":"k3s-server-0","user":"terraform"}} == {} ]]
│ + [[ null != null ]]
│ ++ echo
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install#nixosConfigurations.generic.config.system.build.diskoScript
│ ++ cut -d '#' -f 2
│ + rest=nixosConfigurations.generic.config.system.build.diskoScript
│ + config_path=nixosConfigurations.generic
│ + config_attribute=config.system.build.diskoScript
│ ++ echo
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install#nixosConfigurations.generic.config.system.build.diskoScript
│ ++ cut -d '#' -f 1
│ + flake_rel=/home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install
│ ++ nix flake prefetch
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install --json
│ +
│ prefetch_result='{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ echo'{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ jq -r .storePath
│ + store_path=/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source
│ ++ echo'{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ jq -r .hash
│ + nar_hash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=
│ +
│ flake_url='path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='
│ + nix_expr='(builtins.getFlake
'\'''\''path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='\'''\'').nixosConfigurations.generic.extendModules
│ { specialArgs = builtins.fromJSON
'\'''\''{"terraform":{"hostname":"k3s-server-0","user":"terraform"}}'\'''\''; }'
│ ++ nix build --no-link --json --expr '(builtins.getFlake
'\'''\''path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='\'''\'').nixosConfigurations.generic.extendModules
│ { specialArgs = builtins.fromJSON
'\'''\''{"terraform":{"hostname":"k3s-server-0","user":"terraform"}}'\'''\''; }'
│ config.system.build.diskoScript
│ error:
│        … while calling the 'seq' builtin
│          at /nix/store/4vsv6wrnqrynrlnclblrz1f3xq49s7v1-source/lib/modules.nix:361:18:
│           360|         options = checked options;
│           361|         config = checked (removeAttrs config [ "_module" ]);|                  ^
│           362|         _module = checked (config._module);
│
│        … while evaluating a branch condition
│          at /nix/store/4vsv6wrnqrynrlnclblrz1f3xq49s7v1-source/lib/modules.nix:297:9:
│           296|       checkUnmatched =
│           297|         if config._module.check && config._module.freeformType == null && merged.unmatchedDefns != [ ] then|         ^
│           298|           let
│
│        (stack trace truncated; use '--show-trace' to show the full, detailed trace)
│
│        error: Have you forgotten to run nixos-anywhere with `--generate-hardware-config nixos-generate-config ./hardware-configuration.nix`?
│ + out=
│
│ State: exit status 1
╵
╷
│ Error: External Program Execution Failed
│
│   with module.nixos-install.module.deploy["k3s-agent-1"].module.system-build.data.external.nix-build,
│   on .terraform/modules/nixos-install.deploy/terraform/nix-build/main.tf line 7, in data "external" "nix-build":
│    7:   program = ["${path.module}/nix-build.sh"]
│
│ The data source received an unexpected error while attempting to execute the program.
│
│ Program: .terraform/modules/nixos-install.deploy/terraform/nix-build/nix-build.sh
│ Error Message: + '[' '{"options":{}}' '!=' '{"options":{}}' ']'
│ + options=
│ + [[ {"terraform":{"hostname":"k3s-server-0","user":"terraform"}} == {} ]]
│ + [[ null != null ]]
│ ++ echo
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install#nixosConfigurations.generic.config.system.build.toplevel
│ ++ cut -d '#' -f 2
│ + rest=nixosConfigurations.generic.config.system.build.toplevel
│ + config_path=nixosConfigurations.generic
│ + config_attribute=config.system.build.toplevel
│ ++ echo
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install#nixosConfigurations.generic.config.system.build.toplevel
│ ++ cut -d '#' -f 1
│ + flake_rel=/home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install
│ ++ nix flake prefetch
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install --json
│ +
│ prefetch_result='{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ echo'{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ jq -r .storePath
│ + store_path=/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source
│ ++ jq -r .hash
│ ++ echo'{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ + nar_hash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=
│ +
│ flake_url='path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='
│ + nix_expr='(builtins.getFlake
'\'''\''path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='\'''\'').nixosConfigurations.generic.extendModules
│ { specialArgs = builtins.fromJSON
'\'''\''{"terraform":{"hostname":"k3s-server-0","user":"terraform"}}'\'''\''; }'
│ ++ nix build --no-link --json --expr '(builtins.getFlake
'\'''\''path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='\'''\'').nixosConfigurations.generic.extendModules
│ { specialArgs = builtins.fromJSON
'\'''\''{"terraform":{"hostname":"k3s-server-0","user":"terraform"}}'\'''\''; }'
│ config.system.build.toplevel
│ error:
│        … while calling the 'seq' builtin
│          at /nix/store/4vsv6wrnqrynrlnclblrz1f3xq49s7v1-source/lib/modules.nix:361:18:
│           360|         options = checked options;
│           361|         config = checked (removeAttrs config [ "_module" ]);|                  ^
│           362|         _module = checked (config._module);
│
│        … while evaluating a branch condition
│          at /nix/store/4vsv6wrnqrynrlnclblrz1f3xq49s7v1-source/lib/modules.nix:297:9:
│           296|       checkUnmatched =
│           297|         if config._module.check && config._module.freeformType == null && merged.unmatchedDefns != [ ] then|         ^
│           298|           let
│
│        (stack trace truncated; use '--show-trace' to show the full, detailed trace)
│
│        error: Have you forgotten to run nixos-anywhere with `--generate-hardware-config nixos-generate-config ./hardware-configuration.nix`?
│ + out=
│
│ State: exit status 1
╵
╷
│ Error: External Program Execution Failed
│
│   with module.nixos-install.module.deploy["k3s-server-0"].module.partitioner-build.data.external.nix-build,
│   on .terraform/modules/nixos-install.deploy/terraform/nix-build/main.tf line 7, in data "external" "nix-build":
│    7:   program = ["${path.module}/nix-build.sh"]
│
│ The data source received an unexpected error while attempting to execute the program.
│
│ Program: .terraform/modules/nixos-install.deploy/terraform/nix-build/nix-build.sh
│ Error Message: + '[' '{"options":{}}' '!=' '{"options":{}}' ']'
│ + options=
│ + [[ {"terraform":{"hostname":"k3s-server-0","user":"terraform"}} == {} ]]
│ + [[ null != null ]]
│ ++ cut -d '#' -f 2
│ ++ echo
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install#nixosConfigurations.generic.config.system.build.diskoScript
│ + rest=nixosConfigurations.generic.config.system.build.diskoScript
│ + config_path=nixosConfigurations.generic
│ + config_attribute=config.system.build.diskoScript
│ ++ echo
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install#nixosConfigurations.generic.config.system.build.diskoScript
│ ++ cut -d '#' -f 1
│ + flake_rel=/home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install
│ ++ nix flake prefetch
│ /home/kaptcha0/Documents/projects/homelab/terraform/modules/nixos-install --json
│ +
│ prefetch_result='{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ echo'{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ jq -r .storePath
│ + store_path=/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source
│ ++ echo'{"hash":"sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=","locked":{"__final":true,"dir":"terraform/modules/nixos-install","lastModified":1758269301,"rev":"72c605330f2514c42756baac4a264dae469ee3e2","revCount":36,"type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"original":{"dir":"terraform/modules/nixos-install","type":"git","url":"file:///home/kaptcha0/Documents/projects/homelab"},"storePath":"/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source"}'
│ ++ jq -r .hash
│ + nar_hash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I=
│ +
│ flake_url='path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='
│ + nix_expr='(builtins.getFlake
'\'''\''path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='\'''\'').nixosConfigurations.generic.extendModules
│ { specialArgs = builtins.fromJSON
'\'''\''{"terraform":{"hostname":"k3s-server-0","user":"terraform"}}'\'''\''; }'
│ ++ nix build --no-link --json --expr '(builtins.getFlake
'\'''\''path:/nix/store/161bcp33vwxqwkpr7bmsvkc64ar78n6y-source?narHash=sha256-79lD5mK4Vfd7ONrsX/5Z/Vl8x+B14On3f/aojs94Y7I='\'''\'').nixosConfigurations.generic.extendModules
│ { specialArgs = builtins.fromJSON
'\'''\''{"terraform":{"hostname":"k3s-server-0","user":"terraform"}}'\'''\''; }'
│ config.system.build.diskoScript
│ error:
│        … while calling the 'seq' builtin
│          at /nix/store/4vsv6wrnqrynrlnclblrz1f3xq49s7v1-source/lib/modules.nix:361:18:
│           360|         options = checked options;
│           361|         config = checked (removeAttrs config [ "_module" ]);|                  ^
│           362|         _module = checked (config._module);
│
│        … while evaluating a branch condition
│          at /nix/store/4vsv6wrnqrynrlnclblrz1f3xq49s7v1-source/lib/modules.nix:297:9:
│           296|       checkUnmatched =
│           297|         if config._module.check && config._module.freeformType == null && merged.unmatchedDefns != [ ] then|         ^
│           298|           let
│
│        (stack trace truncated; use '--show-trace' to show the full, detailed trace)
│
│        error: Have you forgotten to run nixos-anywhere with `--generate-hardware-config nixos-generate-config ./hardware-configuration.nix`?
│ + out=
│
│ State: exit status 1

Command Used

terraform apply

Target System

Other

NixOS Version

No response

Environment Information

  • Host OS:
  • Nix version:
  • Target architecture:

Configuration Files

flake.nix

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nixos-facter-modules.url = "github:numtide/nixos-facter-modules";

    disko = {
      url = "github:nix-community/disko";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    comin = {
      url = "github:nlewo/comin";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    {
      nixpkgs,
      disko,
      comin,
      ...
    }:
    {
      # Use this for all other targets
      # nixos-anywhere --flake .#generic --generate-hardware-config nixos-generate-config ./hardware-configuration.nix <hostname>
      nixosConfigurations.generic = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          disko.nixosModules.disko
          comin.nixosModules.comin
          ./configuration.nix
          ./hardware-configuration.nix
        ];
      };
    };
}


configuration.nix

{
  modulesPath,
  lib,
  pkgs,
  ...
}@args:
let
  hostname = args.terraform.hostname;
  user = args.terraform.user;
in
{
  imports = [
    (modulesPath + "/installer/scan/not-detected.nix")
    (modulesPath + "/profiles/qemu-guest.nix")
    ./disk-config.nix
  ];
  boot.loader.grub = {
    # no need to set devices, disko will add all devices that have a EF02 partition to the list already
    # devices = [ ];
    efiSupport = true;
    efiInstallAsRemovable = true;
  };
  services.openssh.enable = true;

  environment.systemPackages = map lib.lowPrio [
    pkgs.curl
    pkgs.gitMinimal
  ];

  networking.hostName = hostname;
  networking.interfaces.eth0.useDHCP = true;

  services.comin = {
    enable = true;
    remotes = [
      {
        name = "origin";
        url = "https://github.com/kaptcha0/homelab.git";
        branches.main.name = "main";
        flakeSubdirectory = "nixos";
      }
    ];
  };

  users.users.${user}.openssh.authorizedKeys.keys = [
    # change this to your ssh key
    builtins.readFile /home/kaptcha0/.ssh/id_ed25519
  ]
  ++ (args.extraPublicKeys or [ ]); # this is used for unit-testing this module and can be removed if not needed

  system.stateVersion = "24.05";
}


main.tf

variable "hosts" {
  type = map(list(string))
  description = "the list of hosts with the corresponding host names"
}


module "shared" {
  source = "../shared/"
}

module "deploy" {
  for_each = var.hosts

  source                 = "github.com/nix-community/nixos-anywhere//terraform/all-in-one"
  nixos_system_attr      = "${path.cwd}/${path.module}#nixosConfigurations.generic.config.system.build.toplevel"
  nixos_partitioner_attr = "${path.cwd}/${path.module}#nixosConfigurations.generic.config.system.build.diskoScript"
  target_host            = each.value[0]
  # when instance id changes, it will trigger a reinstall
  instance_id            = each.value[0]
  # useful if something goes wrong
  debug_logging          = true
  # build the closure on the remote machine instead of locally
  # build_on_remote        = true

  special_args = {
    terraform = {
      hostname = each.key
      user = module.shared.proxmox_config.vm_defaults.username
    }
  }
}

Additional Context

The issue seems to be because it's trying to run nix build on my local machine?

Also, the hosts variable is provided by the parent terraform module. It has the shape

{
  host1 = ["ip1", "ip2", ...]
   ...
}

I'm using this because I'm using terraform to provision debian hosts on Proxmox. I want to use nixos-anywhere to move them over to run nixos.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions