Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,26 @@ let
in
eval.config.flake;

# For extending options in an already declared submodule.
# Workaround for https://github.com/NixOS/nixpkgs/issues/146882
/**
Deprecated. Declare options directly, e.g. `options.foo.bar = mkOption { ... }`,
provided that `foo` is already declared as a submodule option.

In flake-parts, `flake` is declared as a submodule option by the core modules,
so `options.flake.<name>` declarations work directly.

This function wraps option declarations in a submodule, allowing them to
be merged into an existing submodule option. For example, if `foo` is
already declared as a submodule option, using
`options.foo = mkSubmoduleOptions { bar = mkOption {...}; }` would add
`bar` to the `foo` submodule.

# History

This was a workaround for https://github.com/NixOS/nixpkgs/issues/146882,
fixed in Nixpkgs 22.05 by https://github.com/NixOS/nixpkgs/pull/156533.
With the fix, declaring `options.foo.bar` directly works when `foo` is
already a submodule option. Documented as deprecated in flake-parts in January 2026.
*/
mkSubmoduleOptions =
options:
mkOption {
Expand Down Expand Up @@ -177,8 +195,7 @@ let
_file = file;

options = {
flake = flake-parts-lib.mkSubmoduleOptions {
${name} = mkOption {
flake.${name} = mkOption {
type = attrsWith {
elemType = option.type;
lazy = true;
Expand All @@ -189,7 +206,6 @@ let
See {option}`perSystem.${name}` for description and examples.
'';
};
};

perSystem = flake-parts-lib.mkPerSystemOption {
_file = file;
Expand Down
5 changes: 1 addition & 4 deletions modules/formatter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@ let
types
;
inherit (flake-parts-lib)
mkSubmoduleOptions
mkPerSystemOption
;
in
{
options = {
flake = mkSubmoduleOptions {
formatter = mkOption {
flake.formatter = mkOption {
type = types.lazyAttrsOf types.package;
default = { };
description = ''
An attribute set of per system a package used by [`nix fmt`](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-fmt.html).
'';
};
};

perSystem = mkPerSystemOption {
_file = ./formatter.nix;
Expand Down
9 changes: 2 additions & 7 deletions modules/nixosConfigurations.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
{ lib, flake-parts-lib, ... }:
{ lib, ... }:
let
inherit (lib)
mkOption
types
literalExpression
;
inherit (flake-parts-lib)
mkSubmoduleOptions
;
in
{
options = {
flake = mkSubmoduleOptions {
nixosConfigurations = mkOption {
flake.nixosConfigurations = mkOption {
type = types.lazyAttrsOf types.raw;
default = { };
description = ''
Expand All @@ -37,5 +33,4 @@ in
'';
};
};
};
}
9 changes: 2 additions & 7 deletions modules/nixosModules.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
{ self, lib, flake-parts-lib, moduleLocation, ... }:
{ self, lib, moduleLocation, ... }:
let
inherit (lib)
mapAttrs
mkOption
types
;
inherit (flake-parts-lib)
mkSubmoduleOptions
;
in
{
options = {
flake = mkSubmoduleOptions {
nixosModules = mkOption {
flake.nixosModules = mkOption {
type = types.lazyAttrsOf types.deferredModule;
default = { };
apply = mapAttrs (k: v: {
Expand All @@ -27,5 +23,4 @@ in
'';
};
};
};
}
9 changes: 2 additions & 7 deletions modules/overlays.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
{ lib, flake-parts-lib, ... }:
{ lib, ... }:
let
inherit (lib)
mkOption
types
;
inherit (flake-parts-lib)
mkSubmoduleOptions
;
in
{
options = {
flake = mkSubmoduleOptions {
overlays = mkOption {
flake.overlays = mkOption {
# uniq -> ordered: https://github.com/NixOS/nixpkgs/issues/147052
# also update description when done
type = types.lazyAttrsOf (types.uniq (types.functionTo (types.functionTo (types.lazyAttrsOf types.unspecified))));
Expand All @@ -33,5 +29,4 @@ in
'';
};
};
};
}