nixos-containers: Added flake option (#413463)

jade f43a0881 2defa371

Changed files
+33 -5
nixos
modules
virtualisation
+33 -5
nixos/modules/virtualisation/nixos-containers.nix
···
cp --remove-destination /etc/resolv.conf "$root/etc/resolv.conf"
+
if [ -n "$FLAKE" ] && [ ! -e "/nix/var/nix/profiles/per-container/$INSTANCE/system" ]; then
+
# we create the etc/nixos-container config file, then if we utilize the update function, we can then build all the necessary system files for the container
+
${lib.getExe nixos-container} update "$INSTANCE"
+
fi
+
declare -a extraFlags
if [ "$PRIVATE_NETWORK" = 1 ]; then
···
'';
};
+
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.<name>.path`.
+
'';
+
};
+
# Removed option. See `checkAssertion` below for the accompanying error message.
pkgs = mkOption { visible = false; };
} // networkOptions;
···
- 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}")
+
];
};
}
)
···
unitConfig.RequiresMountsFor = "${stateDirectory}/%i";
-
path = [ pkgs.iproute2 ];
+
path = [
+
pkgs.iproute2
+
config.nix.package
+
];
environment = {
root = "${stateDirectory}/%i";
···
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) ''