modules/users: refactor to remove inherit
s
This commit is contained in:
parent
3c43fba878
commit
1b4a6207e2
|
@ -1,13 +1,11 @@
|
||||||
{ config, lib, options, sane-lib, utils, ... }:
|
{ config, lib, options, sane-lib, utils, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (builtins) attrValues;
|
|
||||||
inherit (lib) count mapAttrs' mapAttrsToList mkIf mkMerge mkOption types;
|
|
||||||
sane-user-cfg = config.sane.user;
|
sane-user-cfg = config.sane.user;
|
||||||
cfg = config.sane.users;
|
cfg = config.sane.users;
|
||||||
path-lib = sane-lib.path;
|
path-lib = sane-lib.path;
|
||||||
userOptions = {
|
userOptions = {
|
||||||
options = {
|
options = with lib; {
|
||||||
fs = mkOption {
|
fs = mkOption {
|
||||||
# map to listOf attrs so that we can allow multiple assigners to the same path
|
# 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.
|
# 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 // {
|
options = userOptions.options // {
|
||||||
services = mkOption {
|
services = mkOption {
|
||||||
# type = utils.systemdUtils.types.services;
|
# 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 // {
|
options = userOptions.options // {
|
||||||
default = mkOption {
|
default = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
|
@ -92,7 +92,7 @@ let
|
||||||
|
|
||||||
config = lib.mkMerge [
|
config = lib.mkMerge [
|
||||||
# if we're the default user, inherit whatever settings were routed to the default user
|
# 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;
|
inherit (sane-user-cfg) fs persist environment;
|
||||||
services = lib.mapAttrs (_: lib.mkMerge) sane-user-cfg.services;
|
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
|
let
|
||||||
# see: <repo:nixos/nixpkgs:nixos/lib/utils.nix>
|
# see: <repo:nixos/nixpkgs:nixos/lib/utils.nix>
|
||||||
# see: <repo:nix-community/home-manager:modules/systemd.nix>
|
# see: <repo:nix-community/home-manager:modules/systemd.nix>
|
||||||
|
@ -174,7 +174,7 @@ let
|
||||||
});
|
});
|
||||||
processUser = user: defn:
|
processUser = user: defn:
|
||||||
let
|
let
|
||||||
prefixWithHome = mapAttrs' (path: value: {
|
prefixWithHome = lib.mapAttrs' (path: value: {
|
||||||
name = path-lib.concat [ defn.home path ];
|
name = path-lib.concat [ defn.home path ];
|
||||||
inherit value;
|
inherit value;
|
||||||
});
|
});
|
||||||
|
@ -192,7 +192,7 @@ let
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = with lib; {
|
||||||
sane.users = mkOption {
|
sane.users = mkOption {
|
||||||
type = types.attrsOf userModule;
|
type = types.attrsOf userModule;
|
||||||
default = {};
|
default = {};
|
||||||
|
@ -224,14 +224,14 @@ in
|
||||||
};
|
};
|
||||||
config =
|
config =
|
||||||
let
|
let
|
||||||
configs = mapAttrsToList processUser cfg;
|
configs = lib.mapAttrsToList processUser cfg;
|
||||||
num-default-users = count (u: u.default) (attrValues cfg);
|
num-default-users = lib.count (u: u.default) (lib.attrValues cfg);
|
||||||
take = f: {
|
take = f: {
|
||||||
sane.fs = f.sane.fs;
|
sane.fs = f.sane.fs;
|
||||||
sane.persist.sys.byPath = f.sane.persist.sys.byPath;
|
sane.persist.sys.byPath = f.sane.persist.sys.byPath;
|
||||||
sane.defaultUser = f.sane.defaultUser;
|
sane.defaultUser = f.sane.defaultUser;
|
||||||
};
|
};
|
||||||
in mkMerge [
|
in lib.mkMerge [
|
||||||
(take (sane-lib.mkTypedMerge take configs))
|
(take (sane-lib.mkTypedMerge take configs))
|
||||||
{
|
{
|
||||||
assertions = [
|
assertions = [
|
||||||
|
|
Loading…
Reference in New Issue
Block a user