2018-04-03 06:53:08 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.home-manager;
|
|
|
|
|
2020-01-16 23:41:14 +01:00
|
|
|
extendedLib = import ../modules/lib/stdlib-extended.nix pkgs.lib;
|
|
|
|
|
|
|
|
hmModule = types.submoduleWith {
|
2021-02-21 18:40:19 +01:00
|
|
|
specialArgs = {
|
|
|
|
lib = extendedLib;
|
2021-02-21 07:02:25 +01:00
|
|
|
darwinConfig = config;
|
2021-10-06 16:32:13 +02:00
|
|
|
osConfig = config;
|
2021-10-08 22:36:41 +02:00
|
|
|
modulesPath = ../modules;
|
2021-02-21 07:02:25 +01:00
|
|
|
} // cfg.extraSpecialArgs;
|
2020-08-27 19:57:56 +02:00
|
|
|
modules = [
|
|
|
|
({ name, ... }: {
|
2020-01-16 23:41:14 +01:00
|
|
|
imports = import ../modules/modules.nix {
|
|
|
|
inherit pkgs;
|
|
|
|
lib = extendedLib;
|
2020-08-27 19:57:56 +02:00
|
|
|
useNixpkgsModule = !cfg.useGlobalPkgs;
|
2020-01-16 23:41:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
submoduleSupport.enable = true;
|
|
|
|
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
|
|
|
|
|
|
|
|
home.username = config.users.users.${name}.name;
|
|
|
|
home.homeDirectory = config.users.users.${name}.home;
|
|
|
|
};
|
2020-08-27 19:57:56 +02:00
|
|
|
})
|
2021-02-21 07:02:25 +01:00
|
|
|
] ++ cfg.sharedModules;
|
2020-01-16 23:41:14 +01:00
|
|
|
};
|
2018-04-03 06:53:08 +02:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
2019-02-21 08:39:49 +01:00
|
|
|
home-manager = {
|
|
|
|
useUserPackages = mkEnableOption ''
|
|
|
|
installation of user packages through the
|
2021-01-18 23:21:32 +01:00
|
|
|
<option>users.users.<name?>.packages</option> option.
|
2018-04-03 06:53:08 +02:00
|
|
|
'';
|
2019-02-21 08:39:49 +01:00
|
|
|
|
2020-08-27 19:57:56 +02: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 07:02:25 +01:00
|
|
|
extraSpecialArgs = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
Extra <literal>specialArgs</literal> passed to Home Manager.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sharedModules = mkOption {
|
2021-03-26 03:01:16 +01:00
|
|
|
type = with types;
|
|
|
|
listOf (anything // {
|
|
|
|
inherit (submodule { }) check;
|
|
|
|
description = "Home Manager modules";
|
|
|
|
});
|
2021-02-21 07:02:25 +01:00
|
|
|
default = [ ];
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression "[ { home.packages = [ nixpkgs-fmt ]; } ]";
|
2021-02-21 07:02:25 +01:00
|
|
|
description = ''
|
|
|
|
Extra modules added to all users.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-08-27 19:57:56 +02:00
|
|
|
verbose = mkEnableOption "verbose output on activation";
|
|
|
|
|
2019-02-21 08:39:49 +01:00
|
|
|
users = mkOption {
|
|
|
|
type = types.attrsOf hmModule;
|
|
|
|
default = {};
|
2021-01-18 23:21:32 +01:00
|
|
|
# Set as not visible to prevent the entire submodule being included in
|
|
|
|
# the documentation.
|
|
|
|
visible = false;
|
2019-02-21 08:39:49 +01:00
|
|
|
description = ''
|
|
|
|
Per-user Home Manager configuration.
|
|
|
|
'';
|
|
|
|
};
|
2018-04-03 06:53:08 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.users != {}) {
|
2019-08-18 17:37:26 +02:00
|
|
|
warnings =
|
|
|
|
flatten (flip mapAttrsToList cfg.users (user: config:
|
|
|
|
flip map config.warnings (warning:
|
|
|
|
"${user} profile: ${warning}"
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
2019-05-03 16:11:13 +02: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-19 00:21:12 +02:00
|
|
|
packages = [ usercfg.home.path ];
|
2019-05-03 16:11:13 +02:00
|
|
|
}) cfg.users
|
|
|
|
);
|
|
|
|
|
2020-06-17 23:33:13 +02:00
|
|
|
environment.pathsToLink = mkIf cfg.useUserPackages [ "/etc/profile.d" ];
|
|
|
|
|
2019-02-19 19:05:47 +01:00
|
|
|
system.activationScripts.postActivation.text =
|
|
|
|
concatStringsSep "\n" (mapAttrsToList (username: usercfg: ''
|
2018-04-03 06:53:08 +02:00
|
|
|
echo Activating home-manager configuration for ${username}
|
2020-08-27 19:57:56 +02: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 06:53:08 +02:00
|
|
|
'') cfg.users);
|
|
|
|
};
|
|
|
|
}
|