-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlib.nix
31 lines (28 loc) · 1018 Bytes
/
lib.nix
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
{ pkgs, ... }:
with pkgs.lib;
let
ciScriptTemplate = { name, command }: ''
echo -e "${name}:"
echo "Running \"${command}\"..."
${command} \
&& echo -e "\033[0;32mSucceeded!\033[0m" \
|| (s=$?; echo -e "\033[0;31mFailed!\033[0m"; exit $s)
'';
# Wrapper function around `mkCiScriptsBin` and `mkCiScriptBin`.
# Outputs a list containing the results of both functions.
mkCiScripts = s: (mkCiScriptsBin s) ++ [ (mkCiAllScriptBin s) ];
# Writes an executable script for each entry in an attribute set.
mkCiScriptsBin = s: attrsets.mapAttrsToList
(name: command: (pkgs.writeShellScriptBin "ci-${name}"
(ciScriptTemplate { inherit name command; })))
s;
# Writes an executable script that will run all entries in an attribute set.
mkCiAllScriptBin = s: pkgs.writeShellScriptBin "ci-all"
(strings.concatStringsSep "\necho\n"
(attrsets.mapAttrsToList
(name: command: (ciScriptTemplate { inherit name command; }))
s));
in
{
inherit mkCiScripts;
}