How to set up system wide aliases for all shell script in configuration.nix?

I see people recommending “environment.shellAliases” but I cannot find out how to use it.
I do not know how to set it up in my configuration.nix
Teach me how, please.

Your configuration file has the following structure:

{ config, ... }:
{
  some.nixos.option = "its value";
  another.one = [ "a" "list" "value" ];

  maybe.you.have = {
    some.collected = "options";
    like.this = true;
  };
}

I don’t know exactly what yours looks like; you have to learn the language enough to understand where each option definition begins and ends.

To use environment.shellAliases, add a new option definition to the outermost set of braces, like this:

{ config, ... }:
{
  some.nixos.option = "its value";
  another.one = [ "a" "list" "value" ];

  maybe.you.have = {
    some.collected = "options";
    like.this = true;
  };

  environment.shellAliases = {
    your-sweet-alias = "command that it stands for";
    # as many of the above as you like
  };
}

That’s it! Don’t forget to place a semicolon at the end of every attribute, like I have above.

1 Like

Thanks, it works perfectly.
Now my nixOS can be extra lazy!