From 4abac5363eba3e701343bfbde6afa0ce361ffab4 Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 3 Sep 2022 18:40:09 +0200 Subject: project: add nix flake GitHub: related to #285 --- flake.nix | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 flake.nix (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8ad216c --- /dev/null +++ b/flake.nix @@ -0,0 +1,134 @@ +# ldgallery - A static generator which turns a collection of tagged +# pictures into a searchable web gallery. +# +# Copyright (C) 2019-2022 Pacien TRAN-GIRARD +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +{ + description = '' + A static generator which turns a collection of tagged pictures into a \ + searchable web gallery. + ''; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs { inherit system; }; + ldgalleryVersion = "3.0.0-SNAPSHOT"; + + in rec { + packages = rec { + compiler = pkgs.haskell.lib.compose.overrideCabal (super: { + pname = "ldgallery-compiler"; + version = ldgalleryVersion; + + buildTools = (super.buildTools or []) ++ [ pkgs.makeWrapper ]; + + postInstall = '' + ${super.postInstall or ""} + + # wrapper for runtime dependencies registration + wrapProgram "$out/bin/ldgallery" \ + --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.imagemagick ]} + + # bash completion + mkdir -p "$out/share/bash-completion/completions" + "$out/bin/ldgallery" \ + --help=bash \ + > "$out/share/bash-completion/completions/ldgallery" + ''; + }) (pkgs.haskellPackages.callCabal2nix "" ./compiler { }); + + viewer = pkgs.mkYarnPackage { + pname = "ldgallery-viewer"; + version = ldgalleryVersion; + src = ./viewer; + + buildPhase = '' + # Make the node_module directory writable because ESLint and Webpack + # want to write in it during the build… + mv deps/ldgallery-viewer/node_modules{,links} + mkdir deps/ldgallery-viewer/node_modules + cp -r deps/ldgallery-viewer/node_modules{links/.bin,} + + export HOME=/build + yarn --offline run lint + yarn --offline run build + ''; + + installPhase = '' + mkdir -p $out/share/ldgallery + mv deps/ldgallery-viewer/dist $out/share/ldgallery/viewer + ''; + + doDist = false; # no need to generate a source tarball + }; + + man = pkgs.stdenv.mkDerivation { + pname = "ldgallery-man"; + version = ldgalleryVersion; + src = ./.; + + nativeBuildInputs = with pkgs; [ pandoc ]; + installPhase = '' + mkdir -p $out/share/man/man{1,7} + + pandoc --standalone --to man \ + "compiler/ldgallery.1.md" \ + --output "$out/share/man/man1/ldgallery.1" + + pandoc --standalone --to man \ + "viewer/ldgallery-viewer.7.md" \ + --output "$out/share/man/man7/ldgallery-viewer.7" + + pandoc --standalone --to man \ + "ldgallery-quickstart.7.md" \ + --output "$out/share/man/man7/ldgallery-quickstart.7" + ''; + }; + + # compiler + viewer + man pages bundle + ldgallery = pkgs.symlinkJoin { + name = "ldgallery"; + version = ldgalleryVersion; + paths = [ + man + (with pkgs.haskell.lib.compose; overrideCabal (super: { + prePatch = '' + # add viewer dist to compiler bundled resources + rm data/readme.md + ln -s "${viewer}/share/ldgallery/viewer" "data/" + ${super.prePatch or ""} + ''; + }) (justStaticExecutables compiler)) + ]; + }; + + default = ldgallery; + }; + + apps = rec { + ldgallery = flake-utils.lib.mkApp { + drv = packages.default; + }; + + default = ldgallery; + }; + }); +} -- cgit v1.2.3