2022-06-07 20:45:06 +02: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 21:03:06 +02:00
|
|
|
extendedLib = import ../modules/lib/stdlib-extended.nix lib;
|
2022-06-07 20:45:06 +02:00
|
|
|
|
2022-06-10 11:13:27 +02:00
|
|
|
hmModule = types.submoduleWith {
|
|
|
|
description = "Home Manager module";
|
2024-04-26 22:02:25 +02:00
|
|
|
class = "homeManager";
|
2022-06-07 20:45:06 +02:00
|
|
|
specialArgs = {
|
|
|
|
lib = extendedLib;
|
|
|
|
osConfig = config;
|
2022-06-16 12:26:57 +02:00
|
|
|
modulesPath = builtins.toString ../modules;
|
2022-06-07 20:45:06 +02:00
|
|
|
} // cfg.extraSpecialArgs;
|
|
|
|
modules = [
|
|
|
|
({ name, ... }: {
|
2022-06-16 12:26:57 +02:00
|
|
|
imports = import ../modules/modules.nix {
|
2022-06-07 20:45:06 +02: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 15:00:29 +01:00
|
|
|
nix.package = config.nix.package;
|
2022-06-07 20:45:06 +02:00
|
|
|
};
|
|
|
|
})
|
|
|
|
] ++ cfg.sharedModules;
|
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
|
|
|
options.home-manager = {
|
2023-07-02 01:45:18 +02:00
|
|
|
useUserPackages = mkEnableOption ''
|
2022-06-07 20:45:06 +02:00
|
|
|
installation of user packages through the
|
2023-07-02 01:45:18 +02:00
|
|
|
{option}`users.users.<name>.packages` option'';
|
2022-06-07 20:45:06 +02:00
|
|
|
|
2023-07-02 01:45:18 +02:00
|
|
|
useGlobalPkgs = mkEnableOption ''
|
2023-07-01 00:35:51 +02:00
|
|
|
using the system configuration's `pkgs`
|
2022-06-07 20:45:06 +02:00
|
|
|
argument in Home Manager. This disables the Home Manager
|
2023-07-02 01:45:18 +02:00
|
|
|
options {option}`nixpkgs.*`'';
|
2022-06-07 20:45:06 +02:00
|
|
|
|
|
|
|
backupFileExtension = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "backup";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-06-07 20:45:06 +02: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-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 00:35:51 +02:00
|
|
|
Extra `specialArgs` passed to Home Manager. This
|
2022-06-07 20:45:06 +02: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-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-06-07 20:45:06 +02:00
|
|
|
Extra modules added to all users.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-07-02 01:45:18 +02:00
|
|
|
verbose = mkEnableOption "verbose output on activation";
|
2022-06-07 20:45:06 +02:00
|
|
|
|
|
|
|
users = mkOption {
|
|
|
|
type = types.attrsOf hmModule;
|
|
|
|
default = { };
|
|
|
|
# Prevent the entire submodule being included in the documentation.
|
|
|
|
visible = "shallow";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-06-07 20:45:06 +02:00
|
|
|
Per-user Home Manager configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-08-21 21:55:03 +02:00
|
|
|
config = (mkMerge [
|
|
|
|
# Fix potential recursion when configuring home-manager users based on values in users.users #594
|
|
|
|
(mkIf (cfg.useUserPackages && cfg.users != { }) {
|
|
|
|
users.users =
|
|
|
|
(mapAttrs (username: usercfg: { packages = [ usercfg.home.path ]; })
|
|
|
|
cfg.users);
|
|
|
|
environment.pathsToLink = [ "/etc/profile.d" ];
|
|
|
|
})
|
|
|
|
(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}";
|
|
|
|
})));
|
|
|
|
})
|
|
|
|
]);
|
2022-06-07 20:45:06 +02:00
|
|
|
}
|