mirror of
https://github.com/nix-community/home-manager.git
synced 2025-04-09 18:44:14 +00:00
nixos/common: per-user useUserPackages
option
to permit enabling this feature for users specified in `home-manager.users` that have a corresponding entry in `users.users` while still supporting users that do not.
This commit is contained in:
parent
4d627110a4
commit
61c4772096
3 changed files with 48 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
{ config, lib, pkgs, ... }@args:
|
||||
|
||||
let
|
||||
inherit (lib) literalExpression mkOption types;
|
||||
|
@ -500,6 +500,21 @@ in
|
|||
Whether to make programs use XDG directories whenever supported.
|
||||
'';
|
||||
};
|
||||
|
||||
home.useUserPackages = mkOption {
|
||||
type = types.bool;
|
||||
default = args.nixosConfig.home-manager.useUserPackages or false;
|
||||
defaultText = lib.literalExpression "home-manager.useUserPackages";
|
||||
description = ''
|
||||
Enable installation of user packages through the
|
||||
{option}`users.users.<name>.packages` option.
|
||||
|
||||
::: {.warning}
|
||||
This option is specific to NixOS configurations and has no effect
|
||||
elsewhere.
|
||||
:::
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
|
@ -521,6 +536,7 @@ in
|
|||
releaseMismatch =
|
||||
config.home.enableNixpkgsReleaseCheck
|
||||
&& hmRelease != nixpkgsRelease;
|
||||
wronglyUsingUserPackages = cfg.useUserPackages && (!(args ? nixosConfig));
|
||||
in
|
||||
lib.optional releaseMismatch ''
|
||||
You are using
|
||||
|
@ -537,7 +553,11 @@ in
|
|||
home.enableNixpkgsReleaseCheck = false;
|
||||
|
||||
to your configuration.
|
||||
'';
|
||||
''
|
||||
++ lib.optional wronglyUsingUserPackages
|
||||
"You have enabled `home.useUserPackages`, but this option has no effect outside of NixOS configurations.";
|
||||
|
||||
|
||||
|
||||
home.username =
|
||||
lib.mkIf (lib.versionOlder config.home.stateVersion "20.09")
|
||||
|
|
|
@ -10,6 +10,10 @@ let
|
|||
|
||||
extendedLib = import ../modules/lib/stdlib-extended.nix lib;
|
||||
|
||||
usersUsingUserPackages =
|
||||
lib.filterAttrs (_username: usercfg: usercfg.home.useUserPackages)
|
||||
cfg.users;
|
||||
|
||||
# `defaultOverridePriority` (and its legacy counterpart `defaultPriority`)
|
||||
# represents the priority of option definitions that do not explicity specify
|
||||
# a priority; that is, definitions of the form `{ foo = "bar"; }`.
|
||||
|
@ -36,7 +40,7 @@ let
|
|||
modulesPath = builtins.toString ../modules;
|
||||
} // cfg.extraSpecialArgs;
|
||||
modules = [
|
||||
({ name, ... }: {
|
||||
({ name, ... }@usercfg: {
|
||||
imports = import ../modules/modules.nix {
|
||||
inherit pkgs;
|
||||
lib = extendedLib;
|
||||
|
@ -45,7 +49,8 @@ let
|
|||
|
||||
config = {
|
||||
submoduleSupport.enable = true;
|
||||
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
|
||||
submoduleSupport.externalPackageInstall =
|
||||
usercfg.config.home.useUserPackages;
|
||||
|
||||
home.username = mkUserDefault config.users.users.${name}.name;
|
||||
home.homeDirectory = mkUserDefault config.users.users.${name}.home;
|
||||
|
@ -69,8 +74,8 @@ let
|
|||
in {
|
||||
options.home-manager = {
|
||||
useUserPackages = mkEnableOption ''
|
||||
installation of user packages through the
|
||||
{option}`users.users.<name>.packages` option'';
|
||||
the per-user option {option}`home-manager.users.<name>.useUserPackages`
|
||||
by default'';
|
||||
|
||||
useGlobalPkgs = mkEnableOption ''
|
||||
using the system configuration's `pkgs`
|
||||
|
@ -121,10 +126,10 @@ in {
|
|||
};
|
||||
|
||||
config = (lib.mkMerge [
|
||||
# Fix potential recursion when configuring home-manager users based on values in users.users #594
|
||||
(mkIf (cfg.useUserPackages && cfg.users != { }) {
|
||||
(mkIf (usersUsingUserPackages != { }) {
|
||||
users.users = (lib.mapAttrs
|
||||
(_username: usercfg: { packages = [ usercfg.home.path ]; }) cfg.users);
|
||||
(_username: usercfg: { packages = [ usercfg.home.path ]; })
|
||||
usersUsingUserPackages);
|
||||
environment.pathsToLink = [ "/etc/profile.d" ];
|
||||
})
|
||||
(mkIf (cfg.users != { }) {
|
||||
|
|
|
@ -16,19 +16,22 @@ in {
|
|||
home-manager = {
|
||||
extraSpecialArgs.nixosConfig = config;
|
||||
|
||||
sharedModules = [{
|
||||
key = "home-manager#nixos-shared-module";
|
||||
sharedModules = [
|
||||
({ ... }@usercfg: {
|
||||
key = "home-manager#nixos-shared-module";
|
||||
|
||||
config = {
|
||||
# The per-user directory inside /etc/profiles is not known by
|
||||
# fontconfig by default.
|
||||
fonts.fontconfig.enable = lib.mkDefault
|
||||
(cfg.useUserPackages && config.fonts.fontconfig.enable);
|
||||
config = {
|
||||
# The per-user directory inside /etc/profiles is not known by
|
||||
# fontconfig by default.
|
||||
fonts.fontconfig.enable = lib.mkDefault
|
||||
(usercfg.config.home.useUserPackages != { }
|
||||
&& config.fonts.fontconfig.enable);
|
||||
|
||||
# Inherit glibcLocales setting from NixOS.
|
||||
i18n.glibcLocales = lib.mkDefault config.i18n.glibcLocales;
|
||||
};
|
||||
}];
|
||||
# Inherit glibcLocales setting from NixOS.
|
||||
i18n.glibcLocales = lib.mkDefault config.i18n.glibcLocales;
|
||||
};
|
||||
})
|
||||
];
|
||||
};
|
||||
}
|
||||
(lib.mkIf (cfg.users != { }) {
|
||||
|
|
Loading…
Add table
Reference in a new issue