forked from github/personal-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
141 lines (131 loc) · 4.03 KB
/
Copy pathflake.nix
File metadata and controls
141 lines (131 loc) · 4.03 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
{
description = "Daniel Woffinden's personal site built with Zola";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
git-hooks.url = "github:cachix/git-hooks.nix";
git-hooks.inputs.nixpkgs.follows = "nixpkgs";
flint.url = "github:notashelf/flint";
flint.inputs.nixpkgs.follows = "nixpkgs";
zola-hallo = {
url = "git+https://codeberg.org/janbaudisch/zola-hallo?lfs=1";
flake = false;
};
font-awesome = {
url = "github:FortAwesome/Font-Awesome";
flake = false;
};
};
outputs =
{
self,
nixpkgs,
git-hooks,
flint,
zola-hallo,
font-awesome,
...
}:
let
forEachSystem = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
pkgsFor = system: nixpkgs.legacyPackages.${system};
# TODO: read the toml for the theme name
# https://ilanjoselevich.com/blog/building-websites-using-nix-flakes-and-zola
themeName = "hallo";
copyTheme = ''
mkdir -p themes
rm -rf themes/${themeName}
cp -r --no-preserve=mode,ownership ${zola-hallo} themes/${themeName}
rm -rf themes/${themeName}/static/fontawesome
'';
copyIcons = ''
rm -rf fa-svgs
mkdir -p fa-svgs
cp --no-preserve=mode,ownership \
${font-awesome}/svgs/{brands/{github,facebook,keybase,linkedin,stack-overflow,matrix},solid/{key,code,copy,check}}.svg \
fa-svgs/
'';
in
{
packages = forEachSystem (
system:
let
pkgs = pkgsFor system;
in
{
default = pkgs.stdenv.mkDerivation {
name = "dwoffinden-github-io";
src = ./.;
nativeBuildInputs = [ pkgs.zola ];
buildPhase = ''
${copyTheme}
${copyIcons}
zola build
rm public/{,images/}portrait.jpg
rmdir public/images
'';
installPhase = ''
cp -r public $out
'';
};
}
);
checks = forEachSystem (system: {
pre-commit-check = git-hooks.lib.${system}.run {
src = ./.;
hooks = {
mdformat.enable = true;
nixfmt.enable = true;
flint = {
enable = true;
name = "flint";
entry = "${flint.packages.${system}.default}/bin/flint --fail-if-multiple-versions";
files = "flake\\.(nix|lock)$";
};
yamlfmt = {
enable = true;
settings.lint-only = false;
};
};
};
});
formatter = forEachSystem (
system:
let
pkgs = pkgsFor system;
config = self.checks.${system}.pre-commit-check.config;
script = ''
${pkgs.lib.getExe config.package} run --all-files --config ${config.configFile}
'';
in
pkgs.writeShellScriptBin "pre-commit-run" script
);
devShells = forEachSystem (
system:
let
pkgs = pkgsFor system;
pre-commit-check = self.checks.${system}.pre-commit-check;
in
{
default = pkgs.mkShell {
buildInputs = pre-commit-check.enabledPackages;
packages = [
pkgs.zola
flint.packages.${system}.default
];
shellHook = ''
${pre-commit-check.shellHook}
if [[ ! -f themes/${themeName}/.source-path ]] || [[ "$(cat themes/${themeName}/.source-path)" != "${zola-hallo}" ]]; then
${copyTheme}
echo "${zola-hallo}" > themes/${themeName}/.source-path
fi
if [[ ! -f fa-svgs/.source-path ]] || [[ "$(cat fa-svgs/.source-path)" != "$(echo -e "${font-awesome}")" ]]; then
${copyIcons}
echo -e "${font-awesome}" > fa-svgs/.source-path
fi
echo "Zola dev shell loaded. Run 'zola serve' to start."
'';
};
}
);
};
}