Shell script not added to path

Hi. I am working on a derivation which is a simple shell script (mons).

Running nix-shell $MYNIXPKGS -A mons builds the derivation and puts it into /nix/store/. I can call the script with the full path /nix/store/.../usr/bin/mons, however, I cannot call it without the full path.

What is necessary to get nix to make the script accessible? Where is this documented?

1 Like

Hi @feijoas.

This is a common misconception of what nix-shell does. That tools’ main intent is to help debug derivations by bringing all the build phases and dependencies into the shell so you can play with it.

To achieve what you want, try adding your package as a buildInput of yet another derivation and load that-one with nix-shell. For example if your shell.nix looks like this:

{ pkgs ? import <nixpkgs> {} }:
rec {
  mons = pkgs.callPackage ./mons.nix {};
  shell = pkgs.runCommand "my-shell" { buildInputs = [ mons ]; } "";

Then call nix-shell -A shell.

Thanks, but that also doesn’t work.

I also put the package into all-packages.nix an then in my environment.systemPackages. After sudo nixos-rebuild switch -I nixpkgs=$MYNIXPKGS, the script is still not callable. It looks simply like this:

{ stdenv, lib, fetchFromGitHub, fetchpatch, help2man, xrandr }:

stdenv.mkDerivation rec {
    pname = "mons";
    version = "20200107";

    src = fetchFromGitHub {
        owner = "Ventto";
        repo = pname;
        rev = "0c9e1a1dddff23a0525ed8e4ec9af8f9dd8cad4c";
        sha256 = "02c41mw3g1mgl91hhpz1n45iaqk9s7mdk1ixm8yv6sv17hy8rr4w";
        fetchSubmodules = true;

    nativeBuildInputs = [ help2man ];
    makeFlags = [ "DESTDIR=$(out)" ];

    meta = with lib; {
        description = "POSIX Shell script to quickly manage 2-monitors display";
        homepage = "";
        license =;
        maintainers = [ maintainers.mschneider ];

That’s another issue. The package installs things in $out/usr instead of $out. Most of the time packages have a PREFIX and DESTDIR and you want to set the PREFIX instead so that the binary ends-up in $out/bin/mons.

Perfect, thanks a lot. I created a PR: Mons by feijoas · Pull Request #79000 · NixOS/nixpkgs · GitHub