git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #85638 from basvandijk/virtualisation.vmName

nixos/modules/system/activation/top-level.nix: allow overriding system.name

commit7d061cefb7ce031895b591189b505e0d40f2e814 authorBas van Dijk <v.dijk.bas@gmail.com> dateMon 20 Jul 2020, 14:21 (6 years ago) parent1c07a10d06de76
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