-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathreadme.nix
More file actions
33 lines (28 loc) · 734 Bytes
/
readme.nix
File metadata and controls
33 lines (28 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{
system ? builtins.currentSystem,
}:
let
pins = import ./npins;
pkgs = import pins.nixpkgs { inherit system; };
npins = pkgs.callPackage ./default.nix { };
in
pkgs.runCommand "readme"
{
nativeBuildInputs = [ npins ];
preferLocalBuild = true;
raw = ./README.md.in;
}
''
set -euo pipefail
content="$(cat $raw)"
# Match "{{foo}}"
regex='\{\{([^\}]*)\}\}'
# Replace "{{foo}}" with "$(foo)", i.e. run the command
while [[ $content =~ $regex ]]; do
command="''${BASH_REMATCH[1]}"
# Run the command, capture failure gracefully
command="$($command 2>&1 || true)"
content="''${content/"''${BASH_REMATCH[0]}"/"$command"}"
done
echo "$content" >> $out
''