2021-12-19 09:33:33 +00:00
|
|
|
# This enables home-manager specific configs and an easier modularization for
|
|
|
|
# user-specific configurations. This is specifically for creating a convenient
|
|
|
|
# way to create users from `users/home-manager`.
|
|
|
|
#
|
|
|
|
# If you're looking to create users from `users/nixos`, you can just import
|
|
|
|
# them directly.
|
2021-12-06 10:12:00 +00:00
|
|
|
{ inputs, config, options, lib, ... }:
|
|
|
|
|
|
|
|
let
|
2022-01-09 05:38:59 +00:00
|
|
|
cfg = config.profiles.users;
|
2021-12-19 09:33:33 +00:00
|
|
|
users = lib.attrNames cfg.users;
|
|
|
|
homeManagerUserModules = lib.getUsers "home-manager" users;
|
2022-01-09 05:38:59 +00:00
|
|
|
homeManagerModules = lib.filesToAttr ../../home-manager;
|
2021-12-06 10:12:00 +00:00
|
|
|
|
2021-12-19 09:33:33 +00:00
|
|
|
homeManagerUsers = lib.attrNames homeManagerUserModules;
|
|
|
|
nonexistentUsers = lib.filter (name: !lib.elem name homeManagerUsers) users;
|
2021-12-06 10:12:00 +00:00
|
|
|
|
2021-12-19 09:33:33 +00:00
|
|
|
userOption = { name, config, ... }: {
|
|
|
|
options = {
|
|
|
|
settings = lib.mkOption {
|
|
|
|
type = lib.types.attrs;
|
2022-04-06 02:48:29 +00:00
|
|
|
description = ''
|
|
|
|
Configuration to be merged in <literal>users.users.<name></literal>
|
|
|
|
from NixOS configuration.
|
|
|
|
'';
|
2021-12-19 09:33:33 +00:00
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
uid = 1234;
|
|
|
|
description = "John Doe";
|
|
|
|
extraGroups = [ "wheel" "adbusers" "audio" ];
|
|
|
|
};
|
2021-12-06 10:12:00 +00:00
|
|
|
};
|
|
|
|
};
|
2021-12-19 09:33:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mapUsers = f: lib.mapAttrs f cfg.users;
|
2021-12-06 10:12:00 +00:00
|
|
|
in {
|
2022-01-09 05:38:59 +00:00
|
|
|
options.profiles.users = {
|
2021-12-06 10:12:00 +00:00
|
|
|
users = lib.mkOption {
|
2021-12-19 09:33:33 +00:00
|
|
|
default = { };
|
2021-12-26 08:02:57 +00:00
|
|
|
description = ''
|
2022-04-06 02:48:29 +00:00
|
|
|
A set of users from the <filename>./users/home-manager</filename>
|
|
|
|
directory to be included in the NixOS config. This will also create the
|
|
|
|
appropriate user settings in <literal>users.users</literal> in the
|
|
|
|
NixOS configuration.
|
|
|
|
'';
|
2021-12-19 09:33:33 +00:00
|
|
|
example = {
|
|
|
|
foo-dogsquared.settings = {
|
|
|
|
extraGroups = [ "wheel" "audio" "libvirtd" ];
|
|
|
|
};
|
|
|
|
alice = { };
|
|
|
|
bob = { };
|
|
|
|
};
|
|
|
|
type = with lib.types; attrsOf (submodule userOption);
|
2021-12-06 10:12:00 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-12-19 09:33:33 +00:00
|
|
|
imports = [ inputs.home-manager.nixosModules.home-manager ];
|
2021-12-06 10:12:00 +00:00
|
|
|
|
|
|
|
config = {
|
|
|
|
assertions = [{
|
|
|
|
assertion = (builtins.length nonexistentUsers) < 1;
|
|
|
|
message = "${
|
|
|
|
lib.concatMapStringsSep ", " (u: "'${u}'") nonexistentUsers
|
2021-12-19 09:33:33 +00:00
|
|
|
} is not found in the `./users/home-manager` directory.";
|
2021-12-06 10:12:00 +00:00
|
|
|
}];
|
2021-12-19 09:33:33 +00:00
|
|
|
|
|
|
|
# The global configuration for the home-manager module.
|
|
|
|
home-manager.useUserPackages = true;
|
|
|
|
home-manager.useGlobalPkgs = true;
|
|
|
|
home-manager.sharedModules = lib.modulesToList homeManagerModules;
|
2022-07-05 14:28:03 +00:00
|
|
|
home-manager.extraSpecialArgs = { inherit inputs; };
|
2021-12-19 09:33:33 +00:00
|
|
|
|
|
|
|
# Mapping each users to the respective user configuration.
|
|
|
|
# Setting users for home-manager.
|
|
|
|
home-manager.users = mapUsers (user: _:
|
2021-12-26 08:02:57 +00:00
|
|
|
let homeManagerUserModulePath = lib.getAttr user homeManagerUserModules;
|
|
|
|
in import homeManagerUserModulePath);
|
2021-12-19 09:33:33 +00:00
|
|
|
|
|
|
|
# NixOS users.
|
|
|
|
users.users = mapUsers (user: opts:
|
|
|
|
let
|
|
|
|
defaultUserConfig = {
|
|
|
|
extraGroups = [ "wheel" ];
|
|
|
|
createHome = true;
|
|
|
|
home = "/home/${user}";
|
|
|
|
};
|
|
|
|
# TODO: Effectively override the option.
|
|
|
|
# We assume all users set with this module are normal users.
|
|
|
|
absoluteOverrides = { isNormalUser = true; };
|
|
|
|
in defaultUserConfig // opts.settings // absoluteOverrides);
|
2021-12-06 10:12:00 +00:00
|
|
|
};
|
|
|
|
}
|