-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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/nixpkgs: add option to specify Nixpkgs source path #373201
base: master
Are you sure you want to change the base?
Conversation
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.
Can't comment too much about the change itself since I use Flakes, but at least the nixos-rebuild-ng
changes looks good to me.
Left a comment about the tests mocks but this is not a merge blocker.
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.
Hey, nixpkgs.source
option in nixos is an interesting approach to pin nixpkgs for a given nixos configuration. I found several issues with your implementation of it.
I cannot review changes in nixos-rebuild-ng because I am not familiar with its code.
in nixos-rebuild.sh, there is also one more instance of getting nixpkgs from nix path in line 646 (after changes). I think you forgot about that occurence.
I just noticed that there is option |
bd5f609
to
e2076cf
Compare
Thank you for reviewing!
Yes, I missed it because I was looking only for the angle brackets syntax. |
f4152b0
to
2c1cfe0
Compare
I think we should unify the two options. |
2c1cfe0
to
9c91df5
Compare
I made an attempt to unify flakes and non-flakes options in 0fca667. The flake part is completely untested for now. |
9c91df5
to
887facb
Compare
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.
nixos-rebuild-ng
part LGTM, but not tested.
Also didn't review the other changes.
03adbc7
to
b233775
Compare
b233775
to
5252286
Compare
b119c71
to
61e4dbe
Compare
This moves the options under `nixpkgs.flake` to `nixpkgs` and generalises them to work with systems built without flakes. Specifically, nixpkgs.source now allows to pin the version of nixpkgs used by nixos-rebuild to build the system, even without flakes.
This option can be used by other NixOS modules to detect whether the system is being built from a flake.
61e4dbe
to
e84a41a
Compare
e84a41a
to
8247d9f
Compare
if nixpkgsPath=$(test -n "$NIXOS_CONFIG" && runCmd nix-instantiate --eval --expr " | ||
(import <nixpkgs/nixos> { | ||
configuration = { | ||
imports = [ $NIXOS_CONFIG ]; | ||
_module.check = false; | ||
}; | ||
}).config.nixpkgs.source |
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'm really not a fan of this. It's fundamentally impossible to make configuration.nix
specify Nixpkgs and it be used consistently, you always end up with the same problematic cases, such as:
- A separate Nixpkgs is needed to "bootstrap" the eval, like the
<nixpkgs>
here. And this is not reproducible in general. - Upgrades across Nixpkgs versions are problematic, because some module might not evaluate with both the older and newer Nixpkgs (the
_module.check
can't ignore everything)
The real solution is to abandon the idea of "configuration.nix
can reproduce the system" and switch to "system.nix
/flake.nix
/default.nix
can reproduce the system", where that entry-point file depends on configuration.nix
. That's something that Flakes got right, and it's also the direction I've indicated with #333788. This way there's none of the above problems.
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.
Agreed, I kinda think of the non Flakes way as legacy and so large changes specific for it shouldn't be made. Flakes is the direction a lot of things are going and just manages it a lot cleaner.
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 don't necessarily agree with that. I don't want people to have to buy into Flakes just to have an eval-reproducible system. It's very easy to make something similar work in traditional Nix, it's not a large change.
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 fundamentally impossible to make configuration.nix specify Nixpkgs and it be used consistently
My initial proposal was to use callPackage
(or similar) to fill in the arguments of configuration.nix
and extract nixpkgs.source
, without using evalModules
. This works reliably with the only limitation that nixpkgs.source
must not depend on any of the module arguments and be set directly in configuration.nix
.
The real solution is to abandon the idea of "configuration.nix can reproduce the system"
Yes, but even then it's a letdown that you can't have a self-contained expression to describe a system reproducibly.
It means you'll never be able to just copy-paste, build and get the same 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.
Nah it's totally possible. With #333788, you can write a /etc/nixos/system.nix
as follows:
let
nixpkgs = fetchTarball { ... };
in
import (nixpkgs + "/nixos") {
configuration = {
environment.systemPackages = [ ... ];
};
# Or if you want to have the traditional `configuration.nix`:
# configuration = ./configuration.nix;
}
And nixos-rebuild switch
works.
A non-breaking and (IMHO) simpler alternative to #333788 for setting the Nixpkgs versions declaratively from configuration.nix.
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nixos-rebuild
,nixos-rebuild-ng
)Add a 👍 reaction to pull requests you find important.