From 41e158df7c8412fd951551dca6b830138a7506ec Mon Sep 17 00:00:00 2001 From: Vladimir Timofeenko Date: Tue, 5 Dec 2023 14:37:40 -0800 Subject: [PATCH] feat: expose .debug option The new option allows running xremap with upstream's debug logging enabled --- README.md | 1 + homeManagerModules/default.nix | 2 ++ lib/default.nix | 1 + modules/system-service.nix | 2 ++ modules/user-service.nix | 3 ++- 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bbd7543..e463408 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,7 @@ Following `services.xremap` options are exposed: * `deviceName` – the name of the device to be used. To find out the name, you can check `/proc/bus/input/devices` * `watch` – whether to watch for new devices * `mouse` – whether to watch for mice by default +* `debug` – enables debug logging for xremap See examples in `nixosConfigurations` inside flake.nix. diff --git a/homeManagerModules/default.nix b/homeManagerModules/default.nix index f2c4a3f..49cdd3d 100644 --- a/homeManagerModules/default.nix +++ b/homeManagerModules/default.nix @@ -4,6 +4,7 @@ let cfg = config.services.xremap; localLib = localFlake.localLib { inherit pkgs lib cfg; }; inherit (localLib) mkExecStart configFile; + inherit (lib) optionalString; in { options.services.xremap = localLib.commonOptions; @@ -18,6 +19,7 @@ in Type = "simple"; ExecStart = mkExecStart configFile; Restart = "always"; + Environment = optionalString cfg.debug "RUST_LOG=debug"; }; Install.WantedBy = [ "graphical-session.target" ]; }; diff --git a/lib/default.nix b/lib/default.nix index e6e436a..9639265 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -108,6 +108,7 @@ in example = [ "--completions zsh" ]; description = "Extra arguments for xremap"; }; + debug = mkEnableOption "run xremap with RUST_LOG=debug in case upstream needs logs"; }; configFile = pkgs.writeTextFile { name = "xremap-config.yml"; diff --git a/modules/system-service.nix b/modules/system-service.nix index ec81675..f030a87 100644 --- a/modules/system-service.nix +++ b/modules/system-service.nix @@ -4,6 +4,7 @@ let cfg = config.services.xremap; userPath = "/run/user/${toString cfg.userId}"; + inherit (lib) optionalString; in { systemd.services.xremap = lib.mkIf (cfg.serviceMode == "system") { @@ -11,6 +12,7 @@ in path = [ cfg.package ]; wantedBy = [ "multi-user.target" ]; serviceConfig = { + Environment = optionalString cfg.debug "RUST_LOG=debug"; PrivateNetwork = true; MemoryDenyWriteExecute = true; CapabilityBoundingSet = [ "~CAP_SETUID" "~CAP_SETGID" "~CAP_SETPCAP" "~CAP_SYS_ADMIN" "~CAP_SYS_PTRACE" "~CAP_NET_ADMIN" "~CAP_FOWNER" "~CAP_IPC_OWNER" "~CAP_SYS_TIME" "~CAP_KILL" "~CAP_SYS_BOOT" "~CAP_LINUX_IMMUTABLE" "~CAP_IPC_LOCK" "~CAP_SYS_CHROOT" "~CAP_BLOCK_SUSPEND" "~CAP_SYS_PACCT" "~CAP_WAKE_ALARM" "~CAP_AUDIT_WRITE" "~CAP_AUDIT_CONTROL" "~CAP_AUDIT_READ" "CAP_DAC_READ_SEARCH" "CAP_DAC_OVERRIDE" ]; diff --git a/modules/user-service.nix b/modules/user-service.nix index 2ea2e54..7da45ce 100644 --- a/modules/user-service.nix +++ b/modules/user-service.nix @@ -2,6 +2,7 @@ { pkgs, lib, config, ... }: let + inherit (lib) optionalString; cfg = config.services.xremap; in { @@ -48,7 +49,7 @@ in LockPersonality = true; UMask = "077"; RestrictAddressFamilies = "AF_UNIX"; - # Environment = "RUST_LOG=debug"; + Environment = optionalString cfg.debug "RUST_LOG=debug"; ExecStart = mkExecStart configFile; }; };