mirror of
https://github.com/nix-community/home-manager.git
synced 2024-12-14 11:57:55 +00:00
610b1d988c
In #807 I changed the flag passed to `sudo` from `-i` to `-s` so `sudo` wouldn't use a non-existent shell defined in the `passwd` file. kalbasit also reported in that PR that `-i` didn't work for them anymore on an M1 Mac, presumably because Apple changed something in newer versions of macOS. Some users reported that this broke the behavior for them because `SHELL` was set to a path that didn't even exist on their system. It's unclear how this came to be but it shows that my assumption that `SHELL` would be set to a reasonable shell by Home Manager at this point in the activation is false. As a way around this problem we can explicitly set `SHELL` when running the activation script to a value that we know will be good, like `${pkgs.bash}`. One change in behavior this causes is that the activation script will always be run by bash, not the user's shell. If the script is generated by Home Manager this is fine since it can be generated taking into account the supported set of functions and behaviors. If the intent is for the activation script to possibly be run by non-bash and even non-POSIX shells, like tcsh, ksh or Xonsh, then this fix will not suffice. Turns out this is indeed an assumption made by Home Manager, so this is the proper behavior. Fixes #2900
31 lines
939 B
Nix
31 lines
939 B
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.home-manager;
|
|
|
|
in {
|
|
imports = [ ../nixos/common.nix ];
|
|
|
|
config = mkMerge [
|
|
{ home-manager.extraSpecialArgs.darwinConfig = config; }
|
|
(mkIf (cfg.users != { }) {
|
|
system.activationScripts.postActivation.text = concatStringsSep "\n"
|
|
(mapAttrsToList (username: usercfg: ''
|
|
echo Activating home-manager configuration for ${username}
|
|
SHELL=${pkgs.bash} sudo -u ${username} -s --set-home ${
|
|
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
|
|
''
|
|
}
|
|
'') cfg.users);
|
|
})
|
|
];
|
|
}
|