-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
156 lines (130 loc) · 4.99 KB
/
flake.nix
File metadata and controls
156 lines (130 loc) · 4.99 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
{
description = "Hugo site for odoom.net";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
# Paper theme package
paperTheme = pkgs.fetchFromGitHub {
owner = "nanxiaobei";
repo = "hugo-paper";
rev = "8c75cdd9ce53795675f7a54d431870eeac559665";
sha256 = "sha256-p/DFAfG6xAMUnKT0kB0wEu7FziDTcP2n//iJ+GZzb/U=";
};
# Build the Hugo site
site = pkgs.stdenv.mkDerivation rec {
name = "blog-odoom-net";
src = ./hugo-site;
buildInputs = [ pkgs.hugo pkgs.pagefind ];
buildPhase = ''
mkdir -p themes/paper
cp -r ${paperTheme}/* themes/paper/
export NIX_STORE_PATH="$out"
hugo --minify
pagefind --site public
'';
installPhase = ''
cp -r public $out
'';
};
in
{
packages.default = site;
apps.default = {
type = "app";
program = toString (pkgs.writeShellScript "serve" ''
# Build a local version with localhost baseURL
TMPDIR=$(mktemp -d)
cp -r ${./hugo-site}/* $TMPDIR/
chmod -R u+w $TMPDIR
mkdir -p $TMPDIR/themes/paper
cp -r ${paperTheme}/* $TMPDIR/themes/paper/
chmod -R u+w $TMPDIR/themes/paper
cd $TMPDIR
export NIX_STORE_PATH="${site}"
${pkgs.hugo}/bin/hugo --baseURL "http://localhost:8000" --minify
${pkgs.pagefind}/bin/pagefind --site public
echo "Serving blog.odoom.net locally on http://localhost:8000"
cd public
${pkgs.python3}/bin/python -m http.server 8000
'');
};
apps.deploy = {
type = "app";
program = toString (pkgs.writeShellScript "deploy" ''
set -euo pipefail
TAG="''${1:-latest}"
IMAGE="registry.fly.io/blog-odoom-net:$TAG"
echo "Building and deploying to Fly.io with tag: $TAG"
# Build the Hugo site with Nix first to get the store path
echo "Building Hugo site with Nix..."
STORE_PATH=$(${pkgs.nix}/bin/nix build --no-link --print-out-paths)
echo "Nix store path: $STORE_PATH"
# Build Docker image with the Nix store path as a build arg
${pkgs.docker}/bin/docker build --platform linux/amd64 \
--build-arg NIX_STORE_PATH="$STORE_PATH" \
-t "$IMAGE" ${./.}
# Push to Fly registry
${pkgs.docker}/bin/docker push "$IMAGE"
# Get digest
DIGEST=$(${pkgs.docker}/bin/docker inspect "$IMAGE" --format='{{index .RepoDigests 0}}' | cut -d'@' -f2)
# Deploy to Fly (run from project directory to pick up fly.toml)
cd ${./.}
${pkgs.flyctl}/bin/fly deploy --image "registry.fly.io/blog-odoom-net@$DIGEST"
echo "Deployment complete!"
'');
};
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
hugo
pagefind
go
flyctl
# Markdown linting and validation
markdownlint-cli
# Spell checking
aspell
aspellDicts.en
];
shellHook = ''
echo "Hugo dev environment"
echo "hugo version: $(hugo version)"
echo "pagefind version: $(pagefind --version)"
echo ""
# Update aspell word list from existing posts
if [ -f scripts/update-wordlist.sh ]; then
if [ ! -f .aspell.en.pws ] || [ hugo-site/content/post -nt .aspell.en.pws ]; then
echo "Updating spell check word list..."
bash scripts/update-wordlist.sh
fi
fi
# Install pre-commit hook
if [ -f hooks/pre-commit ] && [ ! -f .git/hooks/pre-commit ]; then
echo "Installing pre-commit hook..."
cp hooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
fi
# Clone Paper theme if not exists
if [ ! -d "hugo-site/themes/paper/.git" ]; then
echo "Cloning Paper theme..."
mkdir -p hugo-site/themes
git clone https://github.com/nanxiaobei/hugo-paper.git hugo-site/themes/paper
fi
echo "Building site and generating Pagefind index..."
cd hugo-site
hugo
pagefind --site public
echo "Copying Pagefind index to static/ for dev server..."
mkdir -p static/pagefind
cp -r public/pagefind/* static/pagefind/
echo "Starting Hugo server..."
hugo server
'';
};
}
);
}