From 7ea42f9c8ea19d17ce59449812a5cdffb4ac96e7 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Sat, 11 Nov 2023 22:49:58 +0100 Subject: [PATCH] signaturepdf: add service --- modules/misc/news.nix | 8 +++ modules/modules.nix | 1 + modules/services/signaturepdf.nix | 70 +++++++++++++++++++ tests/default.nix | 1 + .../signaturepdf/basic-configuration.desktop | 7 ++ .../signaturepdf/basic-configuration.nix | 24 +++++++ .../signaturepdf/basic-configuration.service | 8 +++ .../modules/services/signaturepdf/default.nix | 1 + 8 files changed, 120 insertions(+) create mode 100644 modules/services/signaturepdf.nix create mode 100644 tests/modules/services/signaturepdf/basic-configuration.desktop create mode 100644 tests/modules/services/signaturepdf/basic-configuration.nix create mode 100644 tests/modules/services/signaturepdf/basic-configuration.service create mode 100644 tests/modules/services/signaturepdf/default.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 052c23a68..3e81a55f8 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1309,6 +1309,14 @@ in A new module is available: 'programs.ruff'. ''; } + + { + time = "2023-11-26T23:18:01+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.signaturepdf'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index ced8e9510..83130d60d 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -326,6 +326,7 @@ let ./services/safeeyes.nix ./services/screen-locker.nix ./services/sctd.nix + ./services/signaturepdf.nix ./services/spotifyd.nix ./services/ssh-agent.nix ./services/stalonetray.nix diff --git a/modules/services/signaturepdf.nix b/modules/services/signaturepdf.nix new file mode 100644 index 000000000..ef30e6287 --- /dev/null +++ b/modules/services/signaturepdf.nix @@ -0,0 +1,70 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.services.signaturepdf; + extraConfigToArgs = extraConfig: + lib.flatten + (lib.mapAttrsToList (name: value: [ "-d" "${name}=${value}" ]) extraConfig); +in { + meta.maintainers = [ lib.maintainers.DamienCassou ]; + + options.services.signaturepdf = with lib; { + enable = mkEnableOption + "signaturepdf; signing, organizing, editing metadatas or compressing PDFs"; + + package = mkOption { + type = types.package; + default = pkgs.signaturepdf; + defaultText = "pkgs.signaturepdf"; + description = "signaturepdf derivation to use."; + }; + + port = mkOption { + type = types.port; + default = 8080; + example = 8081; + description = "The port on which the application runs"; + }; + + extraConfig = mkOption { + default = { }; + type = with types; + let primitive = oneOf [ str int bool float ]; + in attrsOf primitive; + example = { + upload_max_filesize = "24M"; + post_max_size = "24M"; + max_file_uploads = "201"; + }; + description = "Additional configuration optional."; + }; + }; + + config = lib.mkIf cfg.enable { + xdg.desktopEntries = { + signaturepdf = { + name = "SignaturePDF"; + exec = "${pkgs.xdg-utils}/bin/xdg-open http://localhost:${ + toString cfg.port + }"; + terminal = false; + icon = "${cfg.package}/share/signaturepdf/public/favicon.ico"; + }; + }; + + systemd.user.services.signaturepdf = { + Unit = { + Description = + "signaturepdf; signing, organizing, editing metadatas or compressing PDFs"; + }; + + Service = { + ExecStart = "${cfg.package}/bin/signaturepdf ${toString cfg.port} ${ + lib.escapeShellArgs (extraConfigToArgs cfg.extraConfig) + }"; + }; + + Install = { WantedBy = [ "default.target" ]; }; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 497f363cc..89a6cedd3 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -244,6 +244,7 @@ import nmt { ./modules/services/recoll ./modules/services/redshift-gammastep ./modules/services/screen-locker + ./modules/services/signaturepdf ./modules/services/swayidle ./modules/services/swayosd ./modules/services/sxhkd diff --git a/tests/modules/services/signaturepdf/basic-configuration.desktop b/tests/modules/services/signaturepdf/basic-configuration.desktop new file mode 100644 index 000000000..921ca5df4 --- /dev/null +++ b/tests/modules/services/signaturepdf/basic-configuration.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Exec=@xdg-utils@/bin/xdg-open http://localhost:9494 +Icon=/signaturepdf/share/signaturepdf/public/favicon.ico +Name=SignaturePDF +Terminal=false +Type=Application +Version=1.4 diff --git a/tests/modules/services/signaturepdf/basic-configuration.nix b/tests/modules/services/signaturepdf/basic-configuration.nix new file mode 100644 index 000000000..66c1b0834 --- /dev/null +++ b/tests/modules/services/signaturepdf/basic-configuration.nix @@ -0,0 +1,24 @@ +{ config, pkgs, ... }: + +{ + services.signaturepdf = { + enable = true; + port = 9494; + extraConfig = { upload_max_filesize = "24M"; }; + }; + + test.stubs = { + signaturepdf = { outPath = "/signaturepdf"; }; + xdg-utils = { }; + }; + + nmt.script = '' + assertFileContent \ + home-files/.config/systemd/user/signaturepdf.service \ + ${./basic-configuration.service} + + assertFileContent \ + home-path/share/applications/signaturepdf.desktop \ + ${./basic-configuration.desktop} + ''; +} diff --git a/tests/modules/services/signaturepdf/basic-configuration.service b/tests/modules/services/signaturepdf/basic-configuration.service new file mode 100644 index 000000000..0775fff65 --- /dev/null +++ b/tests/modules/services/signaturepdf/basic-configuration.service @@ -0,0 +1,8 @@ +[Install] +WantedBy=default.target + +[Service] +ExecStart=/signaturepdf/bin/signaturepdf 9494 '-d' 'upload_max_filesize=24M' + +[Unit] +Description=signaturepdf; signing, organizing, editing metadatas or compressing PDFs diff --git a/tests/modules/services/signaturepdf/default.nix b/tests/modules/services/signaturepdf/default.nix new file mode 100644 index 000000000..a887f1242 --- /dev/null +++ b/tests/modules/services/signaturepdf/default.nix @@ -0,0 +1 @@ +{ signaturepdf-basic-configuration = ./basic-configuration.nix; }