2018-04-03 04:53:08 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.home-manager;
|
|
|
|
|
2020-01-16 22:41:14 +00:00
|
|
|
extendedLib = import ../modules/lib/stdlib-extended.nix pkgs.lib;
|
|
|
|
|
|
|
|
hmModule = types.submoduleWith {
|
2021-02-21 17:40:19 +00:00
|
|
|
specialArgs = {
|
|
|
|
lib = extendedLib;
|
2021-02-21 06:02:25 +00:00
|
|
|
darwinConfig = config;
|
2021-10-06 14:32:13 +00:00
|
|
|
osConfig = config;
|
2021-10-08 20:36:41 +00:00
|
|
|
modulesPath = ../modules;
|
2021-02-21 06:02:25 +00:00
|
|
|
} // cfg.extraSpecialArgs;
|
2020-08-27 17:57:56 +00:00
|
|
|
modules = [
|
|
|
|
({ name, ... }: {
|
2020-01-16 22:41:14 +00:00
|
|
|
imports = import ../modules/modules.nix {
|
|
|
|
inherit pkgs;
|
|
|
|
lib = extendedLib;
|
2020-08-27 17:57:56 +00:00
|
|
|
useNixpkgsModule = !cfg.useGlobalPkgs;
|
2020-01-16 22:41:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
submoduleSupport.enable = true;
|
|
|
|
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
|
|
|
|
|
|
|
|
home.username = config.users.users.${name}.name;
|
|
|
|
home.homeDirectory = config.users.users.${name}.home;
|
2022-02-03 20:24:31 +00:00
|
|
|
|
|
|
|
# Make activation script use same version of Nix as system as a whole.
|
|
|
|
# This avoids problems with Nix not being in PATH.
|
|
|
|
home.extraActivationPath = [ config.nix.package ];
|
2020-01-16 22:41:14 +00:00
|
|
|
};
|
2020-08-27 17:57:56 +00:00
|
|
|
})
|
2021-02-21 06:02:25 +00:00
|
|
|
] ++ cfg.sharedModules;
|
2020-01-16 22:41:14 +00:00
|
|
|
};
|
2018-04-03 04:53:08 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
2019-02-21 07:39:49 +00:00
|
|
|
home-manager = {
|
|
|
|
useUserPackages = mkEnableOption ''
|
|
|
|
installation of user packages through the
|
2021-01-18 22:21:32 +00:00
|
|
|
<option>users.users.<name?>.packages</option> option.
|
2018-04-03 04:53:08 +00:00
|
|
|
'';
|
2019-02-21 07:39:49 +00:00
|
|
|
|
2020-08-27 17:57:56 +00:00
|
|
|
useGlobalPkgs = mkEnableOption ''
|
|
|
|
using the system configuration's <literal>pkgs</literal>
|
|
|
|
argument in Home Manager. This disables the Home Manager
|
|
|
|
options <option>nixpkgs.*</option>
|
|
|
|
'';
|
|
|
|
|
|
|
|
backupFileExtension = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "backup";
|
|
|
|
description = ''
|
|
|
|
On activation move existing files by appending the given
|
|
|
|
file extension rather than exiting with an error.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-02-21 06:02:25 +00:00
|
|
|
extraSpecialArgs = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = { };
|
2021-11-01 16:42:22 +00:00
|
|
|
example = literalExpression "{ inherit emacs-overlay; }";
|
2021-02-21 06:02:25 +00:00
|
|
|
description = ''
|
2021-11-01 16:42:22 +00:00
|
|
|
Extra <literal>specialArgs</literal> passed to Home Manager. This
|
|
|
|
option can be used to pass additional arguments to all modules.
|
2021-02-21 06:02:25 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sharedModules = mkOption {
|
2021-03-26 02:01:16 +00:00
|
|
|
type = with types;
|
2021-10-22 21:52:19 +00:00
|
|
|
# TODO: use types.raw once this PR is merged: https://github.com/NixOS/nixpkgs/pull/132448
|
|
|
|
listOf (mkOptionType {
|
|
|
|
name = "submodule";
|
2021-03-26 02:01:16 +00:00
|
|
|
inherit (submodule { }) check;
|
2021-10-22 21:52:19 +00:00
|
|
|
merge = lib.options.mergeOneOption;
|
2021-03-26 02:01:16 +00:00
|
|
|
description = "Home Manager modules";
|
|
|
|
});
|
2021-02-21 06:02:25 +00:00
|
|
|
default = [ ];
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression "[ { home.packages = [ nixpkgs-fmt ]; } ]";
|
2021-02-21 06:02:25 +00:00
|
|
|
description = ''
|
|
|
|
Extra modules added to all users.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-08-27 17:57:56 +00:00
|
|
|
verbose = mkEnableOption "verbose output on activation";
|
|
|
|
|
2019-02-21 07:39:49 +00:00
|
|
|
users = mkOption {
|
|
|
|
type = types.attrsOf hmModule;
|
|
|
|
default = {};
|
2021-01-18 22:21:32 +00:00
|
|
|
# Set as not visible to prevent the entire submodule being included in
|
|
|
|
# the documentation.
|
|
|
|
visible = false;
|
2019-02-21 07:39:49 +00:00
|
|
|
description = ''
|
|
|
|
Per-user Home Manager configuration.
|
|
|
|
'';
|
|
|
|
};
|
2018-04-03 04:53:08 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.users != {}) {
|
2019-08-18 15:37:26 +00:00
|
|
|
warnings =
|
|
|
|
flatten (flip mapAttrsToList cfg.users (user: config:
|
|
|
|
flip map config.warnings (warning:
|
|
|
|
"${user} profile: ${warning}"
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
2019-05-03 14:11:13 +00:00
|
|
|
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: {
|
2020-06-18 22:21:12 +00:00
|
|
|
packages = [ usercfg.home.path ];
|
2019-05-03 14:11:13 +00:00
|
|
|
}) cfg.users
|
|
|
|
);
|
|
|
|
|
2020-06-17 21:33:13 +00:00
|
|
|
environment.pathsToLink = mkIf cfg.useUserPackages [ "/etc/profile.d" ];
|
|
|
|
|
2019-02-19 18:05:47 +00:00
|
|
|
system.activationScripts.postActivation.text =
|
|
|
|
concatStringsSep "\n" (mapAttrsToList (username: usercfg: ''
|
2018-04-03 04:53:08 +00:00
|
|
|
echo Activating home-manager configuration for ${username}
|
2020-08-27 17:57:56 +00:00
|
|
|
sudo -u ${username} -i ${pkgs.writeShellScript "activation-${username}" ''
|
|
|
|
${lib.optionalString (cfg.backupFileExtension != null)
|
|
|
|
"export HOME_MANAGER_BACKUP_EXT=${lib.escapeShellArg cfg.backupFileExtension}"}
|
|
|
|
${lib.optionalString cfg.verbose "export VERBOSE=1"}
|
|
|
|
exec ${usercfg.home.activationPackage}/activate
|
|
|
|
''}
|
2018-04-03 04:53:08 +00:00
|
|
|
'') cfg.users);
|
|
|
|
};
|
|
|
|
}
|