refactor: sane.programs.$foo.service: specify type concretely

This commit is contained in:
Colin 2024-05-30 03:39:32 +00:00
parent f1d397940f
commit 9ba8ff738b
2 changed files with 44 additions and 44 deletions

View File

@ -216,7 +216,7 @@ let
''; '';
}; };
services = mkOption { services = mkOption {
type = types.attrsOf types.anything; # options.sane.users.value.type; type = options.sane.user._options.services.type;
default = {}; default = {};
description = '' description = ''
user services to define if this package is enabled. user services to define if this package is enabled.

View File

@ -108,58 +108,56 @@ let
]; ];
}; };
}); });
userOptions = { userOptions = with lib; {
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. type = types.attrsOf (types.coercedTo types.attrs (a: [ a ]) (types.listOf types.attrs));
type = types.attrsOf (types.coercedTo types.attrs (a: [ a ]) (types.listOf types.attrs)); default = {};
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 and marking them as wanted.
and marking them as wanted. e.g. `sane.users.colin.fs."/.config/aerc" = X`
e.g. `sane.users.colin.fs."/.config/aerc" = X` => `sane.fs."/home/colin/.config/aerc" = { wantedBy = [ "multi-user.target"]; } // X;
=> `sane.fs."/home/colin/.config/aerc" = { wantedBy = [ "multi-user.target"]; } // X;
conventions are similar as to toplevel `sane.fs`. so `sane.users.foo.fs."/"` represents the home directory, conventions are similar as to toplevel `sane.fs`. so `sane.users.foo.fs."/"` represents the home directory,
whereas every other entry is expected to *not* have a trailing slash. whereas every other entry is expected to *not* have a trailing slash.
option merging happens inside `sane.fs`, so `sane.users.colin.fs."foo" = A` and `sane.fs."/home/colin/foo" = B` option merging happens inside `sane.fs`, so `sane.users.colin.fs."foo" = A` and `sane.fs."/home/colin/foo" = B`
behaves identically to `sane.fs."/home/colin/foo" = lib.mkMerge [ A B ]; behaves identically to `sane.fs."/home/colin/foo" = lib.mkMerge [ A B ];
(the unusual signature for this type is how we delay option merging) (the unusual signature for this type is how we delay option merging)
''; '';
}; };
persist = mkOption { persist = mkOption {
type = options.sane.persist.sys.type; type = options.sane.persist.sys.type;
default = {}; default = {};
description = '' description = ''
entries to pass onto `sane.persist.sys` after prepending the user's home-dir to the path. entries to pass onto `sane.persist.sys` after prepending the user's home-dir to the path.
''; '';
}; };
environment = mkOption { environment = mkOption {
type = types.attrsOf types.str; type = types.attrsOf types.str;
default = {}; default = {};
description = '' description = ''
environment variables to place in user's shell profile. environment variables to place in user's shell profile.
these end up in ~/.profile these end up in ~/.profile
''; '';
}; };
services = mkOption { services = mkOption {
type = types.attrsOf serviceType; type = types.attrsOf serviceType;
default = {}; default = {};
description = '' description = ''
services to define for this user. services to define for this user.
''; '';
};
}; };
}; };
userModule = let userModule = let
nixConfig = config; nixConfig = config;
in with lib; types.submodule ({ name, config, ... }: { in with lib; types.submodule ({ name, config, ... }: {
options = userOptions.options // { options = userOptions// {
default = mkOption { default = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
@ -335,11 +333,13 @@ in
}; };
sane.user = mkOption { sane.user = mkOption {
type = types.nullOr (types.submodule userOptions); type = types.nullOr (types.submodule { options = userOptions; });
default = null; default = null;
description = '' description = ''
options to pass down to the default user options to pass down to the default user
''; '';
} // {
_options = userOptions;
}; };
sane.defaultUser = mkOption { sane.defaultUser = mkOption {