diff --git a/flake.nix b/flake.nix
index 1e20fcd40ebe5..bb76fae486d52 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 c11872f1441ab..6beb4cd3a7df7 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 2dd27649c52c2..e87fec9a2e562 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
@@ -132,6 +132,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 595785e732a4b..9d13697a41f1c 100644
--- a/nixos/doc/manual/release-notes/rl-2205.section.md
+++ b/nixos/doc/manual/release-notes/rl-2205.section.md
@@ -57,4 +57,14 @@ 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.
diff --git a/nixos/lib/eval-config.nix b/nixos/lib/eval-config.nix
index 62d09b8173bda..00e58e24e926c 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 cb2dd530de151..5fa8220fa0eab 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -1179,6 +1179,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 501998fa399e2..42e6dd689f93d 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 0000000000000..3baa84cce0184
--- /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;
+ };
+
+ };
+}