flake-parts/setups: create module option for unified configuration directory

This commit is contained in:
Gabriel Arazas 2024-07-23 18:27:15 +08:00
parent 78193d5270
commit dc31e3e36b
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
6 changed files with 32 additions and 15 deletions

View File

@ -14,7 +14,21 @@
./wrapper-manager.nix ./wrapper-manager.nix
]; ];
options.setups.sharedNixpkgsConfig = lib.mkOption { options.setups = {
configDir = lib.mkOption {
type = lib.types.path;
default = ../../../configs;
description = ''
The directory containing configurations of various environments. The
top-level directories are expected to be the name of the environment
with their configurations inside.
'';
example = lib.literalExpression ''
''${inputs.my-flake}/configs
'';
};
sharedNixpkgsConfig = lib.mkOption {
type = with lib.types; attrsOf anything; type = with lib.types; attrsOf anything;
description = '' description = ''
Shared configuration of the nixpkgs instance to be passed to all of the Shared configuration of the nixpkgs instance to be passed to all of the
@ -25,4 +39,5 @@
allowUnfree = true; allowUnfree = true;
}; };
}; };
};
} }

View File

@ -8,6 +8,7 @@
let let
cfg = config.setups.disko; cfg = config.setups.disko;
partsConfig = config;
diskoConfigType = { name, config, ... }: { diskoConfigType = { name, config, ... }: {
options = { options = {
@ -57,7 +58,7 @@ in
config = lib.mkIf (config.diskoConfigs != [ ]) ( config = lib.mkIf (config.diskoConfigs != [ ]) (
let let
diskoConfigs = diskoConfigs =
builtins.map (name: import ../../../configs/disko/${name}) config.diskoConfigs; builtins.map (name: import "${partsConfig.setups.configDir}/disko/${name}") config.diskoConfigs;
in in
{ {
modules = lib.singleton { modules = lib.singleton {
@ -75,6 +76,6 @@ in
config = { config = {
flake.diskoConfigurations = flake.diskoConfigurations =
lib.mapAttrs (name: _: import ../../../configs/disko/${name}) cfg.configs; lib.mapAttrs (name: _: import "${partsConfig.setups.configDir}/disko/${name}") cfg.configs;
}; };
} }

View File

@ -105,7 +105,7 @@ let
config = { config = {
modules = [ modules = [
../../../configs/home-manager/${config.configName} "${partsConfig.setups.configDir}/home-manager/${config.configName}"
( (
let let

View File

@ -6,6 +6,7 @@
let let
cfg = config.setups.nixos; cfg = config.setups.nixos;
partsConfig = config;
nixosModules = ../../nixos; nixosModules = ../../nixos;
# A thin wrapper around the NixOS configuration function. # A thin wrapper around the NixOS configuration function.
@ -172,7 +173,7 @@ let
config.modules = [ config.modules = [
# Bring in the required modules. # Bring in the required modules.
../../../configs/nixos/${config.configName} "${partsConfig.setups.configDir}/nixos/${config.configName}"
# Setting up the typical configuration. # Setting up the typical configuration.
( (

View File

@ -103,7 +103,7 @@ let
config = { config = {
modules = [ modules = [
../../../configs/nixvim/${config.configName} "${partsConfig.setups.configDir}/nixvim/${config.configName}"
]; ];
}; };
}; };

View File

@ -86,7 +86,7 @@ let
nixpkgs.config = cfg.sharedNixpkgsConfig; nixpkgs.config = cfg.sharedNixpkgsConfig;
modules = [ modules = [
../../../configs/wrapper-manager/${config.configName} "${partsConfig.setups.configDir}/wrapper-manager/${config.configName}"
]; ];
}; };
}; };