Skip to content

Commit

Permalink
qgis: add server support
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Gamari <ben@smart-cactus.org>
  • Loading branch information
imincik and bgamari committed Jan 15, 2024
1 parent 817c314 commit 91af823
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 20 deletions.
59 changes: 57 additions & 2 deletions nixos/tests/qgis.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,74 @@ import ./make-test-python.nix ({ pkgs, lib, qgisPackage, ... }:
};

nodes = {
machine = { pkgs, ... }: {
machine = { config, pkgs, ... }:

let
qgisServerUser = config.services.nginx.user;
qgisServerSocket = "/run/qgis_mapserv.socket";
in
{
virtualisation.diskSize = 2 * 1024;

imports = [ ./common/x11.nix ];
environment.systemPackages = [ qgisPackage ];
environment.systemPackages = [
qgisPackage
];

systemd.sockets.qgis-server = {
listenStreams = [ qgisServerSocket ];
socketConfig = {
Accept = false;
SocketUser = qgisServerUser;
SocketMode = 0600;
};
wantedBy = ["sockets.target" "qgis-server.service"];
before = [ "qgis-server.service" ];
};

systemd.services.qgis-server = {
description = "QGIS server";
serviceConfig = {
User = qgisServerUser;
StandardOutput = "null";
StandardError = "journal";
StandardInput = "socket";
Environment = [
"QGIS_SERVER_LOG_LEVEL=0"
"QGIS_SERVER_LOG_STDERR=1"
];
ExecStart = "${qgisPackage}/lib/cgi-bin/qgis_mapserv.fcgi";
};
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
};

services.nginx = {
enable = true;
virtualHosts."qgis" = {
locations."~".extraConfig = ''
gzip off;
include ${pkgs.nginx}/conf/fastcgi_params;
include ${pkgs.nginx}/conf/fastcgi.conf;
fastcgi_pass unix:${qgisServerSocket};
'';
};
};
};
};

testScript = ''
start_all()
# test desktop
machine.succeed("${qgisPackage}/bin/qgis --version | grep 'QGIS ${qgisPackage.version}'")
machine.succeed("${qgisPackage}/bin/qgis --code ${testScript}")
# test server
machine.succeed("${qgisPackage}/bin/qgis_mapserver --version | grep 'QGIS ${qgisPackage.version}'")
machine.succeed("${qgisPackage}/lib/cgi-bin/qgis_mapserv.fcgi | grep 'Server:.*${qgisPackage.version}'")
machine.succeed("curl --head http://localhost | grep 'Server:.*${qgisPackage.version}'")
machine.succeed("curl http://localhost/index.json | grep 'Landing page as JSON'")
'';
})
8 changes: 8 additions & 0 deletions pkgs/applications/gis/qgis/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ in symlinkJoin rec {
wrapProgram $out/bin/qgis \
--prefix PATH : $program_PATH \
--set PYTHONPATH $program_PYTHONPATH
wrapProgram $out/bin/qgis_mapserver \
--prefix PATH : $program_PATH \
--set PYTHONPATH $program_PYTHONPATH
wrapProgram $out/lib/cgi-bin/qgis_mapserv.fcgi \
--prefix PATH : $program_PATH \
--set PYTHONPATH $program_PYTHONPATH
'';

passthru = {
Expand Down
8 changes: 8 additions & 0 deletions pkgs/applications/gis/qgis/ltr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ in symlinkJoin rec {
wrapProgram $out/bin/qgis \
--prefix PATH : $program_PATH \
--set PYTHONPATH $program_PYTHONPATH
wrapProgram $out/bin/qgis_mapserver \
--prefix PATH : $program_PATH \
--set PYTHONPATH $program_PYTHONPATH
wrapProgram $out/lib/cgi-bin/qgis_mapserv.fcgi \
--prefix PATH : $program_PATH \
--set PYTHONPATH $program_PYTHONPATH
'';

passthru = {
Expand Down
24 changes: 15 additions & 9 deletions pkgs/applications/gis/qgis/unwrapped-ltr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -152,26 +152,32 @@ in mkDerivation rec {
];

cmakeFlags = [
"-DWITH_3D=True"
"-DWITH_PDAL=TRUE"
"-DENABLE_TESTS=False"
] ++ lib.optional (!withWebKit) "-DWITH_QTWEBKIT=OFF"
++ lib.optional withGrass (let
"-DCMAKE_BUILD_TYPE=Release"
(lib.cmakeBool "ENABLE_TESTS" false)
(lib.cmakeBool "WITH_3D" true)
(lib.cmakeBool "WITH_PDAL" true)
(lib.cmakeBool "WITH_QTWEBKIT" withWebKit)
(lib.cmakeBool "WITH_SERVER" true)
"-DQGIS_CGIBIN_SUBDIR=${placeholder "out"}/lib/cgi-bin"
] ++ lib.optional withGrass (let
gmajor = lib.versions.major grass.version;
gminor = lib.versions.minor grass.version;
in "-DGRASS_PREFIX${gmajor}=${grass}/grass${gmajor}${gminor}"
);

dontWrapGApps = true; # wrapper params passed below

# 1. GRASS has to be availble on the command line even though we baked in
# the path at build time using GRASS_PREFIX.
# Using wrapGAppsHook also prevents file dialogs from crashing the program
# on non-NixOS.
# 2. Wrap server CGI binary which is not wrapped by default.
postFixup = lib.optionalString withGrass ''
# GRASS has to be availble on the command line even though we baked in
# the path at build time using GRASS_PREFIX.
# Using wrapGAppsHook also prevents file dialogs from crashing the program
# on non-NixOS.
wrapProgram $out/bin/qgis \
"''${gappsWrapperArgs[@]}" \
--prefix PATH : ${lib.makeBinPath [ grass ]}
wrapQtApp $out/lib/cgi-bin/qgis_mapserv.fcgi
'';

meta = with lib; {
Expand Down
23 changes: 14 additions & 9 deletions pkgs/applications/gis/qgis/unwrapped.nix
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ in mkDerivation rec {

cmakeFlags = [
"-DCMAKE_BUILD_TYPE=Release"
"-DWITH_3D=True"
"-DWITH_PDAL=True"
"-DENABLE_TESTS=False"
] ++ lib.optional (!withWebKit) "-DWITH_QTWEBKIT=OFF"
++ lib.optional withGrass (let
(lib.cmakeBool "ENABLE_TESTS" false)
(lib.cmakeBool "WITH_3D" true)
(lib.cmakeBool "WITH_PDAL" true)
(lib.cmakeBool "WITH_QTWEBKIT" withWebKit)
(lib.cmakeBool "WITH_SERVER" true)
"-DQGIS_CGIBIN_SUBDIR=${placeholder "out"}/lib/cgi-bin"
] ++ lib.optional withGrass (let
gmajor = lib.versions.major grass.version;
gminor = lib.versions.minor grass.version;
in "-DGRASS_PREFIX${gmajor}=${grass}/grass${gmajor}${gminor}"
Expand All @@ -169,14 +171,17 @@ in mkDerivation rec {

dontWrapGApps = true; # wrapper params passed below

# 1. GRASS has to be availble on the command line even though we baked in
# the path at build time using GRASS_PREFIX.
# Using wrapGAppsHook also prevents file dialogs from crashing the program
# on non-NixOS.
# 2. Wrap server CGI binary which is not wrapped by default.
postFixup = lib.optionalString withGrass ''
# GRASS has to be availble on the command line even though we baked in
# the path at build time using GRASS_PREFIX.
# Using wrapGAppsHook also prevents file dialogs from crashing the program
# on non-NixOS.
wrapProgram $out/bin/qgis \
"''${gappsWrapperArgs[@]}" \
--prefix PATH : ${lib.makeBinPath [ grass ]}
wrapQtApp $out/lib/cgi-bin/qgis_mapserv.fcgi
'';

meta = with lib; {
Expand Down

0 comments on commit 91af823

Please sign in to comment.