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: fix nixpkgs
container options being ignored
#106767
Conversation
5d60630
to
ed3cb44
Compare
Ok, now I understand the need for a
Seems like the way to go. I'll try to review this in the next couple of days, for the moment I would suggest adding a subtest for overlays in containers to avoid more regressions in the future. |
I've updated the test and added a helpful error message for current users of To test the error message, run nix-instantiate --eval - <<'EOF'
(import /path/to/nixpkgs/nixos {
configuration = { pkgs, ... }: {
containers.test = {
inherit pkgs;
config = {};
};
};
}).vm.outPath
EOF |
@adisbladis, why did you add option |
b13bcb7
to
c3b91ea
Compare
From the test they added, it looks like the use case was modifying the package set. This can indeed be done using However, I fear this option (even if it add very little complexity to Nixpkgs) will make things more confusing for new users. Maybe we should rename it to something more descriptive. |
I've also considered renaming the option. Do you think |
Uhm, I'm not entirely sure because it will also affect other things besides the evaluation of modules. |
Can you (very quickly) elaborate on what else it does affect? I don't see any other effects besides choosing the NixOS modules used for container evaluation. What do you think about calling it |
Besides modules and packages, I had
Good idea, it think it's more appropriate since the option is a path, |
I must confess, I use NixOS recreationally since 17.09, and I'm lost as to what there difference between I'm certainly eager to see this (any) PR merged to address the issue preventing overlays from working inside containers so I can upgrade my last server. But I'm happy to wait for the confusion to be sorted. |
The difference is a bit subtle and may have been unintended when
Yes, but the second option is not really a replacement: in the first case you would get a system with 19.09 packages but 20.09 NixOS modules and standard library ( |
- Fix name - Remove unneeded leftovers that were copied from containers-hosts.nix - Remove redundant 'start_all()'
The values of these args are identical to the default values defined in `eval-config.nix`. Note especially that `lib` is not reevaluated.
Set the default value directly instead of using a `null` proxy value.
c3b91ea
to
8c265f4
Compare
@rnhmjoj, yeah, sorry, with I've now removed option |
]; | ||
config = let | ||
# Throw an error when removed option `pkgs` is used. | ||
# Because this is a submodule we cannot use `mkRemovedOptionModule` or option `assertions`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just hours ago Infinisil merged PR #97023 that should remove this limitation.
It had to be reverted because an issue came up but I'd keep it in mind.
Is there anything blocking progress on this that I could assist with? |
I have been busy, I'll try to finish my review in the next couple of days. |
@rnhmjoj, I don't think it's worth to wait for Infinisil's fixed PR.
instead of
The above is the error msg output by the current code. |
Agreed, I was mostly making a note rather than a request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've looked at this more carefully: the option and assetion are working as intended and diff looks good to me. I don't have any more suggestions but I'm not an expert in this part of NixOS (containers + module system) so I'm not confident with merging the PR right away.
8c265f4
to
c139941
Compare
@rnhmjoj, I've just done some a minor editing to clarify the description of commit |
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`.
c139941
to
9a283a0
Compare
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
Is it possible backport this fix to 20.09, or shall I just wait until 21.05 to update my servers? |
You can open a backport pull request if you want. |
Since the introduction of option
containers.<name>.pkgs
, thenixpkgs.*
options (includingnixpkgs.pkgs
,nixpkgs.config
, ...) were always ignored in container configs, which broke existing containers.This was due to
containers.<name>.pkgs
having two separate effects: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 whichcase the container
pkgs
arg is set to the pkgs of the host system.Previously, the
pkgs
arg was determined by thecontainers.<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 optionnixpkgs
which implements (1.).Existing users of
pkgs
are informed by an error message to use optionnixpkgs
for (1.) or to achieve only (2.) by setting optioncontainers.<name>.config.nixpkgs.pkgs
.The first three commits
tests/containers-custom-pkgs: improve test
nixos-container: simplify 'pkgs' option type
nixos-containers: remove redundant eval-config args
are refactorings without any functional changes.
Reproduce
The following config was broken before and is fixed by this PR:
Fixes #88621.
cc @adisbladis
This PR is an improved version of #98655