Doas not resolving aliases in fish

I’d like to switch to doas and have defined the following in configuration.nix:

  security.sudo.enable = false;
  security.doas.enable = true;
  security.doas.extraRules = [{
    groups = [ "wheel" ];
    persist = true;
    keepEnv = true;

In environment.systemPackages = with pkgs; [ i have (pkgs.writeScriptBin "sudo" ''exec doas "$@"'').

In environment.shellAliases = { i have sudo = "doas";.

It is working as intended except that aliases in fish are not resolved when sudo or doas is prepended:

~ ❯ sudo tp                                                                                                                     
doas (sperber@nixos) password:
doas: tp: command not found
~ ❯ tp
error: No paths were specified to trash

Why is fish not expanding the aliases in this case?

I don’t use fish, but: does this imply that you’ve confirmed it works as you expect in other shells?

IIRC at least in bash aliases have to end with a space for the shell to try expanding additional aliases.

Good point! I just tried in bash and the result is the same.

The strange part is, that even doas tp doesn’t work although doas is not an alias:

[sperber@nixos ~]$ doas tp
doas: tp: command not found
[sperber@nixos ~]$ tp
error: No paths were specified to trash

Not familiar with fish but I assume it handles aliases in the same way as POSIX shells. Aliases are not expaned in command arguments. It’s not specific to sudo or doas.

/run/current-system/sw/bin/time tp will also fail for the same reason.


Alright, then apparently i just didn’t run into this behaviour before.

Is there a way around this, i.e. can i tell fish to expand aliases anyway?

This is mostly true, but there is an asterisk.

Aliases are also commands, and the shell will try to continue expanding aliases if the current one ends with a space or tab.

If sudo is an alias that ends in a space and tp is an alias, it should expand both (but now that I am picking this nit, I realize tp is never stated to be an alias).

tp is an alias for trash put. That’s why it’s working on its own but not with ‘sudo’ or ‘doas’ in front.

As mentioned, doas tp doesn’t work because tp isn’t expanded although doas is not an alias.