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 --- .gitignore | 3 ++ flake.lock | 43 ++++++++++++++++++++ flake.nix | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index 2cdb78d..2f11fd8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ # editor and IDE .idea + +# Nix output symlinks +/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 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1662019588, + "narHash": "sha256-oPEjHKGGVbBXqwwL+UjsveJzghWiWV0n9ogo1X6l4cw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2da64a81275b68fdad38af669afeda43d401e94b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} 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