-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathflake.nix
More file actions
161 lines (142 loc) · 4.88 KB
/
flake.nix
File metadata and controls
161 lines (142 loc) · 4.88 KB
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
158
159
160
161
{
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 = "git+https://git.lix.systems/lix-project/flake-compat";
inputs.flake-compat.flake = false;
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.flake-utils.inputs.systems.follows = "systems";
inputs.treefmt-nix.url = "github:numtide/treefmt-nix";
inputs.treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
outputs =
{
devshell,
flake-utils,
nixpkgs,
treefmt-nix,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ devshell.overlays.default ];
};
in
{
formatter =
let
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
treefmtEval.config.build.wrapper;
devShell = pkgs.devshell.mkShell {
name = "blog-dev-shell";
bash = {
interactive = "";
};
packages = with pkgs; [
git
go
hugo
hyperlink
libwebp
pagefind
];
commands = [
{
name = "build";
category = "deployment";
command = "hugo --gc -D && pagefind --site public";
help = "Build the site";
}
{
name = "conv";
category = "development";
command = ''
DIR=content/posts
for fmt in png jpg jpeg; do
fd -tf "''${fmt}$" "$DIR" -x cwebp -lossless -mt {} -o '{.}.webp'
fd -tf "''${fmt}$" "$DIR" -X rm -v
done
'';
help = "Convert all PNGs to WebP";
}
{
name = "dev";
category = "development";
command = "hugo -D serve";
help = "Run the Hugo development server";
}
{
name = "diffs";
category = "development";
command = ''
set -x
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
# 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;
}
];
};
}
);
}