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 {
|
|
|
|
|
specialArgs = { lib = extendedLib; };
|
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;
|
|
|
|
|
};
|
2020-08-27 17:57:56 +00:00
|
|
|
|
})
|
|
|
|
|
];
|
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
|
2019-09-01 19:28:40 +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.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
verbose = mkEnableOption "verbose output on activation";
|
|
|
|
|
|
2019-02-21 07:39:49 +00:00
|
|
|
|
users = mkOption {
|
|
|
|
|
type = types.attrsOf hmModule;
|
|
|
|
|
default = {};
|
|
|
|
|
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);
|
|
|
|
|
};
|
|
|
|
|
}
|