flake-parts/setups: refactor Disko integration

This commit is contained in:
Gabriel Arazas 2024-07-22 22:05:21 +08:00
parent 27153a368e
commit a56e3ed759
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
2 changed files with 35 additions and 24 deletions

View File

@ -4,7 +4,7 @@
# that. Take note we don't consider integrating this with declarative NixOS
# setups since their Disko scripts are already gettable in
# `config.system.build.diskoScript` along with its variants (e.g., `noDeps`).
{ config, lib, ... }:
{ config, lib, inputs, ... }:
let
cfg = config.setups.disko;
@ -39,6 +39,40 @@ in
};
};
options.setups.nixos.configs =
let
diskoIntegrationModule = { config, lib, name, ... }: {
options = {
diskoConfigs = lib.mkOption {
type = with lib.types; listOf str;
default = [ ];
example = [ "external-hdd" ];
description = ''
A list of declarative Disko configurations to be included alongside
the NixOS configuration.
'';
};
};
config = lib.mkIf (config.diskoConfigs != [ ]) (
let
diskoConfigs =
builtins.map (name: import ../../../configs/disko/${name}) config.diskoConfigs;
in
{
modules = lib.singleton {
imports =
[ inputs.disko.nixosModules.disko ]
++ (lib.lists.flatten diskoConfigs);
};
}
);
};
in
lib.mkOption {
type = with lib.types; attrsOf (submodule diskoIntegrationModule);
};
config = {
flake.diskoConfigurations =
lib.mapAttrs (name: _: import ../../../configs/disko/${name}) cfg.configs;

View File

@ -157,16 +157,6 @@ let
};
};
diskoConfigs = lib.mkOption {
type = with lib.types; listOf str;
default = [ ];
example = [ "external-hdd" ];
description = ''
A list of declarative Disko configurations to be included alongside
the NixOS configuration.
'';
};
shouldBePartOfNixOSConfigurations = lib.mkOption {
type = lib.types.bool;
default = lib.isAttrs config.deploy || config.formats == null;
@ -184,19 +174,6 @@ let
# Bring in the required modules.
../../../configs/nixos/${config.configName}
# Then we include the Disko configuration (if there's any).
(lib.mkIf (config.diskoConfigs != [ ]) (
let
diskoConfigs =
builtins.map (name: import ../../../configs/disko/${name}) config.diskoConfigs;
in
{
imports =
[ inputs.disko.nixosModules.disko ]
++ (lib.lists.flatten diskoConfigs);
})
)
# Setting up the typical configuration.
(
{ config, lib, ... }: {