modules/users: refactor to remove `inherit`s

This commit is contained in:
Colin 2024-03-16 04:58:21 +00:00
parent 3c43fba878
commit 1b4a6207e2
1 changed files with 12 additions and 12 deletions

View File

@ -1,13 +1,11 @@
{ config, lib, options, sane-lib, utils, ... }:
let
inherit (builtins) attrValues;
inherit (lib) count mapAttrs' mapAttrsToList mkIf mkMerge mkOption types;
sane-user-cfg = config.sane.user;
cfg = config.sane.users;
path-lib = sane-lib.path;
userOptions = {
options = {
options = with lib; {
fs = mkOption {
# map to listOf attrs so that we can allow multiple assigners to the same path
# w/o worrying about merging at this layer, and defer merging to modules/fs instead.
@ -59,7 +57,7 @@ let
};
};
};
defaultUserOptions = {
defaultUserOptions = with lib; {
options = userOptions.options // {
services = mkOption {
# type = utils.systemdUtils.types.services;
@ -71,7 +69,9 @@ let
};
};
};
userModule = let nixConfig = config; in types.submodule ({ name, config, ... }: {
userModule = let
nixConfig = config;
in with lib; types.submodule ({ name, config, ... }: {
options = userOptions.options // {
default = mkOption {
type = types.bool;
@ -92,7 +92,7 @@ let
config = lib.mkMerge [
# if we're the default user, inherit whatever settings were routed to the default user
(mkIf config.default {
(lib.mkIf config.default {
inherit (sane-user-cfg) fs persist environment;
services = lib.mapAttrs (_: lib.mkMerge) sane-user-cfg.services;
})
@ -127,7 +127,7 @@ let
'';
}
{
fs = lib.mkMerge (mapAttrsToList (serviceName: value:
fs = lib.mkMerge (lib.mapAttrsToList (serviceName: value:
let
# see: <repo:nixos/nixpkgs:nixos/lib/utils.nix>
# see: <repo:nix-community/home-manager:modules/systemd.nix>
@ -174,7 +174,7 @@ let
});
processUser = user: defn:
let
prefixWithHome = mapAttrs' (path: value: {
prefixWithHome = lib.mapAttrs' (path: value: {
name = path-lib.concat [ defn.home path ];
inherit value;
});
@ -192,7 +192,7 @@ let
};
in
{
options = {
options = with lib; {
sane.users = mkOption {
type = types.attrsOf userModule;
default = {};
@ -224,14 +224,14 @@ in
};
config =
let
configs = mapAttrsToList processUser cfg;
num-default-users = count (u: u.default) (attrValues cfg);
configs = lib.mapAttrsToList processUser cfg;
num-default-users = lib.count (u: u.default) (lib.attrValues cfg);
take = f: {
sane.fs = f.sane.fs;
sane.persist.sys.byPath = f.sane.persist.sys.byPath;
sane.defaultUser = f.sane.defaultUser;
};
in mkMerge [
in lib.mkMerge [
(take (sane-lib.mkTypedMerge take configs))
{
assertions = [