diff options
Diffstat (limited to 'flake.nix')
-rw-r--r-- | flake.nix | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8ad216c --- /dev/null +++ b/flake.nix | |||
@@ -0,0 +1,134 @@ | |||
1 | # ldgallery - A static generator which turns a collection of tagged | ||
2 | # pictures into a searchable web gallery. | ||
3 | # | ||
4 | # Copyright (C) 2019-2022 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 = '' | ||
21 | A static generator which turns a collection of tagged pictures into a \ | ||
22 | searchable web gallery. | ||
23 | ''; | ||
24 | |||
25 | inputs = { | ||
26 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | ||
27 | flake-utils.url = "github:numtide/flake-utils"; | ||
28 | }; | ||
29 | |||
30 | outputs = { self, nixpkgs, flake-utils }: | ||
31 | flake-utils.lib.eachDefaultSystem (system: let | ||
32 | pkgs = import nixpkgs { inherit system; }; | ||
33 | ldgalleryVersion = "3.0.0-SNAPSHOT"; | ||
34 | |||
35 | in rec { | ||
36 | packages = rec { | ||
37 | compiler = pkgs.haskell.lib.compose.overrideCabal (super: { | ||
38 | pname = "ldgallery-compiler"; | ||
39 | version = ldgalleryVersion; | ||
40 | |||
41 | buildTools = (super.buildTools or []) ++ [ pkgs.makeWrapper ]; | ||
42 | |||
43 | postInstall = '' | ||
44 | ${super.postInstall or ""} | ||
45 | |||
46 | # wrapper for runtime dependencies registration | ||
47 | wrapProgram "$out/bin/ldgallery" \ | ||
48 | --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.imagemagick ]} | ||
49 | |||
50 | # bash completion | ||
51 | mkdir -p "$out/share/bash-completion/completions" | ||
52 | "$out/bin/ldgallery" \ | ||
53 | --help=bash \ | ||
54 | > "$out/share/bash-completion/completions/ldgallery" | ||
55 | ''; | ||
56 | }) (pkgs.haskellPackages.callCabal2nix "" ./compiler { }); | ||
57 | |||
58 | viewer = pkgs.mkYarnPackage { | ||
59 | pname = "ldgallery-viewer"; | ||
60 | version = ldgalleryVersion; | ||
61 | src = ./viewer; | ||
62 | |||
63 | buildPhase = '' | ||
64 | # Make the node_module directory writable because ESLint and Webpack | ||
65 | # want to write in it during the build… | ||
66 | mv deps/ldgallery-viewer/node_modules{,links} | ||
67 | mkdir deps/ldgallery-viewer/node_modules | ||
68 | cp -r deps/ldgallery-viewer/node_modules{links/.bin,} | ||
69 | |||
70 | export HOME=/build | ||
71 | yarn --offline run lint | ||
72 | yarn --offline run build | ||
73 | ''; | ||
74 | |||
75 | installPhase = '' | ||
76 | mkdir -p $out/share/ldgallery | ||
77 | mv deps/ldgallery-viewer/dist $out/share/ldgallery/viewer | ||
78 | ''; | ||
79 | |||
80 | doDist = false; # no need to generate a source tarball | ||
81 | }; | ||
82 | |||
83 | man = pkgs.stdenv.mkDerivation { | ||
84 | pname = "ldgallery-man"; | ||
85 | version = ldgalleryVersion; | ||
86 | src = ./.; | ||
87 | |||
88 | nativeBuildInputs = with pkgs; [ pandoc ]; | ||
89 | installPhase = '' | ||
90 | mkdir -p $out/share/man/man{1,7} | ||
91 | |||
92 | pandoc --standalone --to man \ | ||
93 | "compiler/ldgallery.1.md" \ | ||
94 | --output "$out/share/man/man1/ldgallery.1" | ||
95 | |||
96 | pandoc --standalone --to man \ | ||
97 | "viewer/ldgallery-viewer.7.md" \ | ||
98 | --output "$out/share/man/man7/ldgallery-viewer.7" | ||
99 | |||
100 | pandoc --standalone --to man \ | ||
101 | "ldgallery-quickstart.7.md" \ | ||
102 | --output "$out/share/man/man7/ldgallery-quickstart.7" | ||
103 | ''; | ||
104 | }; | ||
105 | |||
106 | # compiler + viewer + man pages bundle | ||
107 | ldgallery = pkgs.symlinkJoin { | ||
108 | name = "ldgallery"; | ||
109 | version = ldgalleryVersion; | ||
110 | paths = [ | ||
111 | man | ||
112 | (with pkgs.haskell.lib.compose; overrideCabal (super: { | ||
113 | prePatch = '' | ||
114 | # add viewer dist to compiler bundled resources | ||
115 | rm data/readme.md | ||
116 | ln -s "${viewer}/share/ldgallery/viewer" "data/" | ||
117 | ${super.prePatch or ""} | ||
118 | ''; | ||
119 | }) (justStaticExecutables compiler)) | ||
120 | ]; | ||
121 | }; | ||
122 | |||
123 | default = ldgallery; | ||
124 | }; | ||
125 | |||
126 | apps = rec { | ||
127 | ldgallery = flake-utils.lib.mkApp { | ||
128 | drv = packages.default; | ||
129 | }; | ||
130 | |||
131 | default = ldgallery; | ||
132 | }; | ||
133 | }); | ||
134 | } | ||