diff options
author | Erik Arvstedt <erik.arvstedt@gmail.com> | 2020-12-15 20:25:00 +0100 |
---|---|---|
committer | Erik Arvstedt <erik.arvstedt@gmail.com> | 2021-01-15 12:49:42 +0100 |
commit | 9a283a038d3c028f8b067c6b2e56f2e38bd93192 (patch) | |
tree | 9e6ff2d99e921093f19cfa684f2d7f7f6d16c743 /nixos/modules/virtualisation/nixos-containers.nix | |
parent | 77c4fc2e89eca27e7ba559ed5b0f053a5ef122ce (diff) | |
download | nixpkgs-9a283a038d3c028f8b067c6b2e56f2e38bd93192.tar nixpkgs-9a283a038d3c028f8b067c6b2e56f2e38bd93192.tar.gz nixpkgs-9a283a038d3c028f8b067c6b2e56f2e38bd93192.tar.bz2 nixpkgs-9a283a038d3c028f8b067c6b2e56f2e38bd93192.tar.lz nixpkgs-9a283a038d3c028f8b067c6b2e56f2e38bd93192.tar.xz nixpkgs-9a283a038d3c028f8b067c6b2e56f2e38bd93192.tar.zst nixpkgs-9a283a038d3c028f8b067c6b2e56f2e38bd93192.zip |
nixos-container: fix `nixpkgs` container options being ignored
Since the introduction of option `containers.<name>.pkgs`, the `nixpkgs.*` options (including `nixpkgs.pkgs`, `nixpkgs.config`, ...) were always ignored in container configs, which broke existing containers. This was due to `containers.<name>.pkgs` having two separate effects: (1) It sets the source for the modules that are used to evaluate the container. (2) It sets the `pkgs` arg (`_module.args.pkgs`) that is used inside the container modules. This happens even when the default value of `containers.<name>.pkgs` is unchanged, in which case the container `pkgs` arg is set to the pkgs of the host system. Previously, the `pkgs` arg was determined by the `containers.<name>.config.nixpkgs.*` options. This commit reverts the breaking change (2) while adding a backwards-compatible way to achieve (1). It removes option `pkgs` and adds option `nixpkgs` which implements (1). Existing users of `pkgs` are informed by an error message to use option `nixpkgs` or to achieve only (2) by setting option `containers.<name>.config.nixpkgs.pkgs`.
Diffstat (limited to 'nixos/modules/virtualisation/nixos-containers.nix')
-rw-r--r-- | nixos/modules/virtualisation/nixos-containers.nix | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/nixos/modules/virtualisation/nixos-containers.nix b/nixos/modules/virtualisation/nixos-containers.nix index 5949c54052c..c721858225c 100644 --- a/nixos/modules/virtualisation/nixos-containers.nix +++ b/nixos/modules/virtualisation/nixos-containers.nix @@ -463,7 +463,6 @@ in { config, options, name, ... }: { options = { - config = mkOption { description = '' A specification of the desired configuration of this @@ -471,9 +470,8 @@ in ''; type = lib.mkOptionType { name = "Toplevel NixOS config"; - merge = loc: defs: (import (config.pkgs.path + "/nixos/lib/eval-config.nix") { + merge = loc: defs: (import "${toString config.nixpkgs}/nixos/lib/eval-config.nix" { inherit system; - pkgs = config.pkgs; modules = let extraConfig = { @@ -522,12 +520,18 @@ in ''; }; - pkgs = mkOption { - type = types.attrs; - default = pkgs; - defaultText = "pkgs"; + nixpkgs = mkOption { + type = types.path; + default = pkgs.path; + defaultText = "pkgs.path"; description = '' - Customise which nixpkgs to use for this container. + A path to the nixpkgs that provide the modules, pkgs and lib for evaluating the container. + + To only change the <literal>pkgs</literal> argument used inside the container modules, + set the <literal>nixpkgs.*</literal> options in the container <option>config</option>. + Setting <literal>config.nixpkgs.pkgs = pkgs</literal> speeds up the container evaluation + by reusing the system pkgs, but the <literal>nixpkgs.config</literal> option in the + container config is ignored in this case. ''; }; @@ -668,14 +672,31 @@ in ''; }; + # Removed option. See `checkAssertion` below for the accompanying error message. + pkgs = mkOption { visible = false; }; } // networkOptions; - config = mkMerge - [ - (mkIf options.config.isDefined { - path = config.config.system.build.toplevel; - }) - ]; + config = let + # Throw an error when removed option `pkgs` is used. + # Because this is a submodule we cannot use `mkRemovedOptionModule` or option `assertions`. + optionPath = "containers.${name}.pkgs"; + files = showFiles options.pkgs.files; + checkAssertion = if options.pkgs.isDefined then throw '' + The option definition `${optionPath}' in ${files} no longer has any effect; please remove it. + + Alternatively, you can use the following options: + - containers.${name}.nixpkgs + This sets the nixpkgs (and thereby the modules, pkgs and lib) that + are used for evaluating the container. + + - containers.${name}.config.nixpkgs.pkgs + This only sets the `pkgs` argument used inside the container modules. + '' + else null; + in { + path = builtins.seq checkAssertion + mkIf options.config.isDefined config.config.system.build.toplevel; + }; })); default = {}; |