Skip to content

Instantly share code, notes, and snippets.

@monadplus
Last active March 19, 2025 21:46
Show Gist options
  • Save monadplus/3a4eb505633f5b03ef093514cf8356a1 to your computer and use it in GitHub Desktop.
Save monadplus/3a4eb505633f5b03ef093514cf8356a1 to your computer and use it in GitHub Desktop.
Nix: runCommand, writeShellApplication
# cat $(nix-build)/bin/date/today.txt
{ nixpkgs ? import <nixpkgs> {}}:
nixpkgs.runCommand "print-date" {
nativeBuildInputs = [ nixpkgs.coreutils ];
} ''
# line 5 in nix file = line 1 in bash script -> offset 4
PS4='+ Line $(expr $LINENO + 4): '
set -o xtrace # print commands
mkdir -p $out/date/
date > $out/date/today.txt
set +o xtrace # hide commands
''
# $(nix-build)/bin/test
# cat response.json
{ nixpkgs ? import <nixpkgs> {}}:
nixpkgs.writeShellApplication {
name = "test";
runtimeInputs = with nixpkgs; [ curl w3m ];
text = ''
curl -XPOST httpbin.org/post > response.json
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment