-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.nix
61 lines (55 loc) · 1.81 KB
/
shell.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
51
52
53
54
55
56
57
58
59
60
61
{ pkgs ? import <nixpkgs> { }
, system ? builtins.currentSystem
, devshell ? import (fetchTarball "https://github.com/numtide/devshell/archive/master.tar.gz") { inherit system; }
}:
let
inherit (pkgs)
writeShellApplication
pandoc
jq
curl
;
# Writes my-file to /nix/store/<store path>/bin/my-file and makes executable.
update-readme = writeShellApplication {
name = "update-readme";
runtimeInputs = [ jq curl pandoc ];
text = ''
# Generate a personal access token and export it as PRIVATE_BEARER_TOKEN:
[ -e /tmp/dotfield-readme-update-access-token.txt ] && bearer_token="$(cat /tmp/dotfield-readme-update-access-token.txt)"
pandoc docs/README.org -f org -t gfm -o /tmp/README.md --table-of-contents -s
pandoc /tmp/README.md -f gfm -t html5 -o /tmp/README.html
repo_id=234254
# And the readme file:
readme=/tmp/README.html
# Set the repository's README
jq -sR '{
"query": "mutation UpdateRepo($id: Int!, $readme: String!) {
updateRepository(id: $id, input: { readme: $readme }) { id }
}", "variables": {
"id": '$repo_id',
"readme": .
} }' < $readme \
| curl --oauth2-bearer "$bearer_token" \
-H "Content-Type: application/json" \
-d@- https://git.sr.ht/query
echo
echo "Updated project README with $(wc -l < "$readme") lines"
'';
};
in
devshell.mkShell {
commands = [
{
name = "cachix-develop";
category = "utils";
command = "cachix watch-exec virtual-dts-mode nix -- develop";
help = "Build devshell and push to cachix";
}
{
name = "update-readme";
category = "utils";
package = update-readme;
help = "Convert the README.org to HTML and update the sourcehut README";
}
];
}