A quick way to add cmds to PATH?

Hi all,

Use case → Coding simple stuff I am trying & changing constantly. I would not install it at every single change but want to be able to call these commands directly.

In another OS I could add the various bin or shell to the $PATH , or directly create symlinks from /usr/bin to these few projects.

What is a quick but proper way in NixOS? I would add in the NixOS configuration few lines about this specific user to complete his $PATH? I have home-manager installed from previous trials, I could maybe rather use this I bet ? Or is there a somewhat simpler way to enrich path?

Sorry if the answer is obvious, I looked at few docs but honnestly answers here are generally more interesting

Hey hey,

Check out pkgs.writeShellScript. I think this is largely what you’re looking for :slight_smile:

1 Like

nix profile install

I have a Zettel on this topic: Separation of concerns – ners

Basically, it is a good idea to aim for the smallest scope:

  • if at all possible, use temporary shells (backed by a flake / shell.nix for reproducibility)
  • failing that, home-manager is the second smallest scope
  • failing that, you can either use shell aliases or nix profile, with their respective caveats

The existing answers don’t really help with this use case, since they all imply rebuilding your NixOS configuration on every change.

If you want a really low-friciton way of just getting a binary in $PATH, just do that. It’s perfectly reasonable to add ~/.local/bin to $PATH, and just symlink your binaries into there. It’s not “proper”, in that it’s not reproducible, but with stuff you just have lying around locally in directories that won’t be true anyway.

Once you’re ready to make those things more permanent you should package them and install them just like any other package; depending on the languages you write your mini projects in, this will look different.

I would not recommend manually symlinking stuff to /usr/bin even on other distros. Use ~/.local/bin.

5 Likes

home manager seems to fit. I tried to edit it and switch, then restarted shell and even rebooted but unfortunately I saw no result


  home = {
    stateVersion = "25.05";
    username = "xxx";
    homeDirectory = "/home/xxx";


    #
    # PATH
    #
    sessionPath = [
      "/home/xxx/nshell/intime/target/release"
    ];
  };

So what i did for the moment is adding the path to fish config. It works fine but i wonder what I miss with home manager

Are you using home-manager standalone or with NixOS?


If using it standalone (which I do not recommend if you’re using NixOS, see these docs on how to do it correctly), you need to potentially also set up your shell profile. From the manual:

If you do not plan on having Home Manager manage your shell configuration then you must source the

$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh

file in your shell configuration. Alternatively source

/etc/profiles/per-user/$USER/etc/profile.d/hm-session-vars.sh`

when managing home configuration together with system configuration.

This file can be sourced directly by POSIX.2-like shells such as Bash or Z shell. Fish users can use utilities such as foreign-env or babelfish.

For example, if you use Bash then add

. "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"`

to your ~/.profile file.

Without this, home-manager cannot control your user’s $PATH.


If using it with NixOS things should just work, however you might not notice the home-manager activation script failing. This is pretty common on new installations because it will refuse to overwrite existing files. Check journalctl --user -e after running the switch.

It’s also quite possible that fish doesn’t source the default path that home-manager sets your env variables in. I don’t use fish, I don’t know how the default NixOS fish configuration works and I don’t know if your configuration overrides default behavior.

Oh you are a genius. Or maybe am I stupid haha. Anyway

  • I use home manager with NixOS. Happy to read it is recommended. I remember I hesitated because rebuilding just home seemed a useful feature, but anyway my HM usage is very limited and just started in order to try hyprland.
  • … And actually the HM sessionPath worked like a charm! As you bet, fish does ignore it. I ran a bash session and the $PATH was properly set. Not a very good point for fish - but I probably forgot to read about it somewhere.

So HM seems very convenient for someone not using fish, while fish users may use for example set -U fish_user_paths . I will investigate pkgs.writeShellScript later.

Well, you just need to configure fish to read the home-manager profile. You can even get home-manager to do it for youAppendix A. Home Manager Configuration Options.