Packaging shell scripts



I’d love to package for NixOS, which is a simple bash script which relies on a single external utility, wmctrl. What is the nix was to handle this? Should I use makeWrapper or should I try to patch the source code of the script with the correct executable? Are there some nice examples I can use?



I’d vote for patching. But looks like in this case patching is easy:

  pkgs = import <nixpkgs> {};
in pkgs.runCommand "jumpapp" {
    buildInputs = with pkgs; [ xdotool wmctrl xorg.xprop nettools ];
} ''
  mkdir -p $out/bin
  cp ${./jumpapp} $out/bin/jumpapp
  sed -i "2 i export PATH=$PATH" $out/bin/jumpapp

So running jumpapp script is exactly the same, what you get when running in nix-shell --pure. You can make it less pure (and reduce closure size) with following patch:

  sed -i "2 i export PATH=$_PATH:\$PATH" $out/bin/jumpapp
1 Like


Thanks! Send a PR: