2022-06-07 18:45:06 +00:00
|
|
|
# This module is the common base for the NixOS and nix-darwin modules.
|
|
|
|
# For OS-specific configuration, please edit nixos/default.nix or nix-darwin/default.nix instead.
|
|
|
|
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.home-manager;
|
|
|
|
|
2023-04-26 19:03:06 +00:00
|
|
|
extendedLib = import ../modules/lib/stdlib-extended.nix lib;
|
2022-06-07 18:45:06 +00:00
|
|
|
|
2022-06-10 09:13:27 +00:00
|
|
|
hmModule = types.submoduleWith {
|
|
|
|
description = "Home Manager module";
|
2022-06-07 18:45:06 +00:00
|
|
|
specialArgs = {
|
|
|
|
lib = extendedLib;
|
|
|
|
osConfig = config;
|
2022-06-16 10:26:57 +00:00
|
|
|
modulesPath = builtins.toString ../modules;
|
2022-06-07 18:45:06 +00:00
|
|
|
} // cfg.extraSpecialArgs;
|
|
|
|
modules = [
|
|
|
|
({ name, ... }: {
|
2022-06-16 10:26:57 +00:00
|
|
|
imports = import ../modules/modules.nix {
|
2022-06-07 18:45:06 +00:00
|
|
|
inherit pkgs;
|
|
|
|
lib = extendedLib;
|
|
|
|
useNixpkgsModule = !cfg.useGlobalPkgs;
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
submoduleSupport.enable = true;
|
|
|
|
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
|
|
|
|
|
|
|
|
home.username = config.users.users.${name}.name;
|
|
|
|
home.homeDirectory = config.users.users.${name}.home;
|
|
|
|
|
|
|
|
# Make activation script use same version of Nix as system as a whole.
|
|
|
|
# This avoids problems with Nix not being in PATH.
|
2022-11-03 14:00:29 +00:00
|
|
|
nix.package = config.nix.package;
|
2022-06-07 18:45:06 +00:00
|
|
|
};
|
|
|
|
})
|
|
|
|
] ++ cfg.sharedModules;
|
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
|
|
|
options.home-manager = {
|
2023-06-30 22:35:51 +00:00
|
|
|
useUserPackages = mkEnableOption (mdDoc ''
|
2022-06-07 18:45:06 +00:00
|
|
|
installation of user packages through the
|
2023-06-30 22:35:51 +00:00
|
|
|
{option}`users.users.<name>.packages` option'');
|
2022-06-07 18:45:06 +00:00
|
|
|
|
2023-06-30 22:35:51 +00:00
|
|
|
useGlobalPkgs = mkEnableOption (mdDoc ''
|
|
|
|
using the system configuration's `pkgs`
|
2022-06-07 18:45:06 +00:00
|
|
|
argument in Home Manager. This disables the Home Manager
|
2023-06-30 22:35:51 +00:00
|
|
|
options {option}`nixpkgs.*`'');
|
2022-06-07 18:45:06 +00:00
|
|
|
|
|
|
|
backupFileExtension = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "backup";
|
2023-06-30 22:35:51 +00:00
|
|
|
description = mdDoc ''
|
2022-06-07 18:45:06 +00:00
|
|
|
On activation move existing files by appending the given
|
|
|
|
file extension rather than exiting with an error.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraSpecialArgs = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = { };
|
|
|
|
example = literalExpression "{ inherit emacs-overlay; }";
|
2023-06-30 22:35:51 +00:00
|
|
|
description = mdDoc ''
|
|
|
|
Extra `specialArgs` passed to Home Manager. This
|
2022-06-07 18:45:06 +00:00
|
|
|
option can be used to pass additional arguments to all modules.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sharedModules = mkOption {
|
|
|
|
type = with types; listOf raw;
|
|
|
|
default = [ ];
|
|
|
|
example = literalExpression "[ { home.packages = [ nixpkgs-fmt ]; } ]";
|
2023-06-30 22:35:51 +00:00
|
|
|
description = mdDoc ''
|
2022-06-07 18:45:06 +00:00
|
|
|
Extra modules added to all users.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-06-30 23:30:13 +00:00
|
|
|
verbose = mkEnableOption (lib.mdDoc "verbose output on activation");
|
2022-06-07 18:45:06 +00:00
|
|
|
|
|
|
|
users = mkOption {
|
|
|
|
type = types.attrsOf hmModule;
|
|
|
|
default = { };
|
|
|
|
# Prevent the entire submodule being included in the documentation.
|
|
|
|
visible = "shallow";
|
2023-06-30 22:35:51 +00:00
|
|
|
description = mdDoc ''
|
2022-06-07 18:45:06 +00:00
|
|
|
Per-user Home Manager configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.users != { }) {
|
|
|
|
warnings = flatten (flip mapAttrsToList cfg.users (user: config:
|
|
|
|
flip map config.warnings (warning: "${user} profile: ${warning}")));
|
|
|
|
|
|
|
|
assertions = flatten (flip mapAttrsToList cfg.users (user: config:
|
|
|
|
flip map config.assertions (assertion: {
|
|
|
|
inherit (assertion) assertion;
|
|
|
|
message = "${user} profile: ${assertion.message}";
|
|
|
|
})));
|
|
|
|
|
|
|
|
users.users = mkIf cfg.useUserPackages
|
|
|
|
(mapAttrs (username: usercfg: { packages = [ usercfg.home.path ]; })
|
|
|
|
cfg.users);
|
|
|
|
|
|
|
|
environment.pathsToLink = mkIf cfg.useUserPackages [ "/etc/profile.d" ];
|
|
|
|
};
|
|
|
|
}
|