From 1b4a6207e20dfc1828560b66f01b4f6d687de7af Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 16 Mar 2024 04:58:21 +0000 Subject: [PATCH] modules/users: refactor to remove `inherit`s --- modules/users.nix | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/users.nix b/modules/users.nix index 20ee43ee..39eb03b0 100644 --- a/modules/users.nix +++ b/modules/users.nix @@ -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: # see: @@ -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 = [