diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index fb85df8808f1..3ada88e32f5a 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -845,8 +845,8 @@ in { qemu-vm-volatile-root = runTest ./qemu-vm-volatile-root.nix; qemu-vm-external-disk-image = runTest ./qemu-vm-external-disk-image.nix; qemu-vm-store = runTest ./qemu-vm-store.nix; - qgis = handleTest ./qgis.nix { qgisPackage = pkgs.qgis; }; - qgis-ltr = handleTest ./qgis.nix { qgisPackage = pkgs.qgis-ltr; }; + qgis = handleTest ./qgis.nix { package = pkgs.qgis; }; + qgis-ltr = handleTest ./qgis.nix { package = pkgs.qgis-ltr; }; qownnotes = handleTest ./qownnotes.nix {}; qtile = handleTestOn ["x86_64-linux" "aarch64-linux"] ./qtile/default.nix {}; quake3 = handleTest ./quake3.nix {}; diff --git a/nixos/tests/qgis.nix b/nixos/tests/qgis.nix index 7706b8c07747..e8149e488562 100644 --- a/nixos/tests/qgis.nix +++ b/nixos/tests/qgis.nix @@ -1,5 +1,6 @@ -import ./make-test-python.nix ({ pkgs, lib, qgisPackage, ... }: +import ./make-test-python.nix ({ pkgs, lib, package, ... }: let + qgisPackage = package.override { withServer = true; }; testScript = pkgs.writeTextFile { name = "qgis-test.py"; text = (builtins.readFile ../../pkgs/applications/gis/qgis/test.py); @@ -12,19 +13,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 = [ + "QT_QPA_PLATFORM_PLUGIN_PATH=${pkgs.libsForQt5.qt5.qtbase}/${pkgs.libsForQt5.qt5.qtbase.qtPluginPrefix}/platforms" + "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("curl --head http://localhost | grep 'Server:.*${qgisPackage.version}'") + machine.succeed("curl http://localhost/index.json | grep 'Landing page as JSON'") ''; }) diff --git a/pkgs/applications/gis/qgis/default.nix b/pkgs/applications/gis/qgis/default.nix index 06e2cbef1f24..d7a65bb7b7a4 100644 --- a/pkgs/applications/gis/qgis/default.nix +++ b/pkgs/applications/gis/qgis/default.nix @@ -8,11 +8,13 @@ # unwrapped package parameters , withGrass ? false +, withServer ? false , withWebKit ? false }: let qgis-unwrapped = libsForQt5.callPackage ./unwrapped.nix { withGrass = withGrass; + withServer = withServer; withWebKit = withWebKit; }; in symlinkJoin rec { diff --git a/pkgs/applications/gis/qgis/ltr.nix b/pkgs/applications/gis/qgis/ltr.nix index a588ac6dbd6a..596347a97e3f 100644 --- a/pkgs/applications/gis/qgis/ltr.nix +++ b/pkgs/applications/gis/qgis/ltr.nix @@ -8,11 +8,13 @@ # unwrapped package parameters , withGrass ? false +, withServer ? false , withWebKit ? false }: let qgis-ltr-unwrapped = libsForQt5.callPackage ./unwrapped-ltr.nix { withGrass = withGrass; + withServer = withServer; withWebKit = withWebKit; }; in symlinkJoin rec { diff --git a/pkgs/applications/gis/qgis/unwrapped-ltr.nix b/pkgs/applications/gis/qgis/unwrapped-ltr.nix index 98caf348ae80..bc807b7e1074 100644 --- a/pkgs/applications/gis/qgis/unwrapped-ltr.nix +++ b/pkgs/applications/gis/qgis/unwrapped-ltr.nix @@ -7,6 +7,7 @@ , wrapQtAppsHook , withGrass +, withServer , withWebKit , bison @@ -155,7 +156,10 @@ in mkDerivation rec { "-DWITH_PDAL=True" "-DENABLE_TESTS=False" ] ++ lib.optional (!withWebKit) "-DWITH_QTWEBKIT=OFF" - ++ lib.optional withGrass (let + ++ lib.optional withServer [ + "-DWITH_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}" diff --git a/pkgs/applications/gis/qgis/unwrapped.nix b/pkgs/applications/gis/qgis/unwrapped.nix index 49d0fd5b366e..577dfdf5e17f 100644 --- a/pkgs/applications/gis/qgis/unwrapped.nix +++ b/pkgs/applications/gis/qgis/unwrapped.nix @@ -7,6 +7,7 @@ , wrapQtAppsHook , withGrass +, withServer , withWebKit , bison @@ -157,7 +158,10 @@ in mkDerivation rec { "-DENABLE_TESTS=False" "-DQT_PLUGINS_DIR=${qtbase}/${qtbase.qtPluginPrefix}" ] ++ lib.optional (!withWebKit) "-DWITH_QTWEBKIT=OFF" - ++ lib.optional withGrass (let + ++ lib.optional withServer [ + "-DWITH_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}"