-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
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: Add nixpkgs.pkgs option #33700
Conversation
@nbp do we have a way to check if nixpkgs.config, nixpkgs.system or nixpkgs.overlays have been set by the user? |
Note that NixOps should probably not always set |
Another approach to preventing repeated evaluation of Nixpkgs: NixOS/nix@0395b9b |
That's a very good idea, but does not address the general usefulness of being able to inject That's the point of PR #32422 in which @nbp suggested |
Is there anything I can do to improve this more powerful option for setting |
nixos/modules/misc/nixpkgs.nix
Outdated
default = null; | ||
defaultText = "Situation-dependent; plain NixOS sets this to <code>null</code>."; | ||
type = types.nullOr pkgsType; | ||
example = literalExample ''import pkgs.path {}''; |
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.
That's sounds like a nice example of an infinite loop, if someone write that within a module.
Maybe use <nixpkgs>
instead of pkgs.path
.
nixos/modules/misc/nixpkgs.nix
Outdated
|
||
_pkgs = | ||
if cfg.pkgs == null | ||
then import ../../.. { inherit (cfg) config overlays system; } |
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.
nit: This should be part of the config section, as:
{
config = {
_module.args.pkgs = cfg.pkgs;
nixpkgs.pkgs = mkDefault (import ../../.. { inherit (cfg) config overlays system; });
};
}
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 ditched the null
and put the default right in the option definition. That seems to just work.
Yes you can do:
While I understand what you are looking for, remember that this is a valid use-case to use |
a5e7e40
to
7eab3f8
Compare
I wasn't able to determine whether options were being set. The module system would have to preserve the priority for that to work, which it doesn't expose. That is, it's not in the output of |
Ok, I've implemented everything as suggested. Detecting the priority inversion is outside the scope of this feature, because it requires changes to the module system. |
nixos/modules/misc/nixpkgs.nix
Outdated
_pkgs = import ../../.. config.nixpkgs; | ||
pkgsType = mkOptionType { | ||
name = "nixpkgs"; | ||
description = "An evaluation of NixPkgs; the top level attribute set of packages"; |
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.
It's Nixpkgs
, not NixPkgs
.
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.
So Nixpkgs is the odd one out. Fixed.
7eab3f8
to
798a373
Compare
nixos/modules/misc/nixpkgs.nix
Outdated
<code>config.nixpkgs.overlays</code>, etc. | ||
'' | ||
; | ||
default = import ../../.. { inherit (cfg) config overlays system; }; |
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.
How does it render in the documentation? Isn't the defaultText
supposed to provide a literal example of the default
value?
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.
That didn't look so good. Can't just move documentation around.
Now I've removed the docbook tags and added literalExample
to remove the quotes. It's a code literal now, which is almost good. I can't put code like import ../../../ { whatever}
without an explanation there. That'd be too vague.
So not perfect, but at least the formatting is a lot less wrong now.
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.
Maybe add the rest as part of the documentation attribute, and/or use <nixos>
instead of ../../..
even if this is not exactly true.
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 introduced a fake variable nixos in the docs to indicate the relative path. Not bad after all. Thanks for the input.
798a373
to
d51a53b
Compare
This lets the user set pkgs directly, so that it can be injected externally and be reused among evaluations of NixOS.
d51a53b
to
f2a45a4
Compare
I can't understand how this interacts with `nixos/lib/eval-config.nix`.
Does it still need the `pkgs` and `pkgsModule`?
|
@oxij, this change does not interact much with Your question sounds like it is related to PR #32422. That PR deals with calling NixOS from an evaluation of Nixpkgs. It is loosely related to this PR. The one does not require the other, but applying this PR first is more convenient. |
@oxij coming to think of it, it might be better if |
This lets the user set pkgs directly, so that it can be injected
externally and be reused among evaluations of NixOS.
Motivation for this change
This provides an easy and documented way to set
pkgs
for applications external to NixOS and it provides easy access to some extra flexibility for users of plain NixOS.Things done
build-use-sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)I have tested this change manually using nix-repl
The first module defines a default pkgs. This is what NixOps could do, for example. The second module sets pkgs to null so we get the old behavior in this example. Omitting the second module has the effect of using the default pkgs from 'NixOps'.
This change is relevant for #32422 and improving NixOps performance.