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 From 79fd9e8be8618d69ebb9e50d82aa0eccac05a4e7 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 4 Sep 2022 14:28:52 +0200 Subject: flake: add useful commands to readme --- flake.nix | 5 +---- readme.md | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/flake.nix b/flake.nix index 8ad216c..36c1b4a 100644 --- a/flake.nix +++ b/flake.nix @@ -17,10 +17,7 @@ # along with this program. If not, see . { - description = '' - A static generator which turns a collection of tagged pictures into a \ - searchable web gallery. - ''; + description = "A static web gallery generator with tags"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; diff --git a/readme.md b/readme.md index 1fede70..6cd7396 100644 --- a/readme.md +++ b/readme.md @@ -1,13 +1,34 @@ ldgallery ========= -A static gallery generator which turns a collection of tagged pictures and media into a searchable web gallery. +A static gallery generator which turns a collection of tagged pictures and +media into a searchable web gallery. -The complete list of features, the user manual, demo and download links can be found on the project's website: https://ldgallery.pacien.org. +The complete list of features, the user manual, demo and download links can be +found on the project's website: . -Build ------ +Usage and build (using the Nix Flake) +------------------------------------- + +This program is available as a Nix Flake allowing to build both the viewer +and compiler components and assemble those automatically. + +The following commands are available on NixOS, or a Linux or MacOS system +having the Nix package manager installed: + +* Just running the program (compiler with bundled viewer): + * Using the latest release: `nix run github:ldgallery/ldgallery -- --help` + * Using a local source checkout: `nix run .# -- --help` + +* Building individual components locally: + `nix build .#{compiler,viewer,man} --print-build-logs` + + +Manual build +------------ + +Without using the Nix Flake, the project can be built as follows: * Compile the web _viewer_ as detailed in `./viewer/readme.md`. * Copy/link the compiled _viewer_ to the _ldgallery compiler_ data directory. -- cgit v1.2.3