aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2022-09-03 18:40:09 +0200
committerpacien2022-09-03 20:51:35 +0200
commit4abac5363eba3e701343bfbde6afa0ce361ffab4 (patch)
treeacdce58b0d604c58f394cd40e730ef45459a084c
parent52bf3327a12bef850bd3558ed98a9293db8e6bc7 (diff)
downloadldgallery-4abac5363eba3e701343bfbde6afa0ce361ffab4.tar.gz
project: add nix flake
GitHub: related to #285
-rw-r--r--.gitignore3
-rw-r--r--flake.lock43
-rw-r--r--flake.nix134
3 files changed, 180 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 2cdb78d..2f11fd8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,6 @@
4 4
5# editor and IDE 5# editor and IDE
6.idea 6.idea
7
8# Nix output symlinks
9/result*
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..45b4c6d
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,43 @@
1{
2 "nodes": {
3 "flake-utils": {
4 "locked": {
5 "lastModified": 1659877975,
6 "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
7 "owner": "numtide",
8 "repo": "flake-utils",
9 "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
10 "type": "github"
11 },
12 "original": {
13 "owner": "numtide",
14 "repo": "flake-utils",
15 "type": "github"
16 }
17 },
18 "nixpkgs": {
19 "locked": {
20 "lastModified": 1662019588,
21 "narHash": "sha256-oPEjHKGGVbBXqwwL+UjsveJzghWiWV0n9ogo1X6l4cw=",
22 "owner": "NixOS",
23 "repo": "nixpkgs",
24 "rev": "2da64a81275b68fdad38af669afeda43d401e94b",
25 "type": "github"
26 },
27 "original": {
28 "owner": "NixOS",
29 "ref": "nixos-unstable",
30 "repo": "nixpkgs",
31 "type": "github"
32 }
33 },
34 "root": {
35 "inputs": {
36 "flake-utils": "flake-utils",
37 "nixpkgs": "nixpkgs"
38 }
39 }
40 },
41 "root": "root",
42 "version": 7
43}
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}