From 89979c9c5bef4cfc89e66662b1238a0bf7617702 Mon Sep 17 00:00:00 2001 From: Bernardo Meurer Date: Tue, 12 Oct 2021 12:31:02 -0700 Subject: writeShellApplication: init --- doc/builders/trivial-builders.chapter.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'doc') diff --git a/doc/builders/trivial-builders.chapter.md b/doc/builders/trivial-builders.chapter.md index 46620e1b459..4c0318a2541 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. -- cgit 1.4.1 From 0e4f04b74c3ec5948e2d860540409cf02306cb33 Mon Sep 17 00:00:00 2001 From: Bernardo Meurer Date: Tue, 12 Oct 2021 12:48:27 -0700 Subject: writeShellApplication: buildInputs -> runtimeInputs --- doc/builders/trivial-builders.chapter.md | 4 ++-- pkgs/build-support/trivial-builders.nix | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'doc') diff --git a/doc/builders/trivial-builders.chapter.md b/doc/builders/trivial-builders.chapter.md index 4c0318a2541..c3a3572cd9f 100644 --- a/doc/builders/trivial-builders.chapter.md +++ b/doc/builders/trivial-builders.chapter.md @@ -49,7 +49,7 @@ Many more commands wrap `writeTextFile` including `writeText`, `writeTextDir`, ` ## `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). +This can be used to easily produce a shell script that has some dependencies (`runtimeInputs`). 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: @@ -57,7 +57,7 @@ For example, look at the following code: writeShellApplication { name = "show-nixos-org"; - buildInputs = [ curl w3m ]; + runtimeInputs = [ curl w3m ]; text = '' curl -s 'https://nixos.org' | w3m -dump -T text/html diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix index 506f8431016..e0571632e76 100644 --- a/pkgs/build-support/trivial-builders.nix +++ b/pkgs/build-support/trivial-builders.nix @@ -260,7 +260,7 @@ rec { * # Writes my-file to /nix/store//bin/my-file and makes executable. * writeShellApplication { * name = "my-file"; - * buildInputs = [ curl w3m ]; + * runtimeInputs = [ curl w3m ]; * text = '' * curl -s 'https://nixos.org' | w3m -dump -T text/html * ''; @@ -269,7 +269,7 @@ rec { writeShellApplication = { name , text - , buildInputs ? [ ] + , runtimeInputs ? [ ] , checkPhase ? null }: writeTextFile { @@ -282,7 +282,7 @@ rec { set -o nounset set- o pipefail - export PATH="${makeBinPath buildInputs}:$PATH" + export PATH="${makeBinPath runtimeInputs}:$PATH" ${text} ''; -- cgit 1.4.1