Shell Scripts

From NixOS Wiki
Revision as of 09:06, 1 October 2021 by imported>Milahu (+ demo for writeShellScript)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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
      '';
    };