How to define alias in shellHook?

How can I define alias in shellHook? I have tried something like this, but it doesn’t work. I think I have addressed the non-interactive shell issue by setting shopt -s expand_aliases there?

  description = "Testing flake for alias";

  outputs = { self, nixpkgs }:
    let system = "x86_64-linux";
    in {
      devShell.${system} = (({ pkgs, ... }:
          alias = pkgs.writeShellScriptBin "test-alias" ''
          shopt -s expand_aliases
          alias foo=nvim
        in pkgs.mkShell {
          buildInputs = with pkgs; [

          shellHook = ''
              echo ${alias}/bin/test-alias
              source ${alias}/bin/test-alias
              export hello=world
        }) { pkgs = nixpkgs.legacyPackages.${system}; });

1 Like

You should be able to just do

1 Like

Note that if you’re using direnv, this is currently explicitly impossible because of the way it handles shells.


Yes exactly I am using direnv now. I thought I was the issue of nix-shell so I haven’t searched that way.

Seems like this is the related issue

1 Like