Shell Scripts

From NixOS Wiki
Revision as of 09:15, 1 October 2021 by imported>Milahu (+ section Posix Shell)

the package writeShellScript can be used to add shell scripts to nix expressions

  someBuildHelper = { name, sha256 }:
    stdenv.mkDerivation {
      inherit name;
      outputHashMode = "recursive";
      outputHashAlgo = "sha256";
      outputHash = sha256;
      builder = writeShellScript "builder.sh" ''
        echo "hi, my name is ''${0}" # escape bash variable
        echo "hi, my hash is ${sha256}" # use nix variable
        echo "hello world" >output.txt
      '';
    };

Posix Shell

some environments (like OpenWRT, via busybox) offer only a "limited" shell (sh instead of bash).

on nixos, posix shells are provided by the packages dash and posh