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,15 +14,30 @@
./wrapper-manager.nix
];
options.setups.sharedNixpkgsConfig = lib.mkOption {
type = with lib.types; attrsOf anything;
description = ''
Shared configuration of the nixpkgs instance to be passed to all of the
module environments based from the nixpkgs module system.
'';
default = { };
example = {
allowUnfree = true;
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;
description = ''
Shared configuration of the nixpkgs instance to be passed to all of the
module environments based from the nixpkgs module system.
'';
default = { };
example = {
allowUnfree = true;
};
};
};
}

View File

@ -8,6 +8,7 @@
let
cfg = config.setups.disko;
partsConfig = config;
diskoConfigType = { name, config, ... }: {
options = {
@ -57,7 +58,7 @@ in
config = lib.mkIf (config.diskoConfigs != [ ]) (
let
diskoConfigs =
builtins.map (name: import ../../../configs/disko/${name}) config.diskoConfigs;
builtins.map (name: import "${partsConfig.setups.configDir}/disko/${name}") config.diskoConfigs;
in
{
modules = lib.singleton {
@ -75,6 +76,6 @@ in
config = {
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 = {
modules = [
../../../configs/home-manager/${config.configName}
"${partsConfig.setups.configDir}/home-manager/${config.configName}"
(
let

View File

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

View File

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

View File

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