# Aliases not working for fish shell + sudo

**URL:** <https://forum.systemcrafters.net/t/aliases-not-working-for-fish-shell-sudo/2019>\
**Category:** Guix\
**Created:** [May 19, 2026, 5:36am UTC](https://forum.systemcrafters.net/t/aliases-not-working-for-fish-shell-sudo/2019 "2026-05-19T05:36:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Folaht](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/folaht/32/1145_2.png) [@Folaht](https://forum.systemcrafters.net/u/Folaht)\
**Post date:** [May 19, 2026, 5:36am UTC](https://forum.systemcrafters.net/t/aliases-not-working-for-fish-shell-sudo/2019/1 "2026-05-19T05:36:58Z")

</div>

I have the following setup:

_home-configuration.scm_

```scheme
(services
   (append (list (service home-bash-service-type
                          (home-bash-configuration
     (aliases '(("sudo" . "sudo ") 
      ...
      ("vim" . "nvim")
   (service home-fish-service-type
     (home-fish-configuration
       (aliases '(("sudo" . "sudo ") 
        ...
         ("vim" . "nvim")

```

This causes `vim` and `sudo vim` to work for bash and `vim` for fish including when logging as root user via `su`, but unfortunately `sudo vim` does not work using fish.

```shell
> sudo vim
sudo: vim: command not found

```

What could be the cause?

---

<div class="post-metadata">

**Author:** ![aionfork](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/aionfork/32/1243_2.png) [@aionfork](https://forum.systemcrafters.net/u/aionfork)\
**Post date:** [May 20, 2026, 6:38am UTC](https://forum.systemcrafters.net/t/aliases-not-working-for-fish-shell-sudo/2019/2 "2026-05-20T06:38:12Z")

</div>

You should diff the various environments with those aliases I posted on the other thread.

- bash: env and sudo env
- fish: env and sudo env
- bash and fish

It’s likely you have something in your .bash\_profile (or .profile) which isn’t being set up for fish.

Also, your window manager will set up a profile when it loads. Sometimes you need to login & logout. The Guix home container should show updates.

This is all a bit confusing when setting it up for yourself in Arch (from scratch), NixOS or Guix.

---

<div class="post-metadata">

**Author:** ![aionfork](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/aionfork/32/1243_2.png) [@aionfork](https://forum.systemcrafters.net/u/aionfork)\
**Post date:** [May 20, 2026, 6:42am UTC](https://forum.systemcrafters.net/t/aliases-not-working-for-fish-shell-sudo/2019/3 "2026-05-20T06:42:26Z")

</div>

I haven’t used fish, so I’m not 100% sure.

Again, check `sudo env | grep -e ‘^PATH’ | tr ‘:’ ‘\n’` from within fish. Or use alias. Or whatever command works in fish

Sudo has some environment differences. So it can’t find vim in PATH

---

<div class="post-metadata">

**Author:** ![Folaht](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/folaht/32/1145_2.png) [@Folaht](https://forum.systemcrafters.net/u/Folaht)\
**Post date:** [May 20, 2026, 3:11pm UTC](https://forum.systemcrafters.net/t/aliases-not-working-for-fish-shell-sudo/2019/4 "2026-05-20T15:11:46Z")

</div>

Checking the envs I’ve noticed that all the PATHs are the same.  
On top of that I’ve (re-)discovered that all aliases are not working.

```shell
> df

Filesystem Size Used Avail Use% Mounted on
none 18G 0 18G 0% /dev
...

> sudo df
Filesystem 1K-blocks Used Available Use% Mounted on
none 18250332 0 18250332 0% /dev
...

> bash
$ df

Filesystem Size Used Avail Use% Mounted on
none 18G 0 18G 0% /dev
...

$ sudo df

Filesystem Size Used Avail Use% Mounted on
none 18G 0 18G 0% /dev
...

```

_home-configuration.scm_

```scheme
services
   (append (list (service home-bash-service-type
                          (home-bash-configuration
     (aliases '(("sudo" . "sudo ") 
      ...
      ("df" . "df -h")
   (service home-fish-service-type
     (home-fish-configuration
       (aliases '(("sudo" . "sudo ") 
        ...
         ("df" . "df -h")

```

---

<div class="post-metadata">

**Author:** ![Folaht](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/folaht/32/1145_2.png) [@Folaht](https://forum.systemcrafters.net/u/Folaht)\
**Post date:** [August 15, 2026, 8:35am UTC](https://forum.systemcrafters.net/t/aliases-not-working-for-fish-shell-sudo/2019/5 "2026-08-15T08:35:07Z")

</div>

This seems to be a fish shell issue.  
The bash trick doesn’t work, so one has to write a fish alias function, remove the `sudo` alias for the `home-fish-service-type` and since there’s no `functions` option for `home-fish-configuration`, I put the alias function in the `config.fish` file, which loads at startup.

_~/dotfiles/home/folaht/main-computer.scm_

```auto
(define-module (config home folaht main-computer)
  #:use-module (gnu home)
  ...
  #:use-module (gnu packages shells)
  #:use-module (config home .services shells)
  ...)

(home-environment
  ...
  (services
   (append (list home-fish-service-default
                 ...)
           %base-home-services)))

```

_~/dotfiles/home/.services/shells.scm_

```auto
(define shell-aliases
  '(("df" . "df -h") 
    ...
    (".." . "cd ../")))

(define bash-aliases (append '(("sudo" . "sudo ")) shell-aliases))

(define home-bash-service-default
  (service home-bash-service-type
    (home-bash-configuration
      ...
      (aliases bash-aliases)
      ...)))

(define home-fish-service-default
  (service home-fish-service-type
           (home-fish-configuration 
             (config (list (local-file "../.config/fish/functions/sudo.fish")))
             (aliases shell-aliases)))))

```

_~dotfiles/home/.config/fish/functions/sudo.fish_

```sh
function sudo
    if functions -q -- "$argv[1]"
        set cmdline (
            for arg in $argv
                printf "\"%s\" " $arg
            end
        )
        set -x function_src (string join "\n" (string escape --style=var (functions "$argv[1]")))
        set argv fish -c 'string unescape --style=var (string split "\n" $function_src) | source; '$cmdline
        command sudo -E $argv
    else
        command sudo $argv
    end
end

```
