-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
117 lines (93 loc) · 3.31 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
{
description = "m32's static personal website";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs = inputs@{ self, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" ];
perSystem = { pkgs, self', ... }: {
packages = with pkgs; rec {
# * The static website files as a package
static = stdenv.mkDerivation rec {
pname = "m32.io-static";
version = "${self.shortRev or self.dirtyShortRev}";
src = self;
buildInputs = with pkgs; [
zola
tailwindcss
# Perl
perl
perlPackages.GitRepository
perlPackages.Git
git
perlPackages.CPAN
perlPackages.RESTClient
perlPackages.YAML
perlPackages.DataDumper
];
phases = [ "unpackPhase" "configurePhase" "buildPhase" "installPhase" ];
configurePhase = ''
export PATH="$PATH:${pkgs.lib.makeBinPath buildInputs}"
cp ${self'.packages.data-file} .nix-data.json
'';
buildPhase = ''
tailwindcss -i sass/style.scss -o static/styles/main.css
zola build
'';
installPhase = ''
mkdir -p $out
cp -r ./public/* $out
'';
};
data-file = writeText "nix-data.json"
(builtins.toJSON { inherit (self.sourceInfo) lastModified lastModifiedDate;
rev = self.sourceInfo.rev or self.sourceInfo.dirtyRev;
shortRev = self.sourceInfo.shortRev or self.sourceInfo.dirtyShortRev;
});
dev-server = writeShellScript "dev-server"
''
#!/bin/sh
fetch_data () {
cp $(${pkgs.nix}/bin/nix build .#data-file --no-link --print-out-paths) $PWD/.nix-data.json
}
cleanup () {
local pids=$(jobs -pr)
[ -n $pids ] && kill $pids
}
echo "Building and linking nix data file"
fetch_data
echo "Starting Tailwind watch process"
${pkgs.tailwindcss}/bin/tailwindcss -i sass/style.scss -o static/styles/main.css --watch &
sleep 2
echo "Starting Zola watch process"
${pkgs.zola}/bin/zola serve &
while true; do
fetch_data
sleep 10
done;
trap "cleanup" SIGINT SIGTERM EXIT
'';
default = static;
};
apps.default = {
type = "app";
program = "${self'.packages.dev-server}";
};
devShells.default = with pkgs;
mkShell {
nativeBuildInputs = [
rlwrap
perlPackages.PerlLanguageServer
xq
tree
git
] ++ self'.packages.static.buildInputs;
};
};
};
nixConfig = {
extra-experimental-features = "nix-command flakes recursive-nix";
};
}