Skip to content

Commit 9d3cc92

Browse files
boukastro
authored andcommitted
Allow overriding nixpkgs for VM
This allows settings pkgs = null in the microvm config so it instantiates a new package set. This way you can configure nixpkgs inside the NixOS configuration. Also add a 'nixpkgs' config option to allow overriding the nixpkgs path.
1 parent ebaa5a3 commit 9d3cc92

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

nixos-modules/host/default.nix

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,44 @@ in
2828
default = null;
2929
type = nullOr (lib.mkOptionType {
3030
name = "Toplevel NixOS config";
31-
merge = loc: defs: (import "${toString config.pkgs.path}/nixos/lib/eval-config.nix" {
31+
merge = loc: defs: (import "${config.nixpkgs}/nixos/lib/eval-config.nix" {
3232
modules =
3333
let
34-
extraConfig = {
34+
extraConfig = ({ lib, ... }: {
3535
_file = "module at ${__curPos.file}:${toString __curPos.line}";
3636
config = {
3737
networking.hostName = lib.mkDefault name;
3838
};
39-
};
39+
});
4040
in [
4141
extraConfig
4242
../microvm
4343
] ++ (map (x: x.value) defs);
4444
prefix = [ "microvm" "vms" name "config" ];
4545
inherit (config) specialArgs pkgs;
46-
inherit (config.pkgs) system;
46+
system = if config.pkgs != null then config.pkgs.system else pkgs.system;
4747
});
4848
});
4949
};
5050

51+
nixpkgs = mkOption {
52+
type = types.path;
53+
default = if config.pkgs != null then config.pkgs.path else pkgs.path;
54+
defaultText = literalExpression "pkgs.path";
55+
description = lib.mdDoc ''
56+
This option is only respected when `config` is specified.
57+
The nixpkgs path to use for the MicroVM. Defaults to the host's nixpkgs.
58+
'';
59+
};
60+
5161
pkgs = mkOption {
52-
type = types.unspecified;
62+
type = types.nullOr types.unspecified;
5363
default = pkgs;
5464
defaultText = literalExpression "pkgs";
5565
description = lib.mdDoc ''
5666
This option is only respected when `config` is specified.
5767
The package set to use for the MicroVM. Must be a nixpkgs package set with the microvm overlay. Determines the system of the MicroVM.
68+
If set to null, a new package set will be instantiated.
5869
'';
5970
};
6071

0 commit comments

Comments
 (0)