Shell Scripts: Difference between revisions

imported>Milahu
+ External builder.sh script
imported>Milahu
+ runCommand + builder.sh, fix links
Line 25: Line 25:
   outputTxtPath = stdenv.mkDerivation rec {
   outputTxtPath = stdenv.mkDerivation rec {
     name = "output.txt";
     name = "output.txt";
     # disable unpackPhase etc https://github.com/NixOS/nixpkgs/issues/23099
     # disable unpackPhase etc
     phases = "buildPhase";
     phases = "buildPhase";
     builder = ./builder.sh;
     builder = ./builder.sh;
Line 43: Line 43:
</syntaxHighlight>
</syntaxHighlight>


see also [https://nixos.org/guides/nix-pills/working-derivation.html Nix Pills: Chapter 7. Working Derivation]
See also
 
* [https://github.com/NixOS/nixpkgs/issues/23099 make a derivation with no source]
* [https://nixos.org/guides/nix-pills/working-derivation.html Nix Pills: Chapter 7. Working Derivation]
 
=== runCommand + builder.sh ===
 
Instead of <code>stdenv.mkDerivation</code>, we can also use <code>runCommand</code> to call an external bash script:
 
<syntaxHighlight lang="nix">
# default.nix
{
  outputTxtPath = runCommand "output.txt" {
    nativeBuildInputs = [ coreutils jq ];
    # only strings can be passed to builder
    someString = "hello";
    someNumber = builtins.toString 42;
    someJson = builtins.toJSON { dst = "world"; };
  } (builtins.readFile ./builder.sh);
}
</syntaxHighlight>


== Packaging ==
== Packaging ==