Skip to content

Commit 67196c1

Browse files
committed
Add Nix package for QGIS Documentation
1 parent bad0567 commit 67196c1

File tree

3 files changed

+285
-0
lines changed

3 files changed

+285
-0
lines changed

flake.lock

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
description = "QGIS Documentation";
3+
4+
# nixConfig = {
5+
# extra-substituters = [ "https://example.cachix.org" ];
6+
# extra-trusted-public-keys = [ "example.cachix.org-1:xxxx=" ];
7+
# };
8+
9+
inputs = {
10+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
11+
};
12+
13+
outputs = { self, nixpkgs }:
14+
15+
let
16+
# Flake system
17+
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
18+
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
19+
nixpkgsFor = forAllSystems (system: import nixpkgs {
20+
inherit system;
21+
config.allowUnfree = true;
22+
});
23+
24+
in
25+
{
26+
#
27+
### PACKAGES
28+
#
29+
30+
packages = forAllSystems (system:
31+
let
32+
pkgs = nixpkgsFor.${system};
33+
34+
in
35+
{
36+
website = pkgs.callPackage ./package.nix { };
37+
});
38+
39+
40+
#
41+
### APPS
42+
#
43+
44+
apps = forAllSystems (system:
45+
let
46+
pkgs = nixpkgsFor.${system};
47+
inherit (nixpkgs) lib;
48+
49+
wwwLauncher = pkgs.writeShellApplication {
50+
name = "website";
51+
runtimeInputs = [ pkgs.python3 ];
52+
text = ''
53+
exec ${lib.getExe pkgs.python3} \
54+
-m http.server 8000 \
55+
-d ${self.packages.${system}.website}/
56+
'';
57+
};
58+
59+
in
60+
{
61+
default = {
62+
type = "app";
63+
program = "${wwwLauncher}/bin/website";
64+
};
65+
});
66+
67+
68+
#
69+
### SHELLS
70+
#
71+
72+
devShells = forAllSystems (system:
73+
let
74+
pkgs = nixpkgsFor.${system};
75+
76+
pythonPackages = pkgs.python3Packages;
77+
in
78+
{
79+
# Development environment
80+
default = pkgs.mkShell {
81+
name = "impurePythonEnv";
82+
venvDir = "./.venv";
83+
buildInputs = [
84+
# A Python interpreter including the 'venv' module is required to bootstrap
85+
# the environment.
86+
pythonPackages.python
87+
88+
# This executes some shell code to initialize a venv in $venvDir before
89+
# dropping into the shell
90+
pythonPackages.venvShellHook
91+
pkgs.vscode
92+
pkgs.transifex-cli
93+
94+
# Those are dependencies that we would like to use from nixpkgs, which will
95+
# add them to PYTHONPATH and thus make them accessible from within the venv.
96+
];
97+
98+
# Run this command, only after creating the virtual environment
99+
postVenvCreation = ''
100+
export DIRENV_LOG_FORMAT=
101+
unset SOURCE_DATE_EPOCH
102+
pip install -r REQUIREMENTS.txt
103+
echo "-----------------------"
104+
echo "🌈 Your Dev Environment is prepared."
105+
echo "📒 Note:"
106+
echo "-----------------------"
107+
echo "start vscode like this:"
108+
echo ""
109+
echo "./vscode.sh"
110+
echo "-----------------------"
111+
'';
112+
113+
# Now we can execute any commands within the virtual environment.
114+
# This is optional and can be left out to run pip manually.
115+
postShellHook = ''
116+
# allow pip to install wheels
117+
unset SOURCE_DATE_EPOCH
118+
'';
119+
};
120+
});
121+
};
122+
}

package.nix

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{ lib
2+
, stdenv
3+
, fetchFromGitHub
4+
, fetchurl
5+
6+
, python3Packages
7+
}:
8+
9+
let
10+
sphinxext-rediraffe = python3Packages.buildPythonPackage rec {
11+
pname = "sphinxext-rediraffe";
12+
version = "0.2.7";
13+
pyproject = true;
14+
15+
src = fetchFromGitHub {
16+
owner = "sphinx-doc";
17+
repo = "sphinxext-rediraffe";
18+
rev = "refs/tags/v${version}";
19+
hash = "sha256-g+GD1ApD26g6PwPOH/ir7aaEgH+n1QQYSr9QizYrmug=";
20+
};
21+
22+
# Fix "packaging.version.InvalidVersion: Invalid version: 'main'"
23+
postPatch = ''
24+
substituteInPlace "setup.py" \
25+
--replace-fail 'version = "main"' 'version = "${version}"'
26+
'';
27+
28+
build-system = with python3Packages; [
29+
setuptools
30+
];
31+
32+
dependencies = with python3Packages; [
33+
sphinx
34+
];
35+
36+
pythonImportsCheck = [ "sphinxext.rediraffe" ];
37+
};
38+
39+
sphinx-togglebutton = python3Packages.buildPythonPackage rec {
40+
pname = "sphinx-togglebutton";
41+
version = "0.3.2";
42+
pyproject = true;
43+
44+
src = fetchFromGitHub {
45+
owner = "executablebooks";
46+
repo = "sphinx-togglebutton";
47+
rev = "refs/tags/v${version}";
48+
hash = "sha256-i7SshD1giWgDAHpiIBW03OCTLlPO/Y3Ykz0WXGoG5Zg=";
49+
};
50+
51+
build-system = with python3Packages; [
52+
setuptools
53+
];
54+
55+
dependencies = with python3Packages; [
56+
sphinx
57+
];
58+
59+
pythonImportsCheck = [ "sphinx_togglebutton" ];
60+
};
61+
62+
# FIXME: load this file from API docs package
63+
# Pre-fetch intersphinx mapping objects to fix
64+
# "WARNING: failed to reach any of the inventories with the following issues"
65+
intersphinxMapping = fetchurl {
66+
url = "https://qgis.org/pyqgis/master/objects.inv";
67+
hash = "sha256-pis5FIAAI/9GeJTFsdkJw4CpJrRQIurTnfaX+151Hgo=";
68+
};
69+
70+
in
71+
stdenv.mkDerivation {
72+
name = "qgis-website";
73+
74+
src = lib.cleanSourceWith {
75+
src = ./.;
76+
filter = (
77+
path: type: (builtins.all (x: x != baseNameOf path) [
78+
".git"
79+
".github"
80+
"flake.nix"
81+
"flake.lock"
82+
"package.nix"
83+
"result"
84+
])
85+
);
86+
};
87+
88+
postPatch = ''
89+
# Load intersphinx inventory objects from pre-fetched file
90+
substituteInPlace "conf.py" \
91+
--replace-fail \
92+
"'https://qgis.org/pyqgis/{}/'.format(pyqgis_version), None)}" \
93+
"'${intersphinxMapping}', '${intersphinxMapping}')}"
94+
95+
# Fix "WARNING: unsupported theme option 'display_version' given"
96+
# https://github.com/readthedocs/sphinx_rtd_theme/issues/1623
97+
substituteInPlace "conf.py" \
98+
--replace-fail \
99+
"'display_version': True," \
100+
"# 'display_verson': True,"
101+
'';
102+
103+
buildInputs = with python3Packages; [
104+
pyyaml
105+
sphinx
106+
sphinx-copybutton
107+
sphinxext-rediraffe
108+
sphinx-intl
109+
sphinx-rtd-theme
110+
sphinx-togglebutton
111+
];
112+
113+
buildPhase = ''
114+
# List of languages taken from Makefile
115+
LANGUAGES="en bg cs de es fi fr id it ja ko nl pt_BR pt_PT ro ru tr zh_Hant zh_Hans"
116+
117+
for LANG in $LANGUAGES; do
118+
if [ "$LANG" != "en" ]; then
119+
sphinx-build -b html . build/html/$LANG -D language=$LANG -t i18n
120+
else
121+
sphinx-build -b html -nW --keep-going . build/html/$LANG
122+
fi
123+
done
124+
'';
125+
126+
installPhase = ''
127+
mkdir -p $out
128+
cp -r build/html/* $out/
129+
'';
130+
131+
meta = with lib; {
132+
description = "A QGIS website";
133+
license = licenses.mit;
134+
};
135+
}
136+

0 commit comments

Comments
 (0)