Home-Manager not setting sessionVariables or shellAliases

I am using home-manager within my nix-darwin configuration file.
Like shown here.

I have set up programs, home.packages, home.stateVersion,
Everything works EXCEPT home.sessionVariables and home.shellAliases.

home.sessionVariables = { EDITOR = "nvim"; };
home.shellAliases = { asl = "aws sso login"; };

When I rebuild for some reason these two things are not set.
Any ideas?

Further context:
This is my darwin-configuration.nix file:

{ config, pkgs, ... }:

{
  nixpkgs.config.allowUnfree = true;
  nix.extraOptions = "experimental-features = nix-command flakes";

  environment.systemPackages = with pkgs; [
    wget
    vim
    .
    .
    .
  ];
  services.nix-daemon.enable = true;
 
  programs.zsh.enable = true; # default shell on catalina
 
  system.stateVersion = 4;

  # System Configurations
  environment.loginShell = pkgs.zsh;
  fonts.fonts = [
    (pkgs.nerdfonts.override { fonts = [ "Meslo" "FiraCode" "FiraMono" ]; })
  ];

  system.defaults.NSGlobalDomain."com.apple.mouse.tapBehavior" = 1;
  system.defaults.NSGlobalDomain."com.apple.swipescrolldirection" = false;
  system.defaults.dock.autohide = true;
  system.defaults.dock.static-only = true;
  system.defaults.dock.wvous-bl-corner = 2; # Bottom-Left hot corner is "Mission Control"
  system.defaults.finder.AppleShowAllExtensions = true;

  # Home Manager configurations
  imports = [ <home-manager/nix-darwin> ];

  users.users.<user> = {
    name = "<user>";
    home = "/Users/<user>";
  };

  home-manager.users.<user> = { pkgs, ... }: {
    home.sessionVariables = { EDITOR = "nvim"; };
    home.shellAliases = { asl = "aws sso login"; };

    programs = {
      fzf = {
        enable = true;
        enableZshIntegration = true;
      };
      gh = {
        enable = true;
        settings = {
          git_protocol = "ssh";
          prompt = "enabled";
        };
      };
      neovim = {
        enable = true;
        defaultEditor = true;
        vimAlias = true;
      };
    };

    home.packages = with pkgs; [
      bat
      tree
      .
      .
      .
    ];

    home.stateVersion = "22.05";
  };
}

As you can see I am doing both nix-darwin and home-manager in the same file.

My shell doesn’t have access to home-manager switch, I have to do darwin-rebuild switch to rebuild both.

Please let me know what might be going wrong.

This sounds like this issue but you are using Darwin. I had the same issue with home.sessionVariables having no effect, but on Linux. Since this pull request the issue has resolved for me but perhaps it is not on Darwin.

I have the same thing on darwin.

I can see that the env variables are set in the /nix/store/xxx-set-environment and the aliases are in /nix/store/xxx-etc-zprofile

But

  • I can’t see the etc-zprofile sourced from anywhere
  • I can see the set-environment conditionally sourced from /etc/zshenv but it seems the condition is not met when I start a new shell
  14   │ if [ -z "$__NIX_DARWIN_SET_ENVIRONMENT_DONE" ]; then
  15   │   echo "sourcing set-environment"
  16   │   . /nix/store/m0jamcgydzcdcnqjad0m1c8y2m3hlpp9-set-environment
  17   │ fi

Digging a little bit further

  • seems like environment.shellAliases are setup only for login shell. zsh -l will have the aliases, but not zsh
  • env variables don’t seem preset

and env variables seem to work once I rebooted… this is a bit weird.

as far as the aliases are concerned I guess this is wrong.
They should be available in interactive shell as well as login shells. And they are not inherited by subshells (right?).

For env variables, I guess if they are only in login shell, it should be ok since they should be inherited by subshell (right?)

sorry, I’m not completely sure about all this.

I got my setup working. The problem I had mostly is that I use zellij which does not start a login shell. I add to write a wrapper script and have zellij start that (zsh -l) as you can’t give a command to zellij, just a path to an executable file

I just had the same problem Trouble setting environment variables in home manager - #2 by eljamm

.