From 3f90ed66261cd4c0f58d180f73b6a7b79fa2f8c9 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Sat, 24 Sep 2022 18:39:07 +0200 Subject: [PATCH] chore: Add Nix flakes file for documentation building. --- .envrc | 1 + flake.lock | 43 +++++++++++++++++++++ flake.nix | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc index aacea67bb..370ffa040 100644 --- a/.envrc +++ b/.envrc @@ -1,2 +1,3 @@ use flake github:loophp/nix-auto-changelog use flake github:loophp/nix-shell#env-php81-nts --impure +use flake diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..a51f01d8c --- /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": 1663905476, + "narHash": "sha256-0CSwRKaYravh9v6qSlBpM0gNg0UhKT2lL7Yn6Zbx7UM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e14f9fb57315f0d4abde222364f19f88c77d2b79", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-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 000000000..2394a1681 --- /dev/null +++ b/flake.nix @@ -0,0 +1,109 @@ +{ + description = "loophp/collection"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }@inputs: + with flake-utils.lib; eachSystem allSystems (system: + let + version = self.shortRev or self.lastModifiedDate; + + pkgs = import nixpkgs { + inherit system; + config = { + allowUnfreePredicate = (pkg: true); + }; + }; + + tex = pkgs.texlive.combine { + inherit (pkgs.texlive) scheme-full latex-bin latexmk; + }; + + sphinx-build = + let + env = pkgs.python3.withPackages (pp: with pp; [ + sphinx + sphinx-autobuild + sphinx_rtd_theme + sphinxcontrib-spelling + recommonmark + pyenchant + ]); + in + # Expose only the sphinx-build binary to avoid contaminating + # everything with Sphinx’s Python environment. + pkgs.runCommand "sphinx-build" { } '' + mkdir -p "$out/bin" + ln -s "${env}/bin/sphinx-autobuild" "$out/bin" + ln -s "${env}/bin/sphinx-build" "$out/bin" + ln -s "${env}/bin/sphinx-apidoc" "$out/bin" + ln -s "${env}/bin/sphinx-autogen" "$out/bin" + ln -s "${env}/bin/sphinx-quickstart" "$out/bin" + ''; + + documentProperties = { + name = "loophp-collection"; + inputs = [ + tex + sphinx-build + ]; + }; + + pdf = pkgs.stdenv.mkDerivation { + name = documentProperties.name + "-documentation-pdf"; + + src = self; + + nativeBuildInputs = documentProperties.inputs; + + buildPhase = '' + sphinx-build -M latexpdf ./docs tmp + ''; + + installPhase = '' + install -m 0644 -vD tmp/latex/documentation.pdf $out + ''; + }; + + wrapper-autobuild = pkgs.writeScriptBin "autobuild" '' + ${sphinx-build}/bin/sphinx-autobuild ./docs build/docs + ''; + + autobuild = pkgs.stdenv.mkDerivation { + name = documentProperties.name + "-documentation-autobuild"; + + src = self; + + buildInputs = [ wrapper-autobuild ]; + + nativeBuildInputs = documentProperties.inputs; + + installPhase = '' + mkdir -p $out/bin + cp -r ${wrapper-autobuild}/bin/* $out/bin/ + ''; + }; + + in + rec { + # nix run + apps.default = flake-utils.lib.mkApp { drv = autobuild; }; + + # nix shell, nix build + packages = { + pdf = pdf; + default = self.packages.${system}.pdf; + }; + + # nix develop + devShells = { + default = pkgs.mkShellNoCC { + name = documentProperties.name; + buildInputs = documentProperties.inputs; + }; + }; + }); +}