-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflake.nix
157 lines (139 loc) · 4.65 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
{
description = "The source behind msfjarvis.dev";
inputs.nixpkgs.url = "github:msfjarvis/nixpkgs/nixpkgs-unstable";
inputs.systems.url = "github:msfjarvis/flake-systems";
inputs.devshell.url = "github:numtide/devshell";
inputs.devshell.inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-compat.url = "github:nix-community/flake-compat";
inputs.flake-compat.flake = false;
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.flake-utils.inputs.systems.follows = "systems";
outputs =
{
self,
devshell,
flake-utils,
nixpkgs,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ devshell.overlays.default ];
};
in
{
devShell = pkgs.devshell.mkShell {
name = "blog-dev-shell";
bash = {
interactive = "";
};
packages = with pkgs; [
dprint
git
go
hugo
hyperlink
libwebp
];
commands = [
{
name = "build";
category = "deployment";
command = "hugo";
help = "Build the site";
}
{
name = "conv";
category = "development";
command = ''
DIR=content/posts
fd -tf png$ "$DIR" -x cwebp -lossless -mt {} -o '{.}.webp'
fd -tf png$ "$DIR" -X rm -v
'';
help = "Convert all PNGs to WebP";
}
{
name = "dev";
category = "development";
command = "hugo server -D";
help = "Run the Hugo development server";
}
{
name = "fmt";
category = "development";
command = "dprint fmt";
help = "Format this repository";
}
{
name = "diffs";
category = "development";
command = ''
OLD_DIR=$(mktemp -d)
NEW_DIR=$(mktemp -d)
# Build the current working directory
build
# Relocate the outputs to `$NEW_DIR`
cp -rT public/ $NEW_DIR/
git stash
# Stash any changes
git stash || true
# Checkout the remote main branch for baseline
git checkout origin/main
# Build the baseline
build
# Relocate site to `$OLD_DIR`
cp -rT public/ $OLD_DIR/
# Revert to the default branch
git checkout main
git stash pop
# Pop any potentially stashed changes
git stash pop || true
# Launch meld with the `$OLD_DIR` and `$NEW_DIR` directories to diff them
${pkgs.lib.getExe pkgs.meld} $OLD_DIR $NEW_DIR
# Clean up the temporary folders when `meld` exits
rm -rf $OLD_DIR $NEW_DIR
'';
help = "Launch meld to diff between the `old` and `new` folders";
}
{
name = "new";
category = "development";
command = ''
set -euo pipefail
function create_post() {
local title postslug postdate
if [ $# -lt 1 ]; then
echo -e "\033[01;31mProviding a title is a must!\033[0m"
return
else
title="''${*}"
fi
postdate="$(date +"%Y-%m-%dT%H:%M:%S%:z")"
postslug="$(echo "$title" | tr -dc '[:alnum:][:space:]\n\r' | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g')"
[ -z "$postslug" ] && {
echo -e "\033[01;31mProviding a title is a must!\033[0m"
return
}
mkdir -p content/posts/"$postslug"
printf "+++\ncategories = []\ndate = %s\nlastmod = %s\nsummary = \"\"\ndraft = true\nslug = \"%s\"\ntags = []\ntitle = \"%s\"\n+++\n" \
"$postdate" "$postdate" "$postslug" "$title" >content/posts/"$postslug"/index.md
echo "content/posts/$postslug created!"
}
create_post "''${@}"
'';
help = "Create new post";
}
];
env = [
{
name = "DEVSHELL_NO_MOTD";
value = 1;
}
];
};
}
);
}