flake-parts/setups/nixos: clean up the code

Make it snazzy, more readable, and stuff.
This commit is contained in:
Gabriel Arazas 2024-01-20 12:05:30 +08:00
parent 40895e71c3
commit 23d466dea6
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC

View File

@ -8,6 +8,9 @@
let let
cfg = config.setups.nixos; cfg = config.setups.nixos;
# This is used on a lot of the Nix modules below.
partsConfig = config;
# A thin wrapper around the NixOS configuration function. # A thin wrapper around the NixOS configuration function.
mkHost = { extraModules ? [ ], nixpkgsBranch ? "nixpkgs", system }: mkHost = { extraModules ? [ ], nixpkgsBranch ? "nixpkgs", system }:
let let
@ -99,11 +102,7 @@ let
}; };
}; };
homeManagerUserType = homeManagerUserType = { name, config, lib, ... }: {
let
partsConfig = config;
in
{ name, config, lib, ... }: {
options = { options = {
userConfig = lib.mkOption { userConfig = lib.mkOption {
type = with lib.types; attrsOf anything; type = with lib.types; attrsOf anything;
@ -142,11 +141,7 @@ let
}; };
}; };
configType = configType = { config, name, lib, ... }: {
let
partsConfig = config;
in
{ config, name, lib, ... }: {
options = { options = {
systems = lib.mkOption { systems = lib.mkOption {
type = with lib.types; listOf str; type = with lib.types; listOf str;
@ -398,9 +393,9 @@ let
overlays = lib.lists.flatten hmUsersOverlays; overlays = lib.lists.flatten hmUsersOverlays;
in in
# Most of the overlays are going to be imported from a flake # Most of the overlays are going to be imported from a
# input anyways. This should massively reduce the step needed # variable anyways. This should massively reduce the step
# for nixpkgs to do its thing. # needed for nixpkgs to do its thing.
# #
# Though, it becomes unpredictable due to the way how the # Though, it becomes unpredictable due to the way how the
# overlay list is constructed. However, this is much more # overlay list is constructed. However, this is much more
@ -499,20 +494,15 @@ in
config = lib.mkIf (cfg.configs != { }) { config = lib.mkIf (cfg.configs != { }) {
setups.nixos.sharedModules = [ setups.nixos.sharedModules = [
( ({ lib, ... }: {
let home-manager.sharedModules = partsConfig.setups.home-manager.sharedModules;
osConfig = config;
in
{ lib, ... }: {
home-manager.sharedModules = osConfig.setups.home-manager.sharedModules;
# These are just the recommended options for home-manager that may be # These are just the recommended options for home-manager that may be
# the default value in the future but this is how most of the NixOS # the default value in the future but this is how most of the NixOS
# setups are already done so... # setups are already done so...
home-manager.useUserPackages = lib.mkDefault true; home-manager.useUserPackages = lib.mkDefault true;
home-manager.useGlobalPkgs = lib.mkDefault true; home-manager.useGlobalPkgs = lib.mkDefault true;
} })
)
]; ];
flake = flake =
@ -540,12 +530,12 @@ in
{ {
nixosConfigurations = nixosConfigurations =
let let
renameSystems = name: system: config: renameSystem = name: system: config:
lib.nameValuePair "${name}-${system}" config; lib.nameValuePair "${name}-${system}" config;
in in
lib.concatMapAttrs lib.concatMapAttrs
(name: configs: (name: configs:
lib.mapAttrs' (renameSystems name) configs) lib.mapAttrs' (renameSystem name) configs)
pureNixosConfigs; pureNixosConfigs;
deploy.nodes = deploy.nodes =