From 1f305c363ecd7c6505f03fc7baba15505f3aa630 Mon Sep 17 00:00:00 2001 From: Cynthia Fox Date: Fri, 19 Apr 2024 11:16:42 -0400 Subject: [PATCH] remmina: add module Adds a module to enable managing Remmina, an RDP client, with a Home Manager module, providing a systemd service and mimetype integration that can be disabled if so desired. --- modules/misc/news.nix | 8 ++ modules/modules.nix | 1 + modules/services/remmina.nix | 74 +++++++++++++++++++ tests/default.nix | 1 + .../modules/services/remmina/basic-config.nix | 26 +++++++ .../services/remmina/default-config.nix | 20 +++++ tests/modules/services/remmina/default.nix | 4 + 7 files changed, 134 insertions(+) create mode 100644 modules/services/remmina.nix create mode 100644 tests/modules/services/remmina/basic-config.nix create mode 100644 tests/modules/services/remmina/default-config.nix create mode 100644 tests/modules/services/remmina/default.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index ef5378af1..8d7e17a5a 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1498,6 +1498,14 @@ in { A new module is available: 'programs.spotify-player'. ''; } + + { + time = "2024-04-19T14:53:17+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.remmina'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 512841029..96b2bec56 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -340,6 +340,7 @@ let ./services/recoll.nix ./services/redshift-gammastep/gammastep.nix ./services/redshift-gammastep/redshift.nix + ./services/remmina.nix ./services/rsibreak.nix ./services/safeeyes.nix ./services/screen-locker.nix diff --git a/modules/services/remmina.nix b/modules/services/remmina.nix new file mode 100644 index 000000000..dac0471db --- /dev/null +++ b/modules/services/remmina.nix @@ -0,0 +1,74 @@ +{ config, lib, pkgs, ... }: + +let + + inherit (lib) mkIf mkMerge mkEnableOption mkPackageOption mkOption; + + cfg = config.services.remmina; + +in { + meta.maintainers = with lib.maintainers; [ cyntheticfox ]; + + options.services.remmina = { + enable = mkEnableOption "Remmina"; + + package = mkPackageOption pkgs "remmina" { }; + + addRdpMimeTypeAssoc = mkEnableOption "Remmina RDP file open option" // { + default = true; + }; + + systemdService = { + enable = mkEnableOption "systemd Remmina service" // { default = true; }; + + startupFlags = mkOption { + type = with lib.types; listOf str; + default = [ "--icon" ]; + description = '' + Startup flags documented in the manpage to run at service startup. + ''; + }; + }; + }; + + config = mkIf cfg.enable (mkMerge [ + { home.packages = [ cfg.package ]; } + + (mkIf cfg.systemdService.enable { + systemd.user.services.remmina = { + Unit = { + Description = "Remmina remote desktop client"; + Documentation = "man:remmina(1)"; + Requires = [ "graphical-session-pre.target" ]; + }; + + Service = { + Type = "simple"; + ExecStart = "${lib.getExe cfg.package} ${ + lib.escapeShellArgs cfg.systemdService.startupFlags + }"; + Restart = "on-failure"; + }; + + Install.WantedBy = [ "graphical-session.target" ]; + }; + }) + + (mkIf (config.xdg.mimeApps.enable && cfg.addRdpMimeTypeAssoc) { + xdg.mimeApps.associations.added."application/x-rdp" = + "org.remmina.Remmina.desktop"; + + xdg.dataFile."mime/packages/application-x-rdp.xml".text = '' + + + + rdp file + + + + + + ''; + }) + ]); +} diff --git a/tests/default.nix b/tests/default.nix index c4d98ef2e..3729ce98c 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -255,6 +255,7 @@ in import nmtSrc { ./modules/services/polybar ./modules/services/recoll ./modules/services/redshift-gammastep + ./modules/services/remmina ./modules/services/screen-locker ./modules/services/signaturepdf ./modules/services/swayidle diff --git a/tests/modules/services/remmina/basic-config.nix b/tests/modules/services/remmina/basic-config.nix new file mode 100644 index 000000000..2741353ae --- /dev/null +++ b/tests/modules/services/remmina/basic-config.nix @@ -0,0 +1,26 @@ +{ config, ... }: { + xdg.mimeApps.enable = true; + + services.remmina = { + enable = true; + package = config.lib.test.mkStubPackage { }; + + addRdpMimeTypeAssoc = false; + systemdService = { + enable = true; + startupFlags = [ "--icon" "--enable-extra-hardening" ]; + }; + }; + + nmt.script = '' + serviceFile='./home-files/.config/systemd/user/remmina.service' + + assertFileExists $serviceFile + assertFileRegex $serviceFile 'ExecStart=.*/bin/dummy' + assertFileRegex $serviceFile "dummy '--icon' '--enable-extra-hardening'" + + mimetypeFile='./home-files/.local/share/mime/packages/application-x-rdp.xml' + + assertPathNotExists $mimetypeFile + ''; +} diff --git a/tests/modules/services/remmina/default-config.nix b/tests/modules/services/remmina/default-config.nix new file mode 100644 index 000000000..747623aff --- /dev/null +++ b/tests/modules/services/remmina/default-config.nix @@ -0,0 +1,20 @@ +{ config, ... }: { + xdg.mimeApps.enable = true; + + services.remmina = { + enable = true; + package = config.lib.test.mkStubPackage { }; + }; + + nmt.script = '' + serviceFile='./home-files/.config/systemd/user/remmina.service' + + assertFileExists $serviceFile + assertFileRegex $serviceFile 'ExecStart=.*--icon' + + mimetypeFile='./home-files/.local/share/mime/packages/application-x-rdp.xml' + + assertFileExists $mimetypeFile + assertFileRegex $mimetypeFile '' + ''; +} diff --git a/tests/modules/services/remmina/default.nix b/tests/modules/services/remmina/default.nix new file mode 100644 index 000000000..43fa48940 --- /dev/null +++ b/tests/modules/services/remmina/default.nix @@ -0,0 +1,4 @@ +{ + remmina-default-config = ./default-config.nix; + remmina-basic-config = ./basic-config.nix; +}