Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos-container: re-enable nixpkgs option #98655

Closed
wants to merge 2 commits into from

Conversation

erikarvstedt
Copy link
Member

@erikarvstedt erikarvstedt commented Sep 24, 2020

This PR is superseded by #106767.

Since the introduction (#85570) of option containers.<name>.pkgs, the option nixpkgs (including nixpkgs.pkgs, nixpkgs.config, ...) was always ignored in container configs.

This option is now honored again if pkgs == null.

The default behavior (including its performance benefits by re-using pkgs) is unchanged.
Edit: The fixup commit reverts to the default behavior of 20.03/20.09 to fix existing container configs broken by #85570.

Also, remove the redundant definition of baseModules, which is identical to the one in eval-config.nix.

Reproduce

The following config was broken before and is fixed by this PR:

nix-build --no-out-link - <<'EOF'
let
  configuration = {
    containers.mycontainer = {
      pkgs = null;
      config = { pkgs, ... }: {
        nixpkgs.overlays = [ (self: super: {
          myval = "hello";
        }) ];
        networking.hostName = pkgs.myval;
      };
    };
  };
in
(import <nixpkgs/nixos> { inherit configuration; }).vm
EOF

# error: attribute 'myval' missing, at (string):9:31

Fixes #88621.
cc @adisbladis

Since the introduction of option `containers.<name>.pkgs`, the option
`nixpkgs` (including `nixpkgs.pkgs`, `nixpkgs.config`, ...) was always
ignored in container configs.

This option is now honored again if `pkgs == null`.

The default behavior (including its performance benefits by re-using
pkgs) is unchanged.

Also, remove the redundant definition of `baseModules`, which is
identical to the one in `eval-config.nix`.
evalConfigArgs = optionalAttrs (config.pkgs != null) {
pkgs = confPkgs;
inherit (confPkgs) lib;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably write some code to warn users that when defining your own pkgs for a container, no overlays will apply.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the extra description of pkgs is enough.
Maybe we should revert to the old behaviour, to avoid breaking existing configs. The only downside is the decreased performance.
Edit: I think reverting is the best way to go . All container configs using nixpkgs are broken since #85570.

@@ -528,10 +529,12 @@ in

pkgs = mkOption {
type = types.nullOr types.attrs;
default = null;
example = literalExample "pkgs";
default = pkgs;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you changed the default here? Isn't null the better default as this means that by default, overlays in existing configs from 20.03 still apply?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To quote myself:

The default behavior (including its performance benefits by re-using pkgs) is unchanged.

You may have misread this change, for the reason that the current version of nixos-containers.nix is a bit flawed:
The values null and pkgs for containers.pkgs are equivalent; the extra allowed value null is completely redundant. It is with this PR that null unlocks special behavior (namely container-configured pkgs).

@erikarvstedt erikarvstedt force-pushed the fix-container-pkgs branch 2 times, most recently from ef45593 to 199140b Compare September 25, 2020 14:09
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/20-09-unable-to-use-overlay-in-containers/10442/2

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/20-09-unable-to-use-overlay-in-containers/10442/3

@rnhmjoj
Copy link
Contributor

rnhmjoj commented Dec 12, 2020

I'm not too familiar with containers: I don't understand the original change in #85570, if you could already use containers.<name>.config.nixpkgs.pkgs, what's the point of having containers.<name>.pkgs?

@erikarvstedt
Copy link
Member Author

@rnhmjoj, thanks for looking into this.
I've created an improved and simpler version of this PR that should exactly address your question.

This PR is now superseded by #106767.

@erikarvstedt erikarvstedt marked this pull request as draft December 12, 2020 17:39
@erikarvstedt erikarvstedt force-pushed the fix-container-pkgs branch 2 times, most recently from aa98d64 to 64ec840 Compare December 14, 2020 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nixpkgs.overlays not working inside NixOS containers
4 participants