diff --git a/flake.nix b/flake.nix
index 1e20fcd40eb..bb76fae486d 100644
--- a/flake.nix
+++ b/flake.nix
@@ -22,24 +22,6 @@
import ./nixos/lib/eval-config.nix (args // {
modules =
let
- vmConfig = (import ./nixos/lib/eval-config.nix
- (args // {
- modules = modules ++ [ ./nixos/modules/virtualisation/qemu-vm.nix ];
- })).config;
-
- vmWithBootLoaderConfig = (import ./nixos/lib/eval-config.nix
- (args // {
- modules = modules ++ [
- ./nixos/modules/virtualisation/qemu-vm.nix
- { virtualisation.useBootLoader = true; }
- ({ config, ... }: {
- virtualisation.useEFIBoot =
- config.boot.loader.systemd-boot.enable ||
- config.boot.loader.efi.canTouchEfiVariables;
- })
- ];
- })).config;
-
moduleDeclarationFile =
let
# Even though `modules` is a mandatory argument for `nixosSystem`, it doesn't
@@ -63,11 +45,6 @@
system.nixos.versionSuffix =
".${final.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}.${self.shortRev or "dirty"}";
system.nixos.revision = final.mkIf (self ? rev) self.rev;
-
- system.build = {
- vm = vmConfig.system.build.vm;
- vmWithBootLoader = vmWithBootLoaderConfig.system.build.vm;
- };
}
];
});
diff --git a/nixos/default.nix b/nixos/default.nix
index c11872f1441..6beb4cd3a7d 100644
--- a/nixos/default.nix
+++ b/nixos/default.nix
@@ -9,27 +9,6 @@ let
modules = [ configuration ];
};
- # This is for `nixos-rebuild build-vm'.
- vmConfig = (import ./lib/eval-config.nix {
- inherit system;
- modules = [ configuration ./modules/virtualisation/qemu-vm.nix ];
- }).config;
-
- # This is for `nixos-rebuild build-vm-with-bootloader'.
- vmWithBootLoaderConfig = (import ./lib/eval-config.nix {
- inherit system;
- modules =
- [ configuration
- ./modules/virtualisation/qemu-vm.nix
- { virtualisation.useBootLoader = true; }
- ({ config, ... }: {
- virtualisation.useEFIBoot =
- config.boot.loader.systemd-boot.enable ||
- config.boot.loader.efi.canTouchEfiVariables;
- })
- ];
- }).config;
-
in
{
@@ -37,7 +16,5 @@ in
system = eval.config.system.build.toplevel;
- vm = vmConfig.system.build.vm;
-
- vmWithBootLoader = vmWithBootLoaderConfig.system.build.vm;
+ inherit (eval.config.system.build) vm vmWithBootLoader;
}
diff --git a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
index e77ca0a8521..02e3bc19412 100644
--- a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
+++ b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
@@ -341,6 +341,28 @@
socket /run/redis-${serverName}/redis.sock.
+
+
+ The option
+ virtualisation.vmVariant
+ was added to allow users to make changes to the
+ nixos-rebuild build-vm configuration that
+ do not apply to their normal system.
+
+
+ The config.system.build.vm attribute now
+ always exists and defaults to the value from
+ vmVariant. Configurations that import the
+ virtualisation/qemu-vm.nix module
+ themselves will override this value, such that
+ vmVariant is not used.
+
+
+ Similarly
+ virtualisation.vmVariantWithBootloader
+ was added.
+
+
The
diff --git a/nixos/doc/manual/release-notes/rl-2205.section.md b/nixos/doc/manual/release-notes/rl-2205.section.md
index 5957f82bce9..d42ba989f9d 100644
--- a/nixos/doc/manual/release-notes/rl-2205.section.md
+++ b/nixos/doc/manual/release-notes/rl-2205.section.md
@@ -118,6 +118,16 @@ In addition to numerous new and upgraded packages, this release has the followin
to the members of the Unix group `redis-${serverName}`
through the Unix socket `/run/redis-${serverName}/redis.sock`.
+- The option [virtualisation.vmVariant](#opt-virtualisation.vmVariant) was added
+ to allow users to make changes to the `nixos-rebuild build-vm` configuration
+ that do not apply to their normal system.
+
+ The `config.system.build.vm` attribute now always exists and defaults to the
+ value from `vmVariant`. Configurations that import the `virtualisation/qemu-vm.nix`
+ module themselves will override this value, such that `vmVariant` is not used.
+
+ Similarly [virtualisation.vmVariantWithBootloader](#opt-virtualisation.vmVariantWithBootLoader) was added.
+
- The `writers.writePyPy2`/`writers.writePyPy3` and corresponding `writers.writePyPy2Bin`/`writers.writePyPy3Bin` convenience functions to create executable Python 2/3 scripts using the PyPy interpreter were added.
- The `influxdb2` package was split into `influxdb2-server` and
diff --git a/nixos/lib/eval-config.nix b/nixos/lib/eval-config.nix
index 62d09b8173b..00e58e24e92 100644
--- a/nixos/lib/eval-config.nix
+++ b/nixos/lib/eval-config.nix
@@ -88,13 +88,8 @@ let
nixosWithUserModules = noUserModules.extendModules { modules = allUserModules; };
-in withWarnings {
-
- # Merge the option definitions in all modules, forming the full
- # system configuration.
- inherit (nixosWithUserModules) config options _module type;
-
+in
+withWarnings nixosWithUserModules // {
inherit extraArgs;
-
inherit (nixosWithUserModules._module.args) pkgs;
}
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index db3646b2849..43853555585 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -1187,6 +1187,7 @@
./tasks/powertop.nix
./testing/service-runner.nix
./virtualisation/anbox.nix
+ ./virtualisation/build-vm.nix
./virtualisation/container-config.nix
./virtualisation/containerd.nix
./virtualisation/containers.nix
diff --git a/nixos/modules/system/activation/top-level.nix b/nixos/modules/system/activation/top-level.nix
index 2efe0f05e0c..1c588ff9691 100644
--- a/nixos/modules/system/activation/top-level.nix
+++ b/nixos/modules/system/activation/top-level.nix
@@ -148,7 +148,7 @@ in
system.build = mkOption {
internal = true;
default = {};
- type = types.attrs;
+ type = types.lazyAttrsOf types.unspecified;
description = ''
Attribute set of derivations used to setup the system.
'';
diff --git a/nixos/modules/virtualisation/build-vm.nix b/nixos/modules/virtualisation/build-vm.nix
new file mode 100644
index 00000000000..3baa84cce01
--- /dev/null
+++ b/nixos/modules/virtualisation/build-vm.nix
@@ -0,0 +1,55 @@
+{ config, extendModules, lib, ... }:
+let
+
+ inherit (lib)
+ mkOption
+ ;
+
+ vmVariant = extendModules {
+ modules = [ ./qemu-vm.nix ];
+ };
+
+ vmVariantWithBootLoader = vmVariant.extendModules {
+ modules = [
+ ({ config, ... }: {
+ _file = "nixos/default.nix##vmWithBootLoader";
+ virtualisation.useBootLoader = true;
+ virtualisation.useEFIBoot =
+ config.boot.loader.systemd-boot.enable ||
+ config.boot.loader.efi.canTouchEfiVariables;
+ })
+ ];
+ };
+in
+{
+ options = {
+
+ virtualisation.vmVariant = mkOption {
+ description = ''
+ Machine configuration to be added for the vm script produced by nixos-rebuild build-vm.
+ '';
+ inherit (vmVariant) type;
+ default = {};
+ visible = "shallow";
+ };
+
+ virtualisation.vmVariantWithBootLoader = mkOption {
+ description = ''
+ Machine configuration to be added for the vm script produced by nixos-rebuild build-vm-with-bootloader.
+ '';
+ inherit (vmVariantWithBootLoader) type;
+ default = {};
+ visible = "shallow";
+ };
+
+ };
+
+ config = {
+
+ system.build = {
+ vm = lib.mkDefault config.virtualisation.vmVariant.system.build.vm;
+ vmWithBootLoader = lib.mkDefault config.virtualisation.vmVariantWithBootLoader.system.build.vm;
+ };
+
+ };
+}