refactor(flake)!: flake.autoStuff
-> auto.stuff
Avoids infinite recursion in `auto.configurations` and `auto.modules` Can now fully dynamically define `configuration` and `module` types
This commit is contained in:
parent
ea47ccd981
commit
7956cfd20a
6 changed files with 118 additions and 105 deletions
37
flake.nix
37
flake.nix
|
@ -11,6 +11,11 @@
|
|||
"x86_64-darwin"
|
||||
];
|
||||
|
||||
# BUG: infinite recursion
|
||||
# imports = [
|
||||
# ./modules/flake/modules
|
||||
# ] ++ inputs.self.flakeModules;
|
||||
|
||||
imports = [
|
||||
./modules/flake/lib
|
||||
./modules/flake/pkgs
|
||||
|
@ -23,6 +28,23 @@
|
|||
./modules/flake/shells
|
||||
];
|
||||
|
||||
auto = {
|
||||
# Automatic modules, see `./modules/flake/modules/default.nix`
|
||||
modules.enableAll = true;
|
||||
|
||||
# Automatic configurations, see `./modules/flake/configurations/default.nix`
|
||||
configurations.enableAll = true;
|
||||
|
||||
# Automatic packages, see `./modules/flake/packages/default/default.nix`
|
||||
packages.enable = true;
|
||||
|
||||
# Automatic overlays, see `./modules/flake/overlays/default/default.nix`
|
||||
overlays.enable = true;
|
||||
|
||||
# Automatic devShells, see `./modules/flake/shells/default/default.nix`
|
||||
devShells.enable = true;
|
||||
};
|
||||
|
||||
perSystem = { lib, pkgs, system, ... }: {
|
||||
# Apps (`nix run`)
|
||||
apps = import ./apps { inherit pkgs; };
|
||||
|
@ -34,21 +56,6 @@
|
|||
flake = {
|
||||
inherit (inputs) self;
|
||||
|
||||
# Automatic modules, see `./modules/flake/modules/default.nix`
|
||||
autoModules.enableAll = true;
|
||||
|
||||
# Automatic configurations, see `./modules/flake/configurations/default.nix`
|
||||
autoConfigurations.enableAll = true;
|
||||
|
||||
# Automatic packages, see `./modules/flake/packages/default/default.nix`
|
||||
autoPackages.enable = true;
|
||||
|
||||
# Automatic overlays, see `./modules/flake/overlays/default/default.nix`
|
||||
autoOverlays.enable = true;
|
||||
|
||||
# Automatic devShells, see `./modules/flake/shells/default/default.nix`
|
||||
autoDevShells.enable = true;
|
||||
|
||||
# Templates
|
||||
templates = import ./templates {
|
||||
inherit inputs;
|
||||
|
|
|
@ -7,8 +7,7 @@ let
|
|||
hasDirectories
|
||||
recurseDir
|
||||
kebabToCamel
|
||||
configuration-type-to-outputs-modules
|
||||
configuration-type-to-outputs-configurations;
|
||||
configuration-type-to-outputs-modules;
|
||||
in
|
||||
let
|
||||
# Configuration helpers
|
||||
|
@ -140,7 +139,7 @@ in
|
|||
options = let
|
||||
inherit (lib) types;
|
||||
in {
|
||||
flake.autoConfigurations = lib.mkOption {
|
||||
auto.configurations = lib.mkOption {
|
||||
description = ''
|
||||
Automagically generate configurations from walking directories with Nix files
|
||||
'';
|
||||
|
@ -426,19 +425,10 @@ in
|
|||
};
|
||||
|
||||
config = {
|
||||
# BUG: cannot iterate on `config.flake.autoConfigurations.resultConfigurations`
|
||||
# because of infinite recursion
|
||||
flake = let
|
||||
ogConfigurationTypes = ["nixos" "nix-on-droid" "nix-darwin" "home-manager"];
|
||||
configurations = lib.pipe ogConfigurationTypes [
|
||||
(lib.map
|
||||
configuration-type-to-outputs-configurations)
|
||||
(lib.flip lib.genAttrs
|
||||
(configurationType:
|
||||
config.flake.autoConfigurations.resultConfigurations.${configurationType}))
|
||||
];
|
||||
configurations = config.auto.configurations.resultConfigurations;
|
||||
deployNodes = {
|
||||
deploy.nodes = config.flake.autoConfigurations.resultDeployNodes;
|
||||
deploy.nodes = config.auto.configurations.resultDeployNodes;
|
||||
};
|
||||
deployChecks = {
|
||||
checks =
|
||||
|
|
|
@ -3,12 +3,10 @@
|
|||
let
|
||||
inherit (config.lib)
|
||||
createThings
|
||||
configuration-type-to-outputs-modules;
|
||||
kebabToCamel;
|
||||
in
|
||||
let
|
||||
# Modules helpers
|
||||
moduleTypes = ["nixos" "nix-on-droid" "nix-darwin" "home-manager" "flake"];
|
||||
|
||||
createModules = baseDir:
|
||||
createThings {
|
||||
inherit baseDir;
|
||||
|
@ -19,11 +17,17 @@ in
|
|||
options = let
|
||||
inherit (lib) types;
|
||||
in {
|
||||
flake.autoModules = lib.mkOption {
|
||||
auto.modules = lib.mkOption {
|
||||
description = ''
|
||||
Automagically generate modules from walking directories with Nix files
|
||||
'';
|
||||
type = types.submodule (submodule: {
|
||||
type = types.submodule (autoModulesSubmodule: let
|
||||
inherit (autoModulesSubmodule.config)
|
||||
moduleTypes
|
||||
enableAll
|
||||
baseDir
|
||||
;
|
||||
in {
|
||||
options = {
|
||||
enableAll = lib.mkEnableOption "Automatic ${builtins.toString moduleTypes} modules extraction";
|
||||
baseDir = lib.mkOption {
|
||||
|
@ -34,29 +38,31 @@ in
|
|||
default = "${self}/modules";
|
||||
defaultText = ''''${self}/modules'';
|
||||
};
|
||||
} // (
|
||||
lib.pipe
|
||||
moduleTypes
|
||||
[
|
||||
(builtins.map
|
||||
# NOTE: create small submodule for every `moduleType`
|
||||
(moduleType:
|
||||
lib.nameValuePair
|
||||
"${moduleType}"
|
||||
(lib.mkOption {
|
||||
type = types.submodule {
|
||||
moduleTypes = lib.mkOption {
|
||||
type = types.attrsOf (types.submodule (moduleTypeSubmodule@{ name, ... }: let
|
||||
inherit (moduleTypeSubmodule.config)
|
||||
enable
|
||||
dir
|
||||
;
|
||||
in {
|
||||
options = {
|
||||
# NOTE: each can be enabled (default global `enableAll`)
|
||||
enable = lib.mkEnableOption "Automatic ${moduleType} modules extraction" // {
|
||||
default = submodule.config.enableAll;
|
||||
enable = lib.mkEnableOption "Automatic ${name} modules extraction" // {
|
||||
default = enableAll;
|
||||
};
|
||||
# NOTE: each can be read from a different directory
|
||||
# (default global `baseDir` + `camelToKebab`-ed `moduleType`)
|
||||
dir = lib.mkOption {
|
||||
type = types.path;
|
||||
default = "${submodule.config.baseDir}/${moduleType}";
|
||||
default = "${baseDir}/${name}";
|
||||
};
|
||||
result = lib.mkOption {
|
||||
modulesName = lib.mkOption {
|
||||
description = ''
|
||||
Name of the `modules` output
|
||||
'';
|
||||
type = types.str;
|
||||
default = "${kebabToCamel name}Modules";
|
||||
};
|
||||
resultModules = lib.mkOption {
|
||||
description = ''
|
||||
The resulting automatic packages
|
||||
'';
|
||||
|
@ -66,15 +72,37 @@ in
|
|||
internal = true;
|
||||
default =
|
||||
lib.optionalAttrs
|
||||
config.flake.autoModules.${moduleType}.enable
|
||||
(createModules config.flake.autoModules.${moduleType}.dir);
|
||||
enable
|
||||
(createModules dir);
|
||||
};
|
||||
};
|
||||
config = {};
|
||||
}));
|
||||
# TODO: put in a more visible place
|
||||
default = {
|
||||
nixos = {};
|
||||
nix-on-droid = {};
|
||||
nix-darwin = {
|
||||
modulesName = "darwinModules";
|
||||
};
|
||||
home-manager = {};
|
||||
flake = {};
|
||||
};
|
||||
};
|
||||
resultModules = lib.mkOption {
|
||||
readOnly = true;
|
||||
default = lib.pipe moduleTypes [
|
||||
(lib.mapAttrs'
|
||||
(moduleType: moduleTypeConfig:
|
||||
lib.nameValuePair
|
||||
moduleTypeConfig.modulesName
|
||||
(lib.mapAttrs
|
||||
(host: module:
|
||||
module)
|
||||
moduleTypeConfig.resultModules)))
|
||||
];
|
||||
};
|
||||
};
|
||||
default = {};
|
||||
})))
|
||||
builtins.listToAttrs
|
||||
]);
|
||||
});
|
||||
default = {};
|
||||
};
|
||||
|
@ -82,19 +110,7 @@ in
|
|||
|
||||
config = {
|
||||
flake = let
|
||||
autoModules =
|
||||
lib.pipe
|
||||
moduleTypes
|
||||
[
|
||||
(builtins.map
|
||||
(moduleType:
|
||||
let
|
||||
name = "${configuration-type-to-outputs-modules moduleType}";
|
||||
value = config.flake.autoModules.${moduleType}.result;
|
||||
in
|
||||
lib.nameValuePair name value))
|
||||
builtins.listToAttrs
|
||||
];
|
||||
autoModules = config.auto.modules.resultModules;
|
||||
in autoModules;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ in
|
|||
options = let
|
||||
inherit (lib) types;
|
||||
in {
|
||||
flake.autoOverlays = lib.mkOption {
|
||||
auto.overlays = lib.mkOption {
|
||||
description = ''
|
||||
Automagically generate overlays from walking directories with Nix files
|
||||
'';
|
||||
|
@ -39,8 +39,8 @@ in
|
|||
internal = true;
|
||||
default =
|
||||
lib.optionalAttrs
|
||||
config.flake.autoOverlays.enable
|
||||
(createOverlays config.flake.autoOverlays.dir);
|
||||
config.auto.overlays.enable
|
||||
(createOverlays config.auto.overlays.dir);
|
||||
};
|
||||
};
|
||||
});
|
||||
|
@ -52,7 +52,7 @@ in
|
|||
flake = let
|
||||
overlays =
|
||||
lib.pipe
|
||||
config.flake.autoOverlays.result
|
||||
config.auto.overlays.result
|
||||
[
|
||||
(lib.mapAttrs
|
||||
(name: overlay:
|
||||
|
|
|
@ -19,7 +19,7 @@ in
|
|||
options = let
|
||||
inherit (lib) types;
|
||||
in {
|
||||
flake.autoPackages = lib.mkOption {
|
||||
auto.packages = lib.mkOption {
|
||||
description = ''
|
||||
Automagically generate packages from walking directories with Nix files
|
||||
'';
|
||||
|
@ -46,8 +46,8 @@ in
|
|||
internal = true;
|
||||
default =
|
||||
lib.optionalAttrs
|
||||
config.flake.autoPackages.enable
|
||||
(createPackages config.flake.autoPackages.dir);
|
||||
config.auto.packages.enable
|
||||
(createPackages config.auto.packages.dir);
|
||||
};
|
||||
};
|
||||
});
|
||||
|
@ -59,7 +59,7 @@ in
|
|||
perSystem = { lib, pkgs, system, ... }: let
|
||||
packages =
|
||||
lib.pipe
|
||||
config.flake.autoPackages.result
|
||||
config.auto.packages.result
|
||||
[
|
||||
(lib.filterAttrs
|
||||
(name: { package, systems }:
|
||||
|
|
|
@ -19,7 +19,7 @@ in
|
|||
options = let
|
||||
inherit (lib) types;
|
||||
in {
|
||||
flake.autoDevShells = lib.mkOption {
|
||||
auto.devShells = lib.mkOption {
|
||||
description = ''
|
||||
Automagically generate devShells from walking directories with Nix files
|
||||
'';
|
||||
|
@ -46,8 +46,8 @@ in
|
|||
internal = true;
|
||||
default =
|
||||
lib.optionalAttrs
|
||||
config.flake.autoDevShells.enable
|
||||
(createDevShells config.flake.autoDevShells.dir);
|
||||
config.auto.devShells.enable
|
||||
(createDevShells config.auto.devShells.dir);
|
||||
};
|
||||
};
|
||||
});
|
||||
|
@ -59,7 +59,7 @@ in
|
|||
perSystem = { lib, pkgs, system, ... }: let
|
||||
devShells =
|
||||
lib.pipe
|
||||
config.flake.autoDevShells.result
|
||||
config.auto.devShells.result
|
||||
[
|
||||
(lib.filterAttrs
|
||||
(name: { devShell, systems }:
|
||||
|
|
Loading…
Reference in a new issue