Skip to content

Commit

Permalink
chore: Add Nix flakes file for documentation building.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Sep 24, 2022
1 parent 88e92b6 commit 3f90ed6
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
use flake github:loophp/nix-auto-changelog
use flake github:loophp/nix-shell#env-php81-nts --impure
use flake
43 changes: 43 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 109 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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;
};
};
});
}

0 comments on commit 3f90ed6

Please sign in to comment.