Skip to content

types.submoduleWith: Add evalModules function#143133

Closed
roberth wants to merge 1 commit intoNixOS:masterfrom
hercules-ci:types-submoduleWith-evalModules
Closed

types.submoduleWith: Add evalModules function#143133
roberth wants to merge 1 commit intoNixOS:masterfrom
hercules-ci:types-submoduleWith-evalModules

Conversation

@roberth
Copy link
Copy Markdown
Member

@roberth roberth commented Oct 27, 2021

Motivation for this change

This makes it easier to write configuration systems that can be
reused as submodules, by writing the configuration system as a
type, exposing the type (e.g. in a flake lib attribute), and
using the type's evalModules function in the configuration
system's own wiring.

The alternative, the status quo, is for the configuration system to duplicate its invocation logic when providing both a type and an evalModules-based function. This is error prone. Here's a best case example of the status quo:

let
  type = lib.types.submoduleWith {
    modules = myBuiltInModules;
    inherit specialArgs;
  };
  # Avoidable boilerplate:
  evalConfig = configuration: lib.evalModules {
    modules = [ configuration ] ++ myBuiltInModules;
    inherit specialArgs;
  };
  # With this pr
  evalConfig = configuration: type.evalModules { modules = [ configuration ]; };

Also note that because modules and specialArgs are now referenced only once, we don't need to rely on let bindings as much.

It also turns out the the internal evalTypeModules is a decent abstraction. Wasn't expecting that :)

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • 21.11 Release Notes (or backporting 21.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

This makes it easier to write configuration systems that can be
reused as submodules, by writing the configuration system as a
type, exposing the type (e.g. in a flake lib attribute), and
using the type's evalModules function in the configuration
system's own wiring.
@roberth roberth requested a review from infinisil October 27, 2021 11:32
@roberth roberth requested review from edolstra and nbp as code owners October 27, 2021 11:32
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Oct 27, 2021
@roberth
Copy link
Copy Markdown
Member Author

roberth commented Oct 29, 2021

Closing in favor of #143207

@roberth roberth closed this Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant