Skip to content

Commit

Permalink
nix-darwin: improve invocation of activation script
Browse files Browse the repository at this point in the history
In nix-community#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 nix-community#2900
  • Loading branch information
toonn authored and rycee committed Sep 19, 2022
1 parent 5427f3d commit 610b1d9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion nix-darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ in {
system.activationScripts.postActivation.text = concatStringsSep "\n"
(mapAttrsToList (username: usercfg: ''
echo Activating home-manager configuration for ${username}
sudo -u ${username} -s --set-home ${
SHELL=${pkgs.bash} sudo -u ${username} -s --set-home ${
pkgs.writeShellScript "activation-${username}" ''
${lib.optionalString (cfg.backupFileExtension != null)
"export HOME_MANAGER_BACKUP_EXT=${
Expand Down

0 comments on commit 610b1d9

Please sign in to comment.