1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 11:36:05 +01:00

treewide: reformat nixfmt-rfc-style

Reformat repository using new nixfmt-rfc-style.
This commit is contained in:
Austin Horstman 2025-04-07 16:11:29 -05:00
parent 5df48c4255
commit cba2f9ce95
1051 changed files with 37028 additions and 26594 deletions

View file

@ -1,10 +1,22 @@
# 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.
{ options, config, lib, pkgs, ... }:
{
options,
config,
lib,
pkgs,
...
}:
let
inherit (lib) flip mkOption mkEnableOption mkIf types;
inherit (lib)
flip
mkOption
mkEnableOption
mkIf
types
;
cfg = config.home-manager;
@ -19,37 +31,40 @@ let
modulesPath = builtins.toString ../modules;
} // cfg.extraSpecialArgs;
modules = [
({ name, ... }: {
imports = import ../modules/modules.nix {
inherit pkgs;
lib = extendedLib;
useNixpkgsModule = !cfg.useGlobalPkgs;
};
(
{ name, ... }:
{
imports = import ../modules/modules.nix {
inherit pkgs;
lib = extendedLib;
useNixpkgsModule = !cfg.useGlobalPkgs;
};
config = {
submoduleSupport.enable = true;
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
config = {
submoduleSupport.enable = true;
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
home.username = config.users.users.${name}.name;
home.homeDirectory = config.users.users.${name}.home;
home.username = config.users.users.${name}.name;
home.homeDirectory = config.users.users.${name}.home;
# Forward `nix.enable` from the OS configuration. The
# conditional is to check whether nix-darwin is new enough
# to have the `nix.enable` option; it was previously a
# `mkRemovedOptionModule` error, which we can crudely detect
# by `visible` being set to `false`.
nix.enable =
mkIf (options.nix.enable.visible or true) config.nix.enable;
# Forward `nix.enable` from the OS configuration. The
# conditional is to check whether nix-darwin is new enough
# to have the `nix.enable` option; it was previously a
# `mkRemovedOptionModule` error, which we can crudely detect
# by `visible` being set to `false`.
nix.enable = mkIf (options.nix.enable.visible or true) config.nix.enable;
# Make activation script use same version of Nix as system as a whole.
# This avoids problems with Nix not being in PATH.
nix.package = config.nix.package;
};
})
# Make activation script use same version of Nix as system as a whole.
# This avoids problems with Nix not being in PATH.
nix.package = config.nix.package;
};
}
)
] ++ cfg.sharedModules;
};
in {
in
{
options.home-manager = {
useUserPackages = mkEnableOption ''
installation of user packages through the
@ -83,8 +98,7 @@ in {
sharedModules = mkOption {
type = with types; listOf raw;
default = [ ];
example =
lib.literalExpression "[ { home.packages = [ nixpkgs-fmt ]; } ]";
example = lib.literalExpression "[ { home.packages = [ nixpkgs-fmt ]; } ]";
description = ''
Extra modules added to all users.
'';
@ -103,22 +117,30 @@ in {
};
};
config = (lib.mkMerge [
# Fix potential recursion when configuring home-manager users based on values in users.users #594
(mkIf (cfg.useUserPackages && cfg.users != { }) {
users.users = (lib.mapAttrs
(_username: usercfg: { packages = [ usercfg.home.path ]; }) cfg.users);
environment.pathsToLink = [ "/etc/profile.d" ];
})
(mkIf (cfg.users != { }) {
warnings = lib.flatten (flip lib.mapAttrsToList cfg.users (user: config:
flip map config.warnings (warning: "${user} profile: ${warning}")));
config = (
lib.mkMerge [
# Fix potential recursion when configuring home-manager users based on values in users.users #594
(mkIf (cfg.useUserPackages && cfg.users != { }) {
users.users = (lib.mapAttrs (_username: usercfg: { packages = [ usercfg.home.path ]; }) cfg.users);
environment.pathsToLink = [ "/etc/profile.d" ];
})
(mkIf (cfg.users != { }) {
warnings = lib.flatten (
flip lib.mapAttrsToList cfg.users (
user: config: flip map config.warnings (warning: "${user} profile: ${warning}")
)
);
assertions = lib.flatten (flip lib.mapAttrsToList cfg.users (user: config:
flip map config.assertions (assertion: {
inherit (assertion) assertion;
message = "${user} profile: ${assertion.message}";
})));
})
]);
assertions = lib.flatten (
flip lib.mapAttrsToList cfg.users (
user: config:
flip map config.assertions (assertion: {
inherit (assertion) assertion;
message = "${user} profile: ${assertion.message}";
})
)
);
})
]
);
}

View file

@ -1,14 +1,23 @@
{ config, lib, pkgs, utils, ... }:
{
config,
lib,
pkgs,
utils,
...
}:
let
cfg = config.home-manager;
serviceEnvironment = lib.optionalAttrs (cfg.backupFileExtension != null) {
HOME_MANAGER_BACKUP_EXT = cfg.backupFileExtension;
} // lib.optionalAttrs cfg.verbose { VERBOSE = "1"; };
serviceEnvironment =
lib.optionalAttrs (cfg.backupFileExtension != null) {
HOME_MANAGER_BACKUP_EXT = cfg.backupFileExtension;
}
// lib.optionalAttrs cfg.verbose { VERBOSE = "1"; };
in {
in
{
imports = [ ./common.nix ];
config = lib.mkMerge [
@ -16,26 +25,29 @@ in {
home-manager = {
extraSpecialArgs.nixosConfig = config;
sharedModules = [{
key = "home-manager#nixos-shared-module";
sharedModules = [
{
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 (cfg.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 != { }) {
systemd.services = lib.mapAttrs' (_: usercfg:
let username = usercfg.home.username;
in lib.nameValuePair
"home-manager-${utils.escapeSystemdPath username}" {
systemd.services = lib.mapAttrs' (
_: usercfg:
let
username = usercfg.home.username;
in
lib.nameValuePair "home-manager-${utils.escapeSystemdPath username}" {
description = "Home Manager environment for ${username}";
wantedBy = [ "multi-user.target" ];
wants = [ "nix-daemon.socket" ];
@ -44,7 +56,9 @@ in {
environment = serviceEnvironment;
unitConfig = { RequiresMountsFor = usercfg.home.homeDirectory; };
unitConfig = {
RequiresMountsFor = usercfg.home.homeDirectory;
};
stopIfChanged = false;
@ -54,37 +68,39 @@ in {
TimeoutStartSec = "5m";
SyslogIdentifier = "hm-activate-${username}";
ExecStart = let
systemctl =
"XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/run/user/$UID} systemctl";
ExecStart =
let
systemctl = "XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/run/user/$UID} systemctl";
sed = "${pkgs.gnused}/bin/sed";
sed = "${pkgs.gnused}/bin/sed";
exportedSystemdVariables = lib.concatStringsSep "|" [
"DBUS_SESSION_BUS_ADDRESS"
"DISPLAY"
"WAYLAND_DISPLAY"
"XAUTHORITY"
"XDG_RUNTIME_DIR"
];
exportedSystemdVariables = lib.concatStringsSep "|" [
"DBUS_SESSION_BUS_ADDRESS"
"DISPLAY"
"WAYLAND_DISPLAY"
"XAUTHORITY"
"XDG_RUNTIME_DIR"
];
setupEnv = pkgs.writeScript "hm-setup-env" ''
#! ${pkgs.runtimeShell} -el
setupEnv = pkgs.writeScript "hm-setup-env" ''
#! ${pkgs.runtimeShell} -el
# The activation script is run by a login shell to make sure
# that the user is given a sane environment.
# If the user is logged in, import variables from their current
# session environment.
eval "$(
${systemctl} --user show-environment 2> /dev/null \
| ${sed} -En '/^(${exportedSystemdVariables})=/s/^/export /p'
)"
# The activation script is run by a login shell to make sure
# that the user is given a sane environment.
# If the user is logged in, import variables from their current
# session environment.
eval "$(
${systemctl} --user show-environment 2> /dev/null \
| ${sed} -En '/^(${exportedSystemdVariables})=/s/^/export /p'
)"
exec "$1/activate"
'';
in "${setupEnv} ${usercfg.home.activationPackage}";
exec "$1/activate"
'';
in
"${setupEnv} ${usercfg.home.activationPackage}";
};
}) cfg.users;
}
) cfg.users;
})
];
}