-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
Add Nixpkgs invocation helper modules #231940
base: master
Are you sure you want to change the base?
Conversation
4dbad27
to
fc99ccc
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.
Just a superficial review. TBH the documentation doesn't explain to me who and what this thing is for exactly, and how it's supposed to be used. I could go into option documentation if you like, once the big picture is clear.
doc/using/configuration.chapter.md
Outdated
@@ -189,6 +189,13 @@ The following attributes can be passed in [`config`](#chap-packageconfig). | |||
<include xmlns="http://www.w3.org/2001/XInclude" href="../doc-support/result/config-options.docbook.xml"/> | |||
``` | |||
|
|||
## Calling Nixpkgs from the Module System {#sec-invoke-nixpkgs-by-module} | |||
|
|||
For [module system](#module-system) application authors, Nixpkgs provides a reusable module for the purpose of invoking Nixpkgs. Most users should not have to be aware of this. The documentation for its options is meant to be re-exposed in the application's documentation and is therefore not repeated here. |
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.
By "module system application" you mean things like Home Manager? I'm not sure what you mean here.
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 what I meant.
I don't know how to say this without going on a tangent. I think going on a tangent to explain this would distract from the content. Most users will know to skip the clause or skip the paragraph.
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.
For [module system](#module-system) application authors, Nixpkgs provides a reusable module for the purpose of invoking Nixpkgs. Most users should not have to be aware of this. The documentation for its options is meant to be re-exposed in the application's documentation and is therefore not repeated here. | |
For authors of applications based on the [module system](#module-system), Nixpkgs provides a reusable module for the purpose of invoking Nixpkgs. Most users should not have to be aware of this. The documentation for its options is meant to be re-exposed in the application's documentation and is therefore not repeated here. |
I can do a documentation review pass when the implementation is done. Unsubscribing for now, ping me if needed.
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 didn't re-review the docs; I trust @fricklerhandwerk on that.
I reviewed the rest, and it looks good modulo these small few things. Excited that we are getting started on the idea behind NixOS/rfcs#78 --- the grand module deduplication!!
fbc4997
to
f2a2474
Compare
7890fa9
to
8eb5efe
Compare
a5fcf29
to
25a0939
Compare
A helper for module system applications. Naming compatible with NixOS/nix#6257 To be supported by nix flake check in NixOS/nix#8332 Concept is in the spirit of a proposed module based solution to [RFC 0078 System-agnostic configuration file generators](NixOS/rfcs#78).
This hack isn't needed anymore, and would be incompatible with having submodule at `nixpkgs.*`.
A feature flag warning was rightfully picked up by ofborg. This should solve it, and hopefully help out the next person who tries to render docs for an optional module.
25a0939
to
01df1f8
Compare
In the outer rings of context to this PR, I have attempted abstractions in a similar problem domain spanning beyond nixpkgs here. Note that this comment has no bearing to this PR beyond situational awareness for interested parties. |
Co-authored-by: David Arnold <dgx.arnold@gmail.com>
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.
Reviewed together with @roberth on a call
{ | ||
disabledModules = [ | ||
# This replaces the traditional nixpkgs module | ||
../nixpkgs.nix |
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 module has other imports that would also get removed:
nixpkgs/nixos/modules/misc/nixpkgs.nix
Lines 99 to 103 in 4f51d81
imports = [ | |
./assertions.nix | |
./meta.nix | |
(mkRemovedOptionModule [ "nixpkgs" "initialSystem" ] "The NixOS options `nesting.clone` and `nesting.children` have been deleted, and replaced with named specialisation. Therefore `nixpgks.initialSystem` has no effect anymore.") | |
]; |
{ | ||
disabledModules = [ | ||
# This replaces the traditional nixpkgs module | ||
../nixpkgs.nix |
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.
Why does this have to be a separate module? How about updating the ../nixpkgs.nix
one, and soft deprecating the localSystem
and crossSystem
options.
{ | ||
options = { | ||
hostPlatform = mkOption { | ||
type = types.coercedTo types.str lib.systems.elaborate types.attrs; |
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.
We shouldn't use types.attrs
, has weird merging behavior, types.raw
should be fine
type = types.coercedTo types.str lib.systems.elaborate types.attrs; | |
type = types.coercedTo types.str lib.systems.elaborate types.raw; |
Same for the other options.
{ allowBroken = true; allowUnfree = true; } | ||
''; | ||
# FIXME: use a mergeable type, like NixOS but not a hack | ||
type = types.unique { message = "nixpkgs/pkgs/top-level/module.nix: Merging is not supported for the Nixpkgs config option yet."; } types.attrs; |
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.
type = types.unique { message = "nixpkgs/pkgs/top-level/module.nix: Merging is not supported for the Nixpkgs config option yet."; } types.attrs; | |
type = types.unique { message = "nixpkgs/pkgs/top-level/module.nix: Merging is not supported for the Nixpkgs config option yet."; } types.raw; |
Or attrsOf raw
if lib.mapAttrs (_: _: null) (builtins.removeAttrs inputsSet ["hostPlatform"]) | ||
!= { hostPlatform = null; } |
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.
Seems wrong, but could also be done with builtins.removeAttrs inputsSet [ "hostPlatform" ] != { }
isCross = config.buildPlatform != config.hostPlatform; | ||
systemArgs = |
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.
Let's have a comment here mentioning that this is a bit of a hack and should be moved into the pkgs entrypoint function definition
# key are usable with _memoize implementations that are not aware of them, | ||
# as long as these additions are unused. | ||
inputsSet = lib.filterAttrs | ||
(_: v: v != v.isDefined && v.highestPrio < optDefaultPrio) |
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.
This condition needs a bit of work, v != v.isDefined
seems wrong (detected by @roberth himself!)
pkgsMemoizer = { pkgs, inputsSet, ... }: | ||
let system = lib.systems.toLosslessStringMaybe inputsSet.hostPlatform.value.system; | ||
in | ||
if lib.attrNames inputsSet == [ "hostPlatform" ] && system != null |
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.
See also the other comment
@@ -12,6 +12,20 @@ | |||
lib = import ./lib; | |||
|
|||
forAllSystems = lib.genAttrs lib.systems.flakeExposed; | |||
|
|||
pkgsMemoizer = { pkgs, inputsSet, ... }: | |||
let system = lib.systems.toLosslessStringMaybe inputsSet.hostPlatform.value.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.
let system = lib.systems.toLosslessStringMaybe inputsSet.hostPlatform.value.system; | |
let system = lib.systems.toLosslessStringMaybe inputsSet.hostPlatform.value.system; |
Calling this on system
sounds wrong 😆
Description of changes
This makes a number of well tested and documented additions that lead up to
... using the supporting additions and improvements:
lib.systems.equals
function for comparing elaborated system strings.lib.systems.toLosslessStringMaybe
which is useful for converting elaborated systems to optional attribute names.lib.systems
tests are now run by ofborg.This PR contains commits that have been split into a separate PR
lib.systems.equals
#237512Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)