Add Nixpkgs entrypoint lib, <flake>.lib.nixpkgs.configure, (import <nixpkgs>).configure#402298
Add Nixpkgs entrypoint lib, <flake>.lib.nixpkgs.configure, (import <nixpkgs>).configure#402298roberth wants to merge 2 commits intoNixOS:masterfrom
<flake>.lib.nixpkgs.configure, (import <nixpkgs>).configure#402298Conversation
A clean entrypoint into Nixpkgs not too burdened by 20 years of history.
|
I've been thinking a bit about the nixpkgs entrypoint / how to call "nixpkgs the function" in the last couple of days. I'm coming from #380342 and how the top-level package sets like
Those aspects are orthogonal to this PR here, which is precisely about the other case - calling I think it makes sense to think about both things at the same time and implement something that works well for both. For example, if we find a better way to say "I want a fully static package sets" instead of The The idea would then be to turn:
I'm not too happy with the latter, and also experimented with a fake derivation in the flake's Those attribute chains could then be arbitrarily nested, so we could for example do I'd really like to hear your thoughts on this. |
| However, not everything that is specific to Nixpkgs is _relative_ to the _configured_ package set. | ||
|
|
||
| This library is specifically for un-configured things such as the `configure` function, which is used to produce the configured package set. | ||
| Other functions and values that relate to packages without referring to instantiated packages can be added here too. |
There was a problem hiding this comment.
| Other functions and values that relate to packages without referring to instantiated packages can be added here too. | |
| Other functions and values that relate to packages without referring to instantiated packages can be added here, too. |
Is this the right place for the comment, though? The place to add more functions is not here, but in pkgs/abs/default.nix, right? i.e. the functions should be part of lib.nixpkgs.<new_function>, right?
Seems like the whole big comment would be better off at the top of abs/default.nix?
There was a problem hiding this comment.
Not really but it works with :doc in the repl.
Something about adding functions is more the topic of an internal # comment.
There was a problem hiding this comment.
The meaning of the /abs/ folder is not immediately clear to me. I'd argue that this should not be inside pkgs/ at all, because pkgs implies the result of calling this function.
Given the CLI-entrypoint-idea in my previous comment, this could theoretically move to configure/ - although that would not work well for other functions than configure in the future.
There was a problem hiding this comment.
The meaning of the
/abs/folder is not immediately clear to me.
Remnant of a working title, "absolute", as opposed to relative to configuration parameters.
I'd argue that this should not be inside
pkgs/at all, becausepkgsimplies the result of calling this function.
In my mind, pkgs was always the Nixpkgs part of the nixpkgs repo, coincidentally matching the pkgs identifier, but you're right. It's confusing this way.
How about nixpkgs/? Then we have a decent correspondence between this repo's components (including potentially as libraries) and their paths. Then only significant exception is that pkgs/ isn't inside of nixpkgs/ for historical reasons and convenience.
There was a problem hiding this comment.
How about
nixpkgs/? Then we have a decent correspondence between this repo's components (including potentially as libraries) and their paths. Then only significant exception is thatpkgs/isn't inside ofnixpkgs/for historical reasons and convenience.
If we put this into nixpkgs/, then the CLI interface would become something like nix-build nixpkgs -A static.pkgs. Cool.
The nice thing is, that we could also add a "fake derivation" to packages for the flake, which would allow something like nix build '.#nixpkgs.static.pkgs - because the top-level package name "nixpkgs" is really not needed.
There was a problem hiding this comment.
Then only significant exception is that
pkgs/isn't inside ofnixpkgs/for historical reasons and convenience.
Maybe that's not too bad anyway - because in a way pkgs are used for both "nixpkgs" and "NixOS". Somebody running NixOS doesn't really need to know about the difference? Those packages are available via { pkgs, ... }, so they live in pkgs/ - cool.
(Not sure whether I convinced myself with that, though ... :D)
| elaborateSomewhat = platform: if isString platform then { system = platform; } else platform; | ||
|
|
||
| hostPlatform = elaborateSomewhat parameters.hostPlatform; | ||
| buildPlatform = elaborateSomewhat parameters.buildPlatform; |
There was a problem hiding this comment.
This is what lib.systems.systemToAttrs does, we can call it here.
| elaborateSomewhat = platform: if isString platform then { system = platform; } else platform; | |
| hostPlatform = elaborateSomewhat parameters.hostPlatform; | |
| buildPlatform = elaborateSomewhat parameters.buildPlatform; | |
| hostPlatform = lib.systems.systemToAttrs parameters.hostPlatform; | |
| buildPlatform = lib.systems.systemToAttrs parameters.buildPlatform; |
There was a problem hiding this comment.
I vaguely remembered, but I didn't take the time to look up the new proper solution yet ❤️
| localSystem = elaborateSomewhat (if isCross then parameters.buildPlatform else parameters.hostPlatform); | ||
| ${if isCross then "crossSystem" else null} = elaborateSomewhat parameters.hostPlatform; |
There was a problem hiding this comment.
We already elaborated-somewhat above, so this could just be:
| localSystem = elaborateSomewhat (if isCross then parameters.buildPlatform else parameters.hostPlatform); | |
| ${if isCross then "crossSystem" else null} = elaborateSomewhat parameters.hostPlatform; | |
| localSystem = if isCross then buildPlatform else hostPlatform; | |
| ${if isCross then "crossSystem" else null} = hostPlatform; |
| hostPlatform = elaborateSomewhat parameters.hostPlatform; | ||
| buildPlatform = elaborateSomewhat parameters.buildPlatform; | ||
|
|
||
| isCross = parameters?buildPlatform && ! lib.systems.equals hostPlatform buildPlatform; |
There was a problem hiding this comment.
To properly call equals, we'd need fully elaborated systems, I think. That's because there could be redundant data passed to one system, that will elaborate to the same platform, but is not exactly the same attrset.
For example:
{ system = "x86_64-linux"; }
{ config = "x86_64-unknown-linux-gnu"; }
Those two should be equal, but equals as-is would return false.
However, do we even need to do all the isCross logic? The old interface needed it, because system would default to set localSystem. This defaults to set hostPlatform, though.
Could we reduce isCross to isCross = parameters ? buildPlatform? I'm not sure what the implications for the NixOS nixpkgs modules would be, though.
Note, that top-level/default.nix does "equals dance" as well (but with elaborated systems), so this might not make any practical difference, if we leave it out here.
| - `stdenv`: The standard build environment | ||
| - `testers`: Functions that produce derivations that fail to build if something is wrong. | ||
| */ | ||
| # TODO: review copied `crossOverlays` doc: isn't it supposed to be "host packages only"? We don't even have "target" in this context. |
There was a problem hiding this comment.
That's probably right, yes.
I think we should:
- Call them
hostOverlays. - Pass them to
overlaysifisCrossis false. - Pass them to
crossOverlaysifisCrossis true.
That would match the new hostPlatform-centric interface, right?
There was a problem hiding this comment.
That seems exactly right!
|
@wolfgangwalther thank you for your excellent review. I quite like your idea to provide an attribute-based interface for the Nixpkgs entrypoint. I think it qualifies as a "fluent interface", which is generally not something we should do in the Nix language, but this is an exception.
In this case, the we have overriding concerns for each of these, so I think we should use the pattern, while adding a note in the implementation and manual that this style of interface should only be used for CLI-oriented wrapper interfaces (or "facades"). So I think we could have this in both a new file, as well as in the flake, and that's even if flakes will have a better configurability feature at some point. |
{host,build}Platformdirectly + Nixpkgs fn docs #324614nixpkgsFlake.lib.lib#398332Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.