-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
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?
Changes from 9 commits
4aac481
bfe8fd2
7409534
1fad676
14400cd
20e482a
44930c1
fa1a58d
01df1f8
4f51d81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Calling this on |
||||||
in | ||||||
if lib.attrNames inputsSet == [ "hostPlatform" ] && system != null | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See also the other comment |
||||||
then | ||||||
# As only hostPlatform matters in this invocation, we can save | ||||||
# memory by sharing the Nixpkgs invocation. | ||||||
# `pkgs` is never evaluated. | ||||||
self.legacyPackages.${system} | ||||||
else | ||||||
# We let the module invoke Nixpkgs as usual. | ||||||
pkgs; | ||||||
|
||||||
in | ||||||
{ | ||||||
lib = lib.extend (final: prev: { | ||||||
|
@@ -58,18 +72,28 @@ | |||||
nixosModules = { | ||||||
notDetected = ./nixos/modules/installer/scan/not-detected.nix; | ||||||
|
||||||
/* | ||||||
Make the `nixpkgs.*` configuration read-only. Guarantees that `pkgs` | ||||||
is the way you initialize it. | ||||||
# See nixos/doc/manual/nixos-optional-modules.md | ||||||
# TODO: online manual link | ||||||
readOnlyPkgs = ./nixos/modules/misc/nixpkgs/read-only.nix; | ||||||
|
||||||
Example: | ||||||
# See nixos/doc/manual/nixos-optional-modules.md | ||||||
# TODO: online manual link | ||||||
noLegacyPkgs = { | ||||||
imports = [ ./nixos/modules/misc/nixpkgs/no-legacy.nix ]; | ||||||
nixpkgs._memoize = pkgsMemoizer; | ||||||
}; | ||||||
}; | ||||||
|
||||||
{ | ||||||
imports = [ nixpkgs.nixosModules.readOnlyPkgs ]; | ||||||
nixpkgs.pkgs = nixpkgs.legacyPackages.x86_64-linux; | ||||||
} | ||||||
*/ | ||||||
readOnlyPkgs = ./nixos/modules/misc/nixpkgs/read-only.nix; | ||||||
modules = { | ||||||
/* Modules that are not specific to any application of the module system. */ | ||||||
generic = { | ||||||
nixpkgs = { | ||||||
imports = [ | ||||||
./pkgs/top-level/module/module.nix | ||||||
]; | ||||||
config._memoize = pkgsMemoizer; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Optional Modules {#ch-optional-modules} | ||
|
||
## `noLegacyPkgs` {#sec-noLegacyPkgs} | ||
|
||
This module reimplements `nixpkgs.*` without legacy options such as `nixpkgs.localSystem`. | ||
|
||
When imported from the flake (experimental), this module will reuse `legacyPackages` when only `hostPlatform` is specified. | ||
|
||
This module is ignored when [`readOnlyPkgs`](#sec-readOnlyPkgs) is imported. | ||
|
||
Example use with a flake (experimental): | ||
|
||
```nix | ||
inputs.nixpkgs.lib.nixosSystem { | ||
modules = [ | ||
inputs.nixpkgs.nixosModules.noLegacyPkgs | ||
./configuration.nix | ||
]; | ||
} | ||
``` | ||
|
||
```{=include=} options | ||
id-prefix: module-noLegacyPkgs-opt- | ||
list-id: module-noLegacyPkgs-options | ||
source: @OPTIONS_JSON_noLegacyPkgs@ | ||
``` | ||
|
||
## `readOnlyPkgs` {#sec-readOnlyPkgs} | ||
|
||
This module ensures that the `pkgs` module argument is as specified, manually. | ||
|
||
The usual `nixpkgs.*` options are replaced by read-only options for compatibility. These are not listed here. NixOS modules should | ||
get their information from the `pkgs` module argument and ignore `nixpkgs.*`. | ||
|
||
Example use with a flake (experimental): | ||
|
||
```nix | ||
inputs.nixpkgs.lib.nixosSystem { | ||
modules = [ | ||
inputs.nixpkgs.nixosModules.readOnlyPkgs | ||
./configuration.nix | ||
{ | ||
nixpkgs.pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux; | ||
} | ||
]; | ||
} | ||
``` | ||
|
||
```{=include=} options | ||
id-prefix: module-readOnlyPkgs-opt- | ||
list-id: module-readOnlyPkgs-options | ||
source: @OPTIONS_JSON_readOnlyPkgs@ | ||
``` |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,39 @@ | ||||||||||||
/* | ||||||||||||
A clean, [RFC 0078] style implementation of the NixOS `nixpkgs.*` module, which | ||||||||||||
is free of legacy options (as of 23.05). | ||||||||||||
|
||||||||||||
[RFC 0078]: https://github.com/NixOS/rfcs/pull/78 | ||||||||||||
*/ | ||||||||||||
|
||||||||||||
{ config, lib, ... }: | ||||||||||||
|
||||||||||||
{ | ||||||||||||
disabledModules = [ | ||||||||||||
# This replaces the traditional nixpkgs module | ||||||||||||
../nixpkgs.nix | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||||||||
]; | ||||||||||||
options = { | ||||||||||||
nixpkgs = lib.mkOption { | ||||||||||||
description = lib.mdDoc '' | ||||||||||||
Options that configure the `pkgs` module argument. | ||||||||||||
''; | ||||||||||||
example = lib.literalExpression '' | ||||||||||||
nixpkgs = { | ||||||||||||
config.allowUnfree = true; | ||||||||||||
overlays = [ | ||||||||||||
(final: prev: { | ||||||||||||
# Patch nixpkgs here | ||||||||||||
}) | ||||||||||||
]; | ||||||||||||
}; | ||||||||||||
''; | ||||||||||||
type = lib.types.submoduleWith { | ||||||||||||
shorthandOnlyDefinesConfig = true; | ||||||||||||
modules = [ ../../../../pkgs/top-level/module/module.nix ]; | ||||||||||||
}; | ||||||||||||
}; | ||||||||||||
}; | ||||||||||||
config = { | ||||||||||||
_module.args.pkgs = config.nixpkgs.pkgs; | ||||||||||||
}; | ||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ in | |
{ | ||
disabledModules = [ | ||
../nixpkgs.nix | ||
./no-legacy.nix | ||
]; | ||
options = { | ||
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.
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.
I can do a documentation review pass when the implementation is done. Unsubscribing for now, ping me if needed.