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-12-10 10:47:34 +00:00
|
|
|
# This is only used for home-manager users without a NixOS user counterpart.
|
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 = {
|
2022-11-26 02:53:42 +00:00
|
|
|
extraGroups = lib.mkDefault [ "wheel" ];
|
|
|
|
createHome = lib.mkDefault true;
|
|
|
|
home = lib.mkDefault homeDirectory;
|
|
|
|
isNormalUser = lib.mkForce true;
|
2022-07-09 05:54:05 +00:00
|
|
|
};
|
2022-11-19 03:05:31 +00:00
|
|
|
in
|
2023-10-03 13:33:16 +00:00
|
|
|
({ lib, ... }: {
|
2022-08-06 05:58:24 +00:00
|
|
|
home-manager.users."${user}" = { ... }: {
|
2023-10-28 04:23:24 +00:00
|
|
|
imports = [
|
|
|
|
{
|
|
|
|
home.username = user;
|
|
|
|
home.homeDirectory = homeDirectory;
|
|
|
|
}
|
|
|
|
|
|
|
|
(getUser "home-manager" user)
|
|
|
|
];
|
2022-08-06 05:58:24 +00:00
|
|
|
};
|
2023-10-03 13:33:16 +00:00
|
|
|
|
|
|
|
users.users."${user}" = lib.mkMerge [
|
|
|
|
defaultUserConfig
|
|
|
|
settings
|
|
|
|
];
|
|
|
|
});
|
2022-07-09 05:54:05 +00:00
|
|
|
|
2022-07-09 05:46:06 +00:00
|
|
|
getSecret = path: ../secrets/${path};
|
|
|
|
|
2023-07-28 00:30:12 +00:00
|
|
|
isInternal = config: config ? _isfoodogsquaredcustom && config._isfoodogsquaredcustom;
|
2023-07-09 04:02:03 +00:00
|
|
|
|
2022-07-09 05:46:06 +00:00
|
|
|
getUsers = type: users:
|
|
|
|
let
|
|
|
|
userModules = lib.filesToAttr ../users/${type};
|
|
|
|
invalidUsernames = [ "config" "modules" ];
|
|
|
|
|
2023-10-07 19:29:38 +00:00
|
|
|
users' = lib.removeAttrs userModules invalidUsernames;
|
2022-07-09 05:46:06 +00:00
|
|
|
userList = lib.attrNames users';
|
|
|
|
|
|
|
|
nonExistentUsers = lib.filter (name: !lib.elem name userList) users;
|
2022-11-19 03:05:31 +00:00
|
|
|
in
|
|
|
|
lib.trivial.throwIfNot ((lib.length nonExistentUsers) == 0)
|
2022-07-09 05:46:06 +00:00
|
|
|
"there are no users ${lib.concatMapStringsSep ", " (u: "'${u}'") nonExistentUsers} from ${type}"
|
2022-11-19 03:05:31 +00:00
|
|
|
(r: r)
|
|
|
|
users';
|
2022-07-09 05:46:06 +00:00
|
|
|
|
2023-10-09 12:48:01 +00:00
|
|
|
getUser = type: user: ../users/${type}/${user};
|
2022-07-14 00:17:02 +00:00
|
|
|
|
|
|
|
# Import modules with a set blocklist.
|
2022-11-19 03:05:31 +00:00
|
|
|
importModules = attrs:
|
|
|
|
let
|
|
|
|
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"
|
|
|
|
|
|
|
|
# Profiles are often specific to this project so there's not much point
|
|
|
|
# in exporting these.
|
|
|
|
"profiles"
|
|
|
|
];
|
|
|
|
in
|
2023-09-26 14:32:57 +00:00
|
|
|
lib.attrsets.removeAttrs (lib.mapAttrsRecursive (_: sopsFile: import sopsFile) attrs) blocklist;
|
2022-07-09 05:46:06 +00:00
|
|
|
}
|