2021-11-27 08:04:01 +00:00
|
|
|
{ inputs, config, options, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.modules.users;
|
2021-11-27 11:21:08 +00:00
|
|
|
userModules = lib.filesToAttr ../users;
|
|
|
|
|
|
|
|
users = lib.attrNames userModules;
|
2021-11-27 08:04:01 +00:00
|
|
|
nonexistentUsers = lib.filter (name: !lib.elem name users) cfg.users;
|
2021-11-27 11:21:08 +00:00
|
|
|
validUsers = lib.filterAttrs (n: v: lib.elem n users) userModules;
|
2021-11-27 08:04:01 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.modules.users = {
|
|
|
|
users = lib.mkOption {
|
|
|
|
default = [];
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
description = "A list of users from the `./users` directory to be included in the NixOS config.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-11-27 11:21:08 +00:00
|
|
|
imports = [ inputs.home-manager.nixosModules.home-manager ] ++ (lib.attrValues validUsers);
|
|
|
|
|
|
|
|
config = {
|
|
|
|
assertions = [{
|
|
|
|
assertion = (builtins.length nonexistentUsers) < 1;
|
|
|
|
message = "${lib.concatMapStringsSep ", " (u: "'${u}'") nonexistentUsers} is not found in the `./users` directory.";
|
|
|
|
}];
|
|
|
|
};
|
2021-11-27 08:04:01 +00:00
|
|
|
}
|