aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix185
1 files changed, 185 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..bb31db2
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,185 @@
1# ldgallery - A static generator which turns a collection of tagged
2# pictures into a searchable web gallery.
3#
4# Copyright (C) 2019-2023 Pacien TRAN-GIRARD
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Affero General Public License as
8# published by the Free Software Foundation, either version 3 of the
9# License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU Affero General Public License for more details.
15#
16# You should have received a copy of the GNU Affero General Public License
17# along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19{
20 description = "A static web gallery generator with tags";
21
22 inputs = {
23 nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
24 flake-utils.url = "github:numtide/flake-utils";
25 flaky-utils.url = "git+https://cgit.pacien.net/libs/flaky-utils";
26 };
27
28 outputs = { self, nixpkgs, flake-utils, flaky-utils }:
29 flake-utils.lib.eachDefaultSystem (system: let
30 pkgs = nixpkgs.legacyPackages.${system};
31 ldgalleryVersion = "2.3";
32 devTools = with pkgs; [
33 # generic
34 tmux
35
36 # viewer
37 nodejs-18_x
38 yarn
39
40 # compiler
41 stack
42 ];
43
44 in pkgs.lib.fold pkgs.lib.recursiveUpdate { } [
45 (rec {
46 packages = rec {
47 compiler = pkgs.haskell.lib.compose.overrideCabal (super: {
48 pname = "ldgallery-compiler";
49 version = ldgalleryVersion;
50
51 buildTools = (super.buildTools or []) ++ [ pkgs.makeWrapper ];
52
53 postInstall = ''
54 ${super.postInstall or ""}
55
56 # wrapper for runtime dependencies registration
57 wrapProgram "$out/bin/ldgallery" \
58 --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.imagemagick ]}
59
60 # bash completion
61 mkdir -p "$out/share/bash-completion/completions"
62 "$out/bin/ldgallery" \
63 --help=bash \
64 > "$out/share/bash-completion/completions/ldgallery"
65 '';
66 }) (pkgs.haskellPackages.callCabal2nix "" ./compiler { });
67
68 viewer = pkgs.mkYarnPackage {
69 pname = "ldgallery-viewer";
70 version = ldgalleryVersion;
71 src = ./viewer;
72
73 buildPhase = ''
74 # Make the node_module directory writable because ESLint and Webpack
75 # want to write in it during the build…
76 mv deps/ldgallery-viewer/node_modules{,links}
77 mkdir deps/ldgallery-viewer/node_modules
78 cp -r deps/ldgallery-viewer/node_modules{links/.bin,}
79
80 export HOME=/build
81 yarn --offline run lint
82 yarn --offline run build
83 '';
84
85 installPhase = ''
86 mkdir -p $out/share/ldgallery
87 mv deps/ldgallery-viewer/dist $out/share/ldgallery/viewer
88 '';
89
90 doDist = false; # no need to generate a source tarball
91 };
92
93 man = pkgs.stdenv.mkDerivation {
94 pname = "ldgallery-man";
95 version = ldgalleryVersion;
96 src = ./.;
97
98 nativeBuildInputs = with pkgs; [ pandoc ];
99 installPhase = ''
100 mkdir -p $out/share/man/man{1,7}
101
102 pandoc --standalone --to man \
103 "compiler/ldgallery.1.md" \
104 --output "$out/share/man/man1/ldgallery.1"
105
106 pandoc --standalone --to man \
107 "viewer/ldgallery-viewer.7.md" \
108 --output "$out/share/man/man7/ldgallery-viewer.7"
109
110 pandoc --standalone --to man \
111 "ldgallery-quickstart.7.md" \
112 --output "$out/share/man/man7/ldgallery-quickstart.7"
113 '';
114 };
115
116 # compiler + viewer + man pages bundle
117 ldgallery = pkgs.symlinkJoin {
118 name = "ldgallery";
119 version = ldgalleryVersion;
120 paths = [
121 man
122 (with pkgs.haskell.lib.compose; overrideCabal (super: {
123 prePatch = ''
124 # add viewer dist to compiler bundled resources
125 rm data/readme.md
126 ln -s "${viewer}/share/ldgallery/viewer" "data/"
127 ${super.prePatch or ""}
128 '';
129 }) (justStaticExecutables compiler))
130 ];
131 };
132
133 example = pkgs.stdenv.mkDerivation {
134 pname = "ldgallery-example";
135 version = ldgalleryVersion;
136 src = ./example;
137 nativeBuildInputs = [ ldgallery ];
138 buildPhase = ''
139 # Need UTF-8: https://github.com/ldgallery/ldgallery/issues/341
140 export LC_ALL=C.UTF-8
141 ldgallery --input-dir src --output-dir $out --with-viewer
142 '';
143 installPhase = ":";
144 };
145
146 default = ldgallery;
147 };
148
149 apps = rec {
150 ldgallery = flake-utils.lib.mkApp {
151 drv = packages.default;
152 };
153
154 default = ldgallery;
155 };
156
157 devShell = flaky-utils.lib.mkDevShell {
158 inherit pkgs;
159 tools = devTools;
160 shell = null;
161 };
162 })
163
164 (flaky-utils.lib.mkSandboxSystem {
165 inherit pkgs;
166 restrictNetwork = false;
167 patchQemu9p = true;
168 tools = devTools;
169 envVars = {
170 # File modification watch doesn't work through the VM for live reload.
171 VUE_APP_WEBPACK_WATCH_POLL = "1000";
172 };
173 config = {
174 # The viewer's build and devel server are resource-hungry.
175 virtualisation.cores = 2;
176 virtualisation.memorySize = 2 * 1024;
177
178 virtualisation.forwardPorts = [
179 { from = "host"; host.port = 8085; guest.port = 8085; } # vue-cli
180 ];
181 };
182 })
183
184 ]);
185}