-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
94 lines (85 loc) · 2.92 KB
/
flake.nix
File metadata and controls
94 lines (85 loc) · 2.92 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
# Nix flake, see: https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11"; # Nix package repository
utils.url = "github:numtide/flake-utils"; # Flake utility functions
# Zola theme.
zola-theme = {
url = "github:opeik/zola-theme-terminimal";
flake = false;
};
};
outputs = {
self,
nixpkgs,
utils,
zola-theme,
}:
utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
# Our zola theme!
theme = {
name = "terminimal";
src = pkgs.stdenv.mkDerivation {
name = theme.name;
src = zola-theme;
installPhase = ''
mkdir --parents $out/themes/${theme.name}
cp --verbose --recursive . $out/themes/${theme.name}
'';
};
};
in {
packages = {
# `nix run .#serve`
serve = pkgs.writeShellScriptBin "serve" "${pkgs.zola}/bin/zola serve --drafts";
# `nix build .#website`
website = pkgs.stdenv.mkDerivation {
name = "website";
src = builtins.path {
path = ./.;
name = "website-src";
# Only include files which can affect the website output to prevent frivolous rebuilds.
filter = path: type:
(
x:
builtins.any (file: pkgs.lib.hasSuffix file x) ["config.toml"]
|| builtins.any (dir: pkgs.lib.hasInfix dir x) ["content" "static" "templates"]
)
path;
};
configurePhase = ''
echo 'installing theme...'
# Reset the file permissions since they'll be read-only from being in the Nix store.
cp --recursive --no-preserve=mode "${theme.src}"/* .
'';
buildPhase = let
version = pkgs.lib.strings.removeSuffix "-dirty" (self.rev or self.dirtyRev or "unknown");
in ''
echo 'adding version to `config.toml`'
sed -i '/\[extra\]/a version = "${version}"' config.toml
echo 'building website...'
${pkgs.zola}/bin/zola build
echo 'formatting output...'
${pkgs.nodePackages_latest.prettier}/bin/prettier --bracket-same-line true --write public
echo 'stripping empty lines from output html...'
find public -type f -name '*.html' -printf 'stripped file: %p\n' -exec sed -i '/^$/d' {} +
'';
installPhase = "cp --recursive public $out";
};
};
# `nix develop`
devShell = pkgs.mkShell {
buildInputs = [
self.formatter.${system}
pkgs.zola
];
shellHook = ''
mkdir --parents themes
# ln --symbolic --force --no-dereference ${theme.src} themes/${theme.name}
'';
};
# `nix fmt`
formatter = pkgs.alejandra;
});
}