-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
50 lines (44 loc) · 1.51 KB
/
flake.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{
description = "A (very) minimalist nix flake lib for printing a help message in your shell";
outputs = { self, ... }:
let
# inherit (nixpkgs) lib;
# Colors
nc = "\\e[0m";
white = "\\e[1;37m";
in
{
lib = {
mkHelp = { flake, name, system, writeScript, additionalCommands ? {}, supplementalNotes ? "" }:
let
appsHelp =
builtins.attrValues
(builtins.mapAttrs
(name: app: "${white}nix run .#${name}${nc}\t${app.description}")
flake.apps.${system});
additionalHelp =
builtins.attrValues
(builtins.mapAttrs
(command: description: "${white}${command}${nc}\t${description}")
additionalCommands);
# An awful hack, for now
rawFlake = import "${flake.outPath}/flake.nix";
in
writeScript "help" ''
echo '${name}: ${rawFlake.description}'
echo
echo 'APPS:'
echo
column -t -s $'\t' <(printf '${builtins.concatStringsSep "\n" appsHelp}') \
| while read -r line ; do printf "\t$line\n" ; done
echo
echo 'ADDITIONAL COMMANDS:'
echo
column -t -s $'\t' <(printf '${builtins.concatStringsSep "\n" additionalHelp}') \
| while read -r line ; do printf "\t$line\n" ; done
echo
printf '${supplementalNotes}'
'';
};
};
}