Skip to content

Features

Karim Vergnes edited this page Feb 20, 2023 · 5 revisions

The nix script generated by nix-wrap comes with a few handy features, for a smooth user experience.

Full nix-shell compatibility

You can save or symlink your nix script as nix-shell, which will make it behave exactly like the normal nix-shell command. You can even use it as a script shebang, using the exact same format!

Example:

#!./nix-shell
#!nix-shell -i python -p python3 python3Packages.scipy
import scipy
...

Command substitution

If your project contains a shell.nix or flake.nix at its root, you can invoke the same nix script as the name of any command provided by your development environment, and it will be transparently installed and invoked as-is!

Example shell.nix

{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
  name = "cowsay";
  nativeBuildInputs = with pkgs; [ cowsay ];
}

which gives us...

$ cowsay "hello"
bash: cowsay: command not found
$ ln -s ./nix ./cowsay
$ ./cowsay "hello"
 _______ 
< hello >
 ------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
Clone this wiki locally