diff options
author | Bernardo Meurer <bernardo@meurer.org> | 2021-10-12 12:31:02 -0700 |
---|---|---|
committer | Bernardo Meurer <bernardo@meurer.org> | 2021-11-08 09:33:32 -0800 |
commit | 89979c9c5bef4cfc89e66662b1238a0bf7617702 (patch) | |
tree | d5594914e9cfc0346103f6120bbfd8579a1564d6 /doc/builders/trivial-builders.chapter.md | |
parent | 2de888a972be0747c29a23de73a092fd0e558677 (diff) |
writeShellApplication: init
Diffstat (limited to 'doc/builders/trivial-builders.chapter.md')
-rw-r--r-- | doc/builders/trivial-builders.chapter.md | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/doc/builders/trivial-builders.chapter.md b/doc/builders/trivial-builders.chapter.md index 46620e1b459c..4c0318a2541a 100644 --- a/doc/builders/trivial-builders.chapter.md +++ b/doc/builders/trivial-builders.chapter.md @@ -47,6 +47,28 @@ These functions write `text` to the Nix store. This is useful for creating scrip Many more commands wrap `writeTextFile` including `writeText`, `writeTextDir`, `writeScript`, and `writeScriptBin`. These are convenience functions over `writeTextFile`. +## `writeShellApplication` {#trivial-builder-writeShellApplication} + +This can be used to easily produce a shell script that has some dependencies (`buildInputs`). It automatically sets the `PATH` of the script to contain all of the listed inputs, sets some sanity shellopts (`errexit`, `nounset`, `pipefail`), and checks the resulting script with [`shellcheck`](https://github.com/koalaman/shellcheck). + +For example, look at the following code: + +```nix +writeShellApplication { + name = "show-nixos-org"; + + buildInputs = [ curl w3m ]; + + text = '' + curl -s 'https://nixos.org' | w3m -dump -T text/html + ''; +} +``` + +Unlike with normal `writeShellScriptBin`, there is no need to manually write out `${curl}/bin/curl`, setting the PATH +was handled by `writeShellApplication`. Moreover, the script is being checked with `shellcheck` for more strict +validation. + ## `symlinkJoin` {#trivial-builder-symlinkJoin} This can be used to put many derivations into the same directory structure. It works by creating a new derivation and adding symlinks to each of the paths listed. It expects two arguments, `name`, and `paths`. `name` is the name used in the Nix store path for the created derivation. `paths` is a list of paths that will be symlinked. These paths can be to Nix store derivations or any other subdirectory contained within. |