git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/modules/system/activation/top-level.nix: allow overriding system.name

The toplevel derivations of systems that have `networking.hostName` set to `""` (because they want their hostname to be set by DHCP) used to be all named `nixos-system-unnamed-${config.system.nixos.label}`. This makes them hard to distinguish. A similar problem existed in NixOS tests where `vmName` is used in the `testScript` to refer to the VM. It defaulted to the `networking.hostName` which when set to `""` won't allow you to refer to the machine from the `testScript`. This commit makes the `system.name` configurable. It still defaults to: ``` if config.networking.hostName == "" then "unnamed" else config.networking.hostName; ``` but in case `networking.hostName` needs to be to `""` the `system.name` can be set to a distinguishable name.

commitd06de760f8f4a3c304addb33c372d706cc6c6c9e authorBas van Dijk <v.dijk.bas@gmail.com> dateMon 20 Apr 2020, 23:53 (7 years ago) parent27296cc
2 files changed+19−11
nixos/modules/system/activation/top-level.nix+16−3 nixos/modules/virtualisation/qemu-vm.nix+3−8
nixos/modules/system/activation/top-level.nix+16−3
@@ -92,9 +92,7 @@ let
9292 # `switch-to-configuration' that activates the configuration and
9393 # makes it bootable.
9494 baseSystem = pkgs.stdenvNoCC.mkDerivation {
95− name = let hn = config.networking.hostName;
96− nn = if (hn != "") then hn else "unnamed";
97− in "nixos-system-${nn}-${config.system.nixos.label}";
95+ name = "nixos-system-${config.system.name}-${config.system.nixos.label}";
9896 preferLocalBuild = true;
9997 allowSubstitutes = false;
10098 buildCommand = systemBuilder;
@@ -265,6 +263,21 @@ in
265263 '';
266264 };
267265
266+ system.name = mkOption {
267+ type = types.str;
268+ default =
269+ if config.networking.hostName == ""
270+ then "unnamed"
271+ else config.networking.hostName;
272+ defaultText = '''networking.hostName' if non empty else "unnamed"'';
273+ description = ''
274+ The name of the system used in the <option>system.build.toplevel</option> derivation.
275+ </para><para>
276+ That derivation has the following name:
277+ <literal>"nixos-system-''${config.system.name}-''${config.system.nixos.label}"</literal>
278+ '';
279+ };
280+
268281 };
269282
270283
nixos/modules/virtualisation/qemu-vm.nix+3−8
@@ -16,11 +16,6 @@ let
1616
1717 qemu = config.system.build.qemu or pkgs.qemu_test;
1818
19− vmName =
20− if config.networking.hostName == ""
21− then "noname"
22− else config.networking.hostName;
23−
2419 cfg = config.virtualisation;
2520
2621 consoles = lib.concatMapStringsSep " " (c: "console=${c}") cfg.qemu.consoles;
@@ -156,7 +151,7 @@ let
156151
157152 # Start QEMU.
158153 exec ${qemuBinary qemu} \
159− -name ${vmName} \
154+ -name ${config.system.name} \
160155 -m ${toString config.virtualisation.memorySize} \
161156 -smp ${toString config.virtualisation.cores} \
162157 -device virtio-rng-pci \
@@ -294,7 +289,7 @@ in
294289
295290 virtualisation.diskImage =
296291 mkOption {
297− default = "./${vmName}.qcow2";
292+ default = "./${config.system.name}.qcow2";
298293 description =
299294 ''
300295 Path to the disk image containing the root filesystem.
@@ -712,7 +707,7 @@ in
712707 ''
713708 mkdir -p $out/bin
714709 ln -s ${config.system.build.toplevel} $out/system
715− ln -s ${pkgs.writeScript "run-nixos-vm" startVM} $out/bin/run-${vmName}-vm
710+ ln -s ${pkgs.writeScript "run-nixos-vm" startVM} $out/bin/run-${config.system.name}-vm
716711 '';
717712
718713 # When building a regular system configuration, override whatever