@@ -463,21 +463,15 @@ in
463463 { config, options, name, ... }:
464464 {
465465 options = {
466−
467466 config = mkOption {
468467 description = ''
469468 A specification of the desired configuration of this
470469 container, as a NixOS module.
471470 '';
472− type = let
473− confPkgs = if config.pkgs == null then pkgs else config.pkgs;
474− in lib.mkOptionType {
471+ type = lib.mkOptionType {
475472 name = "Toplevel NixOS config";
476− merge = loc: defs: (import (confPkgs.path + "/nixos/lib/eval-config.nix") {
473+ merge = loc: defs: (import "${toString config.nixpkgs}/nixos/lib/eval-config.nix" {
477474 inherit system;
478− pkgs = confPkgs;
479− baseModules = import (confPkgs.path + "/nixos/modules/module-list.nix");
480− inherit (confPkgs) lib;
481475 modules =
482476 let
483477 extraConfig = {
@@ -526,12 +520,18 @@ in
526520 '';
527521 };
528522
529− pkgs = mkOption {
530− type = types.nullOr types.attrs;
531− default = null;
532− example = literalExample "pkgs";
523+ nixpkgs = mkOption {
524+ type = types.path;
525+ default = pkgs.path;
526+ defaultText = "pkgs.path";
533527 description = ''
534− Customise which nixpkgs to use for this container.
528+ A path to the nixpkgs that provide the modules, pkgs and lib for evaluating the container.
529+
530+ To only change the <literal>pkgs</literal> argument used inside the container modules,
531+ set the <literal>nixpkgs.*</literal> options in the container <option>config</option>.
532+ Setting <literal>config.nixpkgs.pkgs = pkgs</literal> speeds up the container evaluation
533+ by reusing the system pkgs, but the <literal>nixpkgs.config</literal> option in the
534+ container config is ignored in this case.
535535 '';
536536 };
537537
@@ -672,14 +672,31 @@ in
672672 '';
673673 };
674674
675+ # Removed option. See `checkAssertion` below for the accompanying error message.
676+ pkgs = mkOption { visible = false; };
675677 } // networkOptions;
676678
677− config = mkMerge
678− [
679− (mkIf options.config.isDefined {
680− path = config.config.system.build.toplevel;
681− })
682− ];
679+ config = let
680+ # Throw an error when removed option `pkgs` is used.
681+ # Because this is a submodule we cannot use `mkRemovedOptionModule` or option `assertions`.
682+ optionPath = "containers.${name}.pkgs";
683+ files = showFiles options.pkgs.files;
684+ checkAssertion = if options.pkgs.isDefined then throw ''
685+ The option definition `${optionPath}' in ${files} no longer has any effect; please remove it.
686+
687+ Alternatively, you can use the following options:
688+ - containers.${name}.nixpkgs
689+ This sets the nixpkgs (and thereby the modules, pkgs and lib) that
690+ are used for evaluating the container.
691+
692+ - containers.${name}.config.nixpkgs.pkgs
693+ This only sets the `pkgs` argument used inside the container modules.
694+ ''
695+ else null;
696+ in {
697+ path = builtins.seq checkAssertion
698+ mkIf options.config.isDefined config.config.system.build.toplevel;
699+ };
683700 }));
684701
685702 default = {};