add a sane.user option which is shorthand for the default user
This commit is contained in:
parent
870afec07e
commit
ee9a2b320d
|
@ -1,13 +1,16 @@
|
||||||
{ config, lib, sane-lib, ... }:
|
{ config, lib, sane-lib, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (lib) mapAttrs' mapAttrsToList mkMerge mkOption types;
|
inherit (builtins) attrValues;
|
||||||
|
inherit (lib) count mapAttrs' mapAttrsToList mkIf mkMerge mkOption types;
|
||||||
|
sane-user-cfg = config.sane.user;
|
||||||
cfg = config.sane.users;
|
cfg = config.sane.users;
|
||||||
path-lib = sane-lib.path;
|
path-lib = sane-lib.path;
|
||||||
userModule = types.submodule {
|
userOptions = {
|
||||||
options = {
|
options = {
|
||||||
fs = mkOption {
|
fs = mkOption {
|
||||||
type = types.attrs;
|
type = types.attrs;
|
||||||
|
default = {};
|
||||||
description = ''
|
description = ''
|
||||||
entries to pass onto `sane.fs` after prepending the user's home-dir to the path.
|
entries to pass onto `sane.fs` after prepending the user's home-dir to the path.
|
||||||
e.g. `sane.users.colin.fs."/.config/aerc" = X`
|
e.g. `sane.users.colin.fs."/.config/aerc" = X`
|
||||||
|
@ -16,6 +19,22 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
userModule = types.submodule ({ config, ... }: {
|
||||||
|
options = {
|
||||||
|
inherit (userOptions) fs;
|
||||||
|
default = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
only one default user may exist.
|
||||||
|
this option determines what the `sane.user` shorthand evaluates to.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# if we're the default user, inherit whatever settings were routed to the default user
|
||||||
|
config = mkIf config.default sane-user-cfg;
|
||||||
|
});
|
||||||
processUser = user: defn: {
|
processUser = user: defn: {
|
||||||
sane.fs = mapAttrs' (path: value: {
|
sane.fs = mapAttrs' (path: value: {
|
||||||
# TODO: query the user's home dir!
|
# TODO: query the user's home dir!
|
||||||
|
@ -36,13 +55,35 @@ in
|
||||||
into the toplevel `sane` options. it's merely a shorthand.
|
into the toplevel `sane` options. it's merely a shorthand.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sane.user = mkOption {
|
||||||
|
type = types.nullOr (types.submodule userOptions);
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
options to pass down to the default user
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
config =
|
config =
|
||||||
let
|
let
|
||||||
configs = mapAttrsToList processUser cfg;
|
configs = mapAttrsToList processUser cfg;
|
||||||
|
num-default-users = count (u: u.default) (attrValues cfg);
|
||||||
take = f: {
|
take = f: {
|
||||||
sane.fs = f.sane.fs;
|
sane.fs = f.sane.fs;
|
||||||
};
|
};
|
||||||
in
|
in mkMerge [
|
||||||
take (sane-lib.mkTypedMerge take configs);
|
(take (sane-lib.mkTypedMerge take configs))
|
||||||
|
{
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = sane-user-cfg == null || num-default-users != 0;
|
||||||
|
message = "cannot set `sane.user` without first setting `sane.users.<user>.default = true` for some user";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
assertion = num-default-users <= 1;
|
||||||
|
message = "cannot set more than one default user";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user