2022-07-09 05:46:06 +00:00
|
|
|
# This is just a library intended solely for this flake.
|
|
|
|
# It is expected to use the nixpkgs library with `lib/default.nix`.
|
|
|
|
{ lib }:
|
|
|
|
|
|
|
|
rec {
|
2022-07-09 05:54:05 +00:00
|
|
|
mapHomeManagerUser = user: settings:
|
|
|
|
let
|
2022-08-06 05:58:24 +00:00
|
|
|
homeDirectory = "/home/${user}";
|
2022-07-09 05:54:05 +00:00
|
|
|
defaultUserConfig = {
|
|
|
|
extraGroups = [ "wheel" ];
|
|
|
|
createHome = true;
|
2022-08-06 05:58:24 +00:00
|
|
|
home = homeDirectory;
|
2022-07-09 05:54:05 +00:00
|
|
|
};
|
|
|
|
# TODO: Effectively override the option.
|
|
|
|
# We assume all users set with this module are normal users.
|
|
|
|
absoluteOverrides = { isNormalUser = true; };
|
|
|
|
in {
|
2022-08-06 05:58:24 +00:00
|
|
|
home-manager.users."${user}" = { ... }: {
|
2022-09-28 07:14:54 +00:00
|
|
|
imports = [ (getUser "home-manager" user) ];
|
2022-08-06 05:58:24 +00:00
|
|
|
};
|
2022-08-13 00:31:09 +00:00
|
|
|
users.users."${user}" = defaultUserConfig // settings // absoluteOverrides;
|
2022-07-09 05:54:05 +00:00
|
|
|
};
|
|
|
|
|
2022-07-09 05:46:06 +00:00
|
|
|
getSecret = path: ../secrets/${path};
|
|
|
|
|
|
|
|
getUsers = type: users:
|
|
|
|
let
|
|
|
|
userModules = lib.filesToAttr ../users/${type};
|
|
|
|
invalidUsernames = [ "config" "modules" ];
|
|
|
|
|
|
|
|
users' = lib.filterAttrs (n: _: !lib.elem n invalidUsernames && lib.elem n users) userModules;
|
|
|
|
userList = lib.attrNames users';
|
|
|
|
|
|
|
|
nonExistentUsers = lib.filter (name: !lib.elem name userList) users;
|
|
|
|
in lib.trivial.throwIfNot ((lib.length nonExistentUsers) == 0)
|
|
|
|
"there are no users ${lib.concatMapStringsSep ", " (u: "'${u}'") nonExistentUsers} from ${type}"
|
|
|
|
(r: r) users';
|
|
|
|
|
|
|
|
getUser = type: user:
|
|
|
|
lib.getAttr user (getUsers type [ user ]);
|
2022-07-14 00:17:02 +00:00
|
|
|
|
|
|
|
# Import modules with a set blocklist.
|
2022-08-08 10:47:12 +00:00
|
|
|
importModules = attrs: let
|
2022-07-14 00:17:02 +00:00
|
|
|
blocklist = [
|
|
|
|
# The modules under this attribute are often incomplete and needing
|
|
|
|
# very specific requirements that is 99% going to be absent from the
|
|
|
|
# outside so we're not going to export it.
|
|
|
|
"tasks"
|
2022-08-08 10:47:12 +00:00
|
|
|
|
|
|
|
# Profiles are often specific to this project so there's not much point
|
|
|
|
# in exporting these.
|
|
|
|
"profiles"
|
2022-07-14 00:17:02 +00:00
|
|
|
];
|
2022-08-08 10:47:12 +00:00
|
|
|
in
|
2022-07-14 00:17:02 +00:00
|
|
|
lib.filterAttrs (n: v: !lib.elem n blocklist) (lib.mapAttrsRecursive (_: path: import path) attrs);
|
2022-07-09 05:46:06 +00:00
|
|
|
}
|