diff --git a/nixos/modules/virtualisation/nixos-containers.nix b/nixos/modules/virtualisation/nixos-containers.nix index e5a0d37d6a9c..e7f3c050bd49 100644 --- a/nixos/modules/virtualisation/nixos-containers.nix +++ b/nixos/modules/virtualisation/nixos-containers.nix @@ -844,6 +844,16 @@ in ''; }; + flake = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + example = "github:NixOS/nixpkgs/master"; + description = '' + The Flake URI of the NixOS configuration to use for the container. + Replaces the option {option}`containers..path`. + ''; + }; + # Removed option. See `checkAssertion` below for the accompanying error message. pkgs = mkOption { visible = false; }; } // networkOptions; @@ -867,13 +877,18 @@ in - containers.${name}.config.nixpkgs.pkgs This only sets the `pkgs` argument used inside the container modules. '' + else if options.config.isDefined && (options.flake.value != null) then + throw '' + The options 'containers.${name}.path' and 'containers.${name}.flake' cannot both be set. + '' else null; in { - path = - builtins.seq checkAssertion mkIf options.config.isDefined - config.config.system.build.toplevel; + path = builtins.seq checkAssertion mkMerge [ + (mkIf options.config.isDefined config.config.system.build.toplevel) + (mkIf (config.flake != null) "/nix/var/nix/profiles/per-container/${name}") + ]; }; } ) @@ -1044,7 +1059,12 @@ in name: cfg: nameValuePair "${configurationDirectoryName}/${name}.conf" { text = '' - SYSTEM_PATH=${cfg.path} + ${optionalString (cfg.flake == null) '' + SYSTEM_PATH=${cfg.path} + ''} + ${optionalString (cfg.flake != null) '' + FLAKE=${cfg.flake} + ''} ${optionalString cfg.privateNetwork '' PRIVATE_NETWORK=1 ${optionalString (cfg.hostBridge != null) ''