Skip to content

Commit 885921c

Browse files
authored
Merge pull request #9690 from timlinux/nixos
Nixos build support
2 parents fce69e0 + fdb846c commit 885921c

11 files changed

+152
-8
lines changed

.envrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use nix
2+
layout python
3+

.gitignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
clean.sh
2-
list-vscode-extensions.sh
3-
shell.nix
4-
vscode.sh
51
testdata
62
sphinx-env
73
*.pyc
@@ -34,4 +30,6 @@ vscode.sh
3430
clean.sh
3531
.envrc
3632
.vscode-extensions
33+
.vscode
3734
core
35+
.env

clean.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#! /usr/bin/env bash
2+
3+
rm -rf .direnv
4+
rm -rf .venv
5+
rm -rf .vscode-extensions
6+
rm -rf __pycache__
7+
cd ..
8+
cd -
9+

scripts/clean_unused_images.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
#This script is used to clean no longer needed images from sources
44
# Run from repository root

scripts/countsubs.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env bash
2+
13
while read SUBSTITUTION; do
24
COUNT=`grep -ir -m1 $SUBSTITUTION --include="*.rst" docs/ | wc -l`;echo $SUBSTITUTION $COUNT
35
done <subst.py

scripts/create_transifex_resources.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
23

34
# This script is used to register QGIS-Documentation translatable resources with Transifex
45
# https://app.transifex.com

scripts/minimize_translation.sh

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
# This script is used to pull translated resources of QGIS-Documentation
44
# from Transifex, clean and keep only the translated strings in them.

scripts/populate_expressions_list.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python3
2+
13
from os import path, walk
24
import glob
35
from sys import argv

scripts/rstcleanup.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
# replacing |nix| |qg| |win| |osx|
44
rpl -qi '|qg|' 'QGIS' $1

shell.nix

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
let
2+
pinnedHash = "f03c983c83471408ef16fcb9f47078491070064f";
3+
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/${pinnedHash}.tar.gz") { };
4+
pythonPackages = pkgs.python3Packages;
5+
in pkgs.mkShell rec {
6+
name = "impurePythonEnv";
7+
venvDir = "./.venv";
8+
buildInputs = [
9+
# A Python interpreter including the 'venv' module is required to bootstrap
10+
# the environment.
11+
pythonPackages.python
12+
13+
# This executes some shell code to initialize a venv in $venvDir before
14+
# dropping into the shell
15+
pythonPackages.venvShellHook
16+
pkgs.vscode
17+
pkgs.transifex-cli
18+
19+
# Those are dependencies that we would like to use from nixpkgs, which will
20+
# add them to PYTHONPATH and thus make them accessible from within the venv.
21+
];
22+
23+
# Run this command, only after creating the virtual environment
24+
postVenvCreation = ''
25+
export DIRENV_LOG_FORMAT=
26+
unset SOURCE_DATE_EPOCH
27+
pip install -r REQUIREMENTS.txt
28+
echo "-----------------------"
29+
echo "🌈 Your Dev Environment is prepared."
30+
echo "📒 Note:"
31+
echo "-----------------------"
32+
echo "start vscode like this:"
33+
echo ""
34+
echo "./vscode.sh"
35+
echo "-----------------------"
36+
'';
37+
38+
# Now we can execute any commands within the virtual environment.
39+
# This is optional and can be left out to run pip manually.
40+
postShellHook = ''
41+
# allow pip to install wheels
42+
unset SOURCE_DATE_EPOCH
43+
'';
44+
45+
}

vscode.sh

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env bash
2+
echo "🪛 Installing VSCode Extensions:"
3+
echo "--------------------------------"
4+
5+
# Locate QGIS binary
6+
QGIS_BIN=$(which qgis)
7+
8+
if [[ -z "$QGIS_BIN" ]]; then
9+
echo "Error: QGIS binary not found!"
10+
exit 1
11+
fi
12+
13+
# Extract the Nix store path (removing /bin/qgis)
14+
QGIS_PREFIX=$(dirname "$(dirname "$QGIS_BIN")")
15+
16+
# Construct the correct QGIS Python path
17+
QGIS_PYTHON_PATH="$QGIS_PREFIX/share/qgis/python"
18+
# Needed for qgis processing module import
19+
PROCESSING_PATH="$QGIS_PREFIX/share/qgis/python/qgis"
20+
21+
# Check if the Python directory exists
22+
if [[ ! -d "$QGIS_PYTHON_PATH" ]]; then
23+
echo "Error: QGIS Python path not found at $QGIS_PYTHON_PATH"
24+
exit 1
25+
fi
26+
27+
# Create .env file for VSCode
28+
ENV_FILE=".env"
29+
30+
QTPOSITIONING="/nix/store/nb3gkbi161fna9fxh9g3bdgzxzpq34gf-python3.11-pyqt5-5.15.10/lib/python3.11/site-packages"
31+
32+
echo "Creating VSCode .env file..."
33+
cat <<EOF > "$ENV_FILE"
34+
PYTHONPATH=$QGIS_PYTHON_PATH:$QTPOSITIONING
35+
QGIS_PREFIX_PATH=$QGIS_PREFIX
36+
PYQT5_PATH="$QGIS_PREFIX/share/qgis/python/PyQt"
37+
QT_QPA_PLATFORM=offscreen
38+
EOF
39+
40+
echo "✅ .env file created successfully!"
41+
echo "Contents of .env:"
42+
cat "$ENV_FILE"
43+
44+
# Also set the python path in this shell in case we want to run tests etc from the command line
45+
export PYTHONPATH=$PYTHONPATH:$QGIS_PYTHON_PATH
46+
47+
# Ensure .vscode directory exists
48+
mkdir -p .vscode
49+
50+
# Define the settings.json file path
51+
SETTINGS_FILE=".vscode/settings.json"
52+
53+
# Ensure settings.json exists
54+
if [[ ! -f "$SETTINGS_FILE" ]]; then
55+
echo "{}" > "$SETTINGS_FILE"
56+
fi
57+
58+
# Update settings.json non-destructively
59+
echo "Updating VSCode settings.json..."
60+
jq --arg pyenv "\${workspaceFolder}/.env" \
61+
--arg qgispath "$QGIS_PYTHON_PATH" \
62+
--arg prefixpath "$QGIS_PREFIX" \
63+
'.["python.envFile"] = $pyenv |
64+
.["python.analysis.extraPaths"] += [$qgispath] |
65+
.["terminal.integrated.env.linux"].PYTHONPATH = $qgispath |
66+
.["git.enableCommitSigning"] = true' \
67+
"$SETTINGS_FILE" > "$SETTINGS_FILE.tmp" && mv "$SETTINGS_FILE.tmp" "$SETTINGS_FILE"
68+
69+
echo "✅ VSCode settings.json updated successfully!"
70+
echo "Contents of settings.json:"
71+
cat "$SETTINGS_FILE"
72+
73+
# Install required extensions
74+
code --user-data-dir='.vscode' \
75+
--profile='qgis-documentation' \
76+
--extensions-dir='.vscode-extensions' . \
77+
--install-extension [email protected] \
78+
--install-extension [email protected] \
79+
--install-extension [email protected]
80+
81+
# Launch VSCode with the sandboxed environment
82+
code --user-data-dir='.vscode' \
83+
--profile='qgis-documentation' \
84+
--extensions-dir='.vscode-extensions' .

0 commit comments

Comments
 (0)