home.shellAliases unable to set aliases using home-manager

I have set up home-manager like this inside my nix-darwin.
Every thing is working perfectly except for the shellAliases part.

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

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

  home-manager.users.<user> = { pkgs, ... }: {
    home = {
      shellAliases = {
          asl = "aws sso login";
      };
      packages = with pkgs; [
        btop
        direnv
        gh
        neovim
        nixfmt
        tree
        zoxide
        bat
        lazygit
        delta
        ripgrep
        cargo
        speedtest-cli
      ];
      stateVersion = "22.05";
    };
  };

The packages are working, but the alias is not.
What could be the issue?

1 Like

I don’t know the problem - what is the exact symptom you’re seeing? - but you could try setting a shell-specific alias instead. I presume you’ve somehow arranged for aws to be on your $PATH?

Yes, aws works.
By the “alias is not” working, I meant that that on executing asl it can’t recognise it at all.

asl
zsh: command not found: asl

I intended to move this alias from my .zshrc to home.shellAliases because I understand that this way, these aliases will accessible from other shells like fish as well right?

I had the same problem. The reason is that home-manager is simply passing the value of home.shellAliases to programs.{bash,zsh,fish}.shellAliases as you can see here:

To make these aliases work, you need to actually enable one of these shells in your home-manager configuration, which I had not - I had enabled programs.zsh only globally in my configuration.nix, and so home-manager never had a reason to generate a ~/.zshrc for me.

Beware though that programs.zsh in home-manager comes with some settings enabled by default, which might override your global settings (for example programs.zsh.history.size = 10000, which overrode the programs.zsh.histSize = 100000 in my configuration.nix). Check the generated ~/.zshrc and customize your programs.zsh settings per Appendix A. Home Manager Configuration Options to sort this out.

2 Likes