nixos-config/modules/users.nix
Gabriel Arazas db5fc8269e Update user-specific config
Oh no, now I'm content with creating my own framework instead of using
something like digga or flake-utils.
2021-11-29 13:30:57 +08:00

57 lines
1.6 KiB
Nix

# This enables home-manager specific configs and an easier modularization for user-specific configurations.
{ inputs, config, options, lib, ... }:
let
cfg = config.modules.users;
userModules = lib.filesToAttr ../users;
users = lib.attrNames userModules;
nonexistentUsers = lib.filter (name: !lib.elem name users) cfg.users;
mkUser = user: path:
let
defaultConfig = {
home.username = user;
home.homeDirectory = "/home/${user}";
};
in
{
users.users.${user} = {
isNormalUser = true;
extraGroups = [ "wheel" ];
};
home-manager.users.${user} = defaultConfig // import path;
};
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.";
};
};
# FIXME: Recursion error when using `lib.getUsers cfg.users`.
# Time to study how Nix modules really work.
# The assertion is basically enough for this case.
imports = [
# home-manager to enable user-specific config.
inputs.home-manager.nixosModules.home-manager
# The global configuration for the home-manager module.
{
home-manager.useUserPackages = true;
home-manager.useGlobalPkgs = true;
}
] ++ (lib.mapAttrsToList mkUser userModules);
config = {
assertions = [{
assertion = (builtins.length nonexistentUsers) < 1;
message = "${lib.concatMapStringsSep ", " (u: "'${u}'") nonexistentUsers} is not found in the `./users` directory.";
}];
};
}