{ config, lib, self, inputs, ... }: let cfg = config.my.user; in { imports = [ inputs.home-manager.nixosModules.home-manager ]; options.my.user = { username = lib.mkOption { type = with lib.types; nullOr str; default = null; }; extraGroups = lib.mkOption { type = with lib.types; listOf str; default = [ ]; }; useDefaultGroups = lib.mkEnableOption null // { default = true; }; homeModule = lib.mkOption { type = with lib.types; nullOr pathInStore; default = null; }; }; config = lib.mkIf (cfg.username != null) { users.users.${cfg.username} = { isNormalUser = true; extraGroups = cfg.extraGroups ++ lib.optionals cfg.useDefaultGroups [ "wheel" "video" "disk" "input" ]; }; home-manager = lib.mkIf (cfg.homeModule != null) { backupFileExtension = "hm-bak"; useUserPackages = true; useGlobalPkgs = true; extraSpecialArgs = {inherit self inputs;}; users.${cfg.username} = _: { imports = [ self.homeManagerModules.default cfg.homeModule ]; home = { inherit (cfg) username; homeDirectory = "/home/${cfg.username}"; }; }; }; }; }