Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release_3.40] Nixos build support #9714

Merged
merged 3 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use nix
layout python

6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
clean.sh
list-vscode-extensions.sh
shell.nix
vscode.sh
testdata
sphinx-env
*.pyc
Expand Down Expand Up @@ -34,4 +30,6 @@ vscode.sh
clean.sh
.envrc
.vscode-extensions
.vscode
core
.env
9 changes: 9 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /usr/bin/env bash

rm -rf .direnv
rm -rf .venv
rm -rf .vscode-extensions
rm -rf __pycache__
cd ..
cd -

2 changes: 1 addition & 1 deletion scripts/clean_unused_images.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

#This script is used to clean no longer needed images from sources
# Run from repository root
Expand Down
2 changes: 2 additions & 0 deletions scripts/countsubs.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

while read SUBSTITUTION; do
COUNT=`grep -ir -m1 $SUBSTITUTION --include="*.rst" docs/ | wc -l`;echo $SUBSTITUTION $COUNT
done <subst.py
3 changes: 2 additions & 1 deletion scripts/create_transifex_resources.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env bash


# This script is used to register QGIS-Documentation translatable resources with Transifex
# https://app.transifex.com
Expand Down
2 changes: 1 addition & 1 deletion scripts/minimize_translation.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

# This script is used to pull translated resources of QGIS-Documentation
# from Transifex, clean and keep only the translated strings in them.
Expand Down
2 changes: 2 additions & 0 deletions scripts/populate_expressions_list.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

from os import path, walk
import glob
from sys import argv
Expand Down
2 changes: 1 addition & 1 deletion scripts/rstcleanup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

# replacing |nix| |qg| |win| |osx|
rpl -qi '|qg|' 'QGIS' $1
Expand Down
45 changes: 45 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
let
pinnedHash = "f03c983c83471408ef16fcb9f47078491070064f";
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/${pinnedHash}.tar.gz") { };
pythonPackages = pkgs.python3Packages;
in pkgs.mkShell rec {
name = "impurePythonEnv";
venvDir = "./.venv";
buildInputs = [
# A Python interpreter including the 'venv' module is required to bootstrap
# the environment.
pythonPackages.python

# This executes some shell code to initialize a venv in $venvDir before
# dropping into the shell
pythonPackages.venvShellHook
pkgs.vscode
pkgs.transifex-cli

# Those are dependencies that we would like to use from nixpkgs, which will
# add them to PYTHONPATH and thus make them accessible from within the venv.
];

# Run this command, only after creating the virtual environment
postVenvCreation = ''
export DIRENV_LOG_FORMAT=
unset SOURCE_DATE_EPOCH
pip install -r REQUIREMENTS.txt
echo "-----------------------"
echo "🌈 Your Dev Environment is prepared."
echo "📒 Note:"
echo "-----------------------"
echo "start vscode like this:"
echo ""
echo "./vscode.sh"
echo "-----------------------"
'';

# Now we can execute any commands within the virtual environment.
# This is optional and can be left out to run pip manually.
postShellHook = ''
# allow pip to install wheels
unset SOURCE_DATE_EPOCH
'';

}
84 changes: 84 additions & 0 deletions vscode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash
echo "🪛 Installing VSCode Extensions:"
echo "--------------------------------"

# Locate QGIS binary
QGIS_BIN=$(which qgis)

if [[ -z "$QGIS_BIN" ]]; then
echo "Error: QGIS binary not found!"
exit 1
fi

# Extract the Nix store path (removing /bin/qgis)
QGIS_PREFIX=$(dirname "$(dirname "$QGIS_BIN")")

# Construct the correct QGIS Python path
QGIS_PYTHON_PATH="$QGIS_PREFIX/share/qgis/python"
# Needed for qgis processing module import
PROCESSING_PATH="$QGIS_PREFIX/share/qgis/python/qgis"

# Check if the Python directory exists
if [[ ! -d "$QGIS_PYTHON_PATH" ]]; then
echo "Error: QGIS Python path not found at $QGIS_PYTHON_PATH"
exit 1
fi

# Create .env file for VSCode
ENV_FILE=".env"

QTPOSITIONING="/nix/store/nb3gkbi161fna9fxh9g3bdgzxzpq34gf-python3.11-pyqt5-5.15.10/lib/python3.11/site-packages"

echo "Creating VSCode .env file..."
cat <<EOF > "$ENV_FILE"
PYTHONPATH=$QGIS_PYTHON_PATH:$QTPOSITIONING
QGIS_PREFIX_PATH=$QGIS_PREFIX
PYQT5_PATH="$QGIS_PREFIX/share/qgis/python/PyQt"
QT_QPA_PLATFORM=offscreen
EOF

echo "✅ .env file created successfully!"
echo "Contents of .env:"
cat "$ENV_FILE"

# Also set the python path in this shell in case we want to run tests etc from the command line
export PYTHONPATH=$PYTHONPATH:$QGIS_PYTHON_PATH

# Ensure .vscode directory exists
mkdir -p .vscode

# Define the settings.json file path
SETTINGS_FILE=".vscode/settings.json"

# Ensure settings.json exists
if [[ ! -f "$SETTINGS_FILE" ]]; then
echo "{}" > "$SETTINGS_FILE"
fi

# Update settings.json non-destructively
echo "Updating VSCode settings.json..."
jq --arg pyenv "\${workspaceFolder}/.env" \
--arg qgispath "$QGIS_PYTHON_PATH" \
--arg prefixpath "$QGIS_PREFIX" \
'.["python.envFile"] = $pyenv |
.["python.analysis.extraPaths"] += [$qgispath] |
.["terminal.integrated.env.linux"].PYTHONPATH = $qgispath |
.["git.enableCommitSigning"] = true' \
"$SETTINGS_FILE" > "$SETTINGS_FILE.tmp" && mv "$SETTINGS_FILE.tmp" "$SETTINGS_FILE"

echo "✅ VSCode settings.json updated successfully!"
echo "Contents of settings.json:"
cat "$SETTINGS_FILE"

# Install required extensions
code --user-data-dir='.vscode' \
--profile='qgis-documentation' \
--extensions-dir='.vscode-extensions' . \
--install-extension [email protected] \
--install-extension [email protected] \
--install-extension [email protected]

# Launch VSCode with the sandboxed environment
code --user-data-dir='.vscode' \
--profile='qgis-documentation' \
--extensions-dir='.vscode-extensions' .
Loading