From 11413f94b2d5eb97756edcec6c7a7b4f9a46ae73 Mon Sep 17 00:00:00 2001 From: Thibault Gagnaux Date: Tue, 12 May 2020 19:20:29 +0200 Subject: [PATCH 1/5] Adds lorri service. --- modules/module-list.nix | 1 + modules/services/lorri.nix | 59 ++++++++++++++++++++++++++++++++++++++ release.nix | 1 + tests/services-lorri.nix | 18 ++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 modules/services/lorri.nix create mode 100644 tests/services-lorri.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index 52b987d65..6375ea38b 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -43,6 +43,7 @@ ./services/emacs.nix ./services/khd ./services/kwm + ./services/lorri.nix ./services/mail/offlineimap.nix ./services/mopidy.nix ./services/nix-daemon.nix diff --git a/modules/services/lorri.nix b/modules/services/lorri.nix new file mode 100644 index 000000000..142f57488 --- /dev/null +++ b/modules/services/lorri.nix @@ -0,0 +1,59 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.lorri; +in +{ + options = { + services.lorri.enable = mkOption { + type = types.bool; + default = false; + description = "Whether to enable the lorri service."; + }; + + services.lorri.package = mkOption { + type = types.path; + default = pkgs.lorri; + defaultText = "pkgs.lorri"; + description = "This option specifies the lorri package to use."; + }; + + services.lorri.logFile = mkOption { + type = types.nullOr types.path; + default = "/var/tmp/lorri.log"; + example = "/var/tmp/lorri.log"; + description = '' + The logfile to use for the lorri service. Alternatively + sudo launchctl debug system/org.nixos.lorri --stderr + can be used to stream the logs to a shell after restarting the service with + sudo launchctl kickstart -k system/org.nixos.lorri. + ''; + }; + + services.lorri.tempDir = mkOption { + type = types.nullOr types.path; + default = null; + description = "The TMPDIR to use for lorri."; + }; + }; + + config = mkIf cfg.enable { + environment.systemPackages = [ cfg.package ]; + launchd.user.agents.lorri = { + serviceConfig = { + KeepAlive = true; + ProcessType = "Background"; + LowPriorityIO = false; + StandardOutPath = cfg.logFile; + StandardErrorPath = cfg.logFile; + EnvironmentVariables = mkMerge [ + config.nix.envVars + { TMPDIR = mkIf (cfg.tempDir != null) cfg.tempDir; } + ]; + }; + command = "${cfg.package}/bin/lorri daemon"; + }; + }; +} \ No newline at end of file diff --git a/release.nix b/release.nix index 77eff1961..750510dcf 100644 --- a/release.nix +++ b/release.nix @@ -113,6 +113,7 @@ let tests.services-activate-system = makeTest ./tests/services-activate-system.nix; tests.services-activate-system-changed-label-prefix = makeTest ./tests/services-activate-system-changed-label-prefix.nix; tests.services-buildkite-agent = makeTest ./tests/services-buildkite-agent.nix; + tests.services-lorri = makeTest ./tests/services-lorri.nix; tests.services-nix-daemon = makeTest ./tests/services-nix-daemon.nix; tests.sockets-nix-daemon = makeTest ./tests/sockets-nix-daemon.nix; tests.services-dnsmasq = makeTest ./tests/services-dnsmasq.nix; diff --git a/tests/services-lorri.nix b/tests/services-lorri.nix new file mode 100644 index 000000000..e70eef5d7 --- /dev/null +++ b/tests/services-lorri.nix @@ -0,0 +1,18 @@ +{ config, pkgs, ... }: + +let + nix = pkgs.runCommand "nix-0.0.0" { version = "1.11.6"; } "mkdir -p $out"; + plistPath = "${config.out}/user/Library/LaunchAgents/org.nixos.lorri.plist"; +in +{ + services.lorri.enable = true; + nix.package = nix; + + test = '' + echo checking lorri service in /Library/LaunchAgents >&2 + cat ${plistPath} + grep -o "KeepAlive" ${plistPath} + grep -o "org.nixos.lorri" ${plistPath} + grep -o "exec ${pkgs.lorri}/bin/lorri daemon" ${plistPath} + ''; +} From 30593350fd91f25b68bfa44cf5f948e481262258 Mon Sep 17 00:00:00 2001 From: Thibault Gagnaux Date: Sat, 29 Aug 2020 16:32:49 +0200 Subject: [PATCH 2/5] Makes it work. --- modules/services/lorri.nix | 59 +++++++++++++++----------------------- tests/services-lorri.nix | 14 +++++---- 2 files changed, 32 insertions(+), 41 deletions(-) diff --git a/modules/services/lorri.nix b/modules/services/lorri.nix index 142f57488..9e2dfd6c9 100644 --- a/modules/services/lorri.nix +++ b/modules/services/lorri.nix @@ -4,56 +4,43 @@ with lib; let cfg = config.services.lorri; + home = "${builtins.getEnv "HOME"}"; in { - options = { - services.lorri.enable = mkOption { - type = types.bool; - default = false; - description = "Whether to enable the lorri service."; - }; - - services.lorri.package = mkOption { - type = types.path; - default = pkgs.lorri; - defaultText = "pkgs.lorri"; - description = "This option specifies the lorri package to use."; - }; - - services.lorri.logFile = mkOption { - type = types.nullOr types.path; - default = "/var/tmp/lorri.log"; - example = "/var/tmp/lorri.log"; - description = '' - The logfile to use for the lorri service. Alternatively - sudo launchctl debug system/org.nixos.lorri --stderr - can be used to stream the logs to a shell after restarting the service with - sudo launchctl kickstart -k system/org.nixos.lorri. - ''; - }; + options = { + services.lorri = { + enable = mkOption { + type = types.bool; + default = false; + description = "Whether to enable the lorri service."; + }; - services.lorri.tempDir = mkOption { - type = types.nullOr types.path; - default = null; - description = "The TMPDIR to use for lorri."; + logFile = mkOption { + type = types.nullOr types.path; + default = "${home}/Library/Logs/lorri.log"; + example = "${home}/Library/Logs/lorri.log"; + description = '' + The logfile to use for the lorri service. Alternatively + sudo launchctl debug system/com.target.lorri --stderr + can be used to stream the logs to a shell after restarting the service with + sudo launchctl kickstart -k system/com.target.lorri. + ''; + }; }; }; config = mkIf cfg.enable { - environment.systemPackages = [ cfg.package ]; + environment.systemPackages = [ pkgs.lorri ]; launchd.user.agents.lorri = { serviceConfig = { + Label = "com.target.lorri"; + ProgramArguments = with pkgs; ["${zsh}/bin/zsh" "-c" "${lorri}/bin/lorri daemon"]; KeepAlive = true; + RunAtLoad = true; ProcessType = "Background"; - LowPriorityIO = false; StandardOutPath = cfg.logFile; StandardErrorPath = cfg.logFile; - EnvironmentVariables = mkMerge [ - config.nix.envVars - { TMPDIR = mkIf (cfg.tempDir != null) cfg.tempDir; } - ]; }; - command = "${cfg.package}/bin/lorri daemon"; }; }; } \ No newline at end of file diff --git a/tests/services-lorri.nix b/tests/services-lorri.nix index e70eef5d7..d6a9935ca 100644 --- a/tests/services-lorri.nix +++ b/tests/services-lorri.nix @@ -2,17 +2,21 @@ let nix = pkgs.runCommand "nix-0.0.0" { version = "1.11.6"; } "mkdir -p $out"; - plistPath = "${config.out}/user/Library/LaunchAgents/org.nixos.lorri.plist"; + plistPath = "${config.out}/user/Library/LaunchAgents/com.target.lorri.plist"; in { services.lorri.enable = true; - nix.package = nix; + nix.package = pkgs.nix; test = '' echo checking lorri service in /Library/LaunchAgents >&2 - cat ${plistPath} grep -o "KeepAlive" ${plistPath} - grep -o "org.nixos.lorri" ${plistPath} - grep -o "exec ${pkgs.lorri}/bin/lorri daemon" ${plistPath} + grep -o "RunAtLoad" ${plistPath} + grep -o "ProcessType" ${plistPath} + grep -o "Background" ${plistPath} + grep -o "com.target.lorri" ${plistPath} + grep -o "${pkgs.zsh}/bin/zsh" ${plistPath} + grep -o "-c" ${plistPath} + grep -o "${pkgs.lorri}/bin/lorri daemon" ${plistPath} ''; } From 91504bd926dd451f149904157109c39d4d2788c8 Mon Sep 17 00:00:00 2001 From: Thibault Gagnaux Date: Sun, 30 Aug 2020 18:06:40 +0200 Subject: [PATCH 3/5] Removes zsh and getEnv and adds needed NIX_PATH env. --- modules/services/lorri.nix | 12 ++++++------ tests/services-lorri.nix | 14 ++++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/modules/services/lorri.nix b/modules/services/lorri.nix index 9e2dfd6c9..cefd005ce 100644 --- a/modules/services/lorri.nix +++ b/modules/services/lorri.nix @@ -4,7 +4,6 @@ with lib; let cfg = config.services.lorri; - home = "${builtins.getEnv "HOME"}"; in { options = { @@ -14,11 +13,11 @@ in default = false; description = "Whether to enable the lorri service."; }; - + logFile = mkOption { type = types.nullOr types.path; - default = "${home}/Library/Logs/lorri.log"; - example = "${home}/Library/Logs/lorri.log"; + default = "/var/tmp/lorri.log"; + example = "/var/tmp/lorri.log"; description = '' The logfile to use for the lorri service. Alternatively sudo launchctl debug system/com.target.lorri --stderr @@ -32,14 +31,15 @@ in config = mkIf cfg.enable { environment.systemPackages = [ pkgs.lorri ]; launchd.user.agents.lorri = { + command = with pkgs; "${lorri}/bin/lorri daemon"; + path = with pkgs; [ nix ]; serviceConfig = { - Label = "com.target.lorri"; - ProgramArguments = with pkgs; ["${zsh}/bin/zsh" "-c" "${lorri}/bin/lorri daemon"]; KeepAlive = true; RunAtLoad = true; ProcessType = "Background"; StandardOutPath = cfg.logFile; StandardErrorPath = cfg.logFile; + EnvironmentVariables = { NIX_PATH = "nixpkgs=" + toString pkgs.path; }; }; }; }; diff --git a/tests/services-lorri.nix b/tests/services-lorri.nix index d6a9935ca..90b45c40a 100644 --- a/tests/services-lorri.nix +++ b/tests/services-lorri.nix @@ -1,22 +1,24 @@ { config, pkgs, ... }: let - nix = pkgs.runCommand "nix-0.0.0" { version = "1.11.6"; } "mkdir -p $out"; - plistPath = "${config.out}/user/Library/LaunchAgents/com.target.lorri.plist"; + lorri = pkgs.runCommand "lorri-0.0.0" {} "mkdir $out"; + plistPath = "${config.out}/user/Library/LaunchAgents/org.nixos.lorri.plist"; in { services.lorri.enable = true; - nix.package = pkgs.nix; test = '' echo checking lorri service in /Library/LaunchAgents >&2 + grep -o "NIX_PATH" ${plistPath} + grep -o "EnvironmentVariables" ${plistPath} + grep -o "nixpkgs=" ${plistPath} grep -o "KeepAlive" ${plistPath} grep -o "RunAtLoad" ${plistPath} grep -o "ProcessType" ${plistPath} grep -o "Background" ${plistPath} - grep -o "com.target.lorri" ${plistPath} - grep -o "${pkgs.zsh}/bin/zsh" ${plistPath} + grep -o "/bin/sh" ${plistPath} + grep -o "org.nixos.lorri" ${plistPath} grep -o "-c" ${plistPath} - grep -o "${pkgs.lorri}/bin/lorri daemon" ${plistPath} + grep -o "exec ${pkgs.lorri}/bin/lorri daemon" ${plistPath} ''; } From 798fc52d126e975c91dc0f2dcd090a41d4e052c2 Mon Sep 17 00:00:00 2001 From: Thibault Gagnaux Date: Sun, 30 Aug 2020 19:27:41 +0200 Subject: [PATCH 4/5] Corrects description. --- modules/services/lorri.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/services/lorri.nix b/modules/services/lorri.nix index cefd005ce..a52c9194a 100644 --- a/modules/services/lorri.nix +++ b/modules/services/lorri.nix @@ -20,9 +20,9 @@ in example = "/var/tmp/lorri.log"; description = '' The logfile to use for the lorri service. Alternatively - sudo launchctl debug system/com.target.lorri --stderr + sudo launchctl debug system/org.nixos.lorri --stderr can be used to stream the logs to a shell after restarting the service with - sudo launchctl kickstart -k system/com.target.lorri. + sudo launchctl kickstart -k system/org.nixos.lorri. ''; }; }; From 1dbe3b71e334d4cf75e603e75e3f7ef40d973d91 Mon Sep 17 00:00:00 2001 From: Thibault Gagnaux Date: Mon, 31 Aug 2020 13:07:06 +0200 Subject: [PATCH 5/5] Disable StandardOutPath by default and refactor test to using plutil --- modules/services/lorri.nix | 2 +- tests/services-lorri.nix | 37 ++++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/modules/services/lorri.nix b/modules/services/lorri.nix index a52c9194a..354bcf44a 100644 --- a/modules/services/lorri.nix +++ b/modules/services/lorri.nix @@ -16,7 +16,7 @@ in logFile = mkOption { type = types.nullOr types.path; - default = "/var/tmp/lorri.log"; + default = null; example = "/var/tmp/lorri.log"; description = '' The logfile to use for the lorri service. Alternatively diff --git a/tests/services-lorri.nix b/tests/services-lorri.nix index 90b45c40a..f66c16f02 100644 --- a/tests/services-lorri.nix +++ b/tests/services-lorri.nix @@ -3,22 +3,33 @@ let lorri = pkgs.runCommand "lorri-0.0.0" {} "mkdir $out"; plistPath = "${config.out}/user/Library/LaunchAgents/org.nixos.lorri.plist"; + actual = pkgs.runCommand "convert-plist-to-json" { buildInputs = [ pkgs.xcbuild ]; } + "plutil -convert json -o $out ${plistPath}"; + actualJson = builtins.fromJSON (builtins.readFile "${actual.out}"); + expectedJson = builtins.fromJSON '' + { + "EnvironmentVariables": { + "NIX_PATH": "${"nixpkgs="+ toString pkgs.path}", + "PATH": "${builtins.unsafeDiscardStringContext pkgs.nix}/bin" + }, + "KeepAlive": true, + "Label": "org.nixos.lorri", + "ProcessType": "Background", + "ProgramArguments": [ + "/bin/sh", + "-c", + "exec ${builtins.unsafeDiscardStringContext pkgs.lorri}/bin/lorri daemon" + ], + "RunAtLoad": true + } + ''; + testResult = toString (actualJson == expectedJson); in { services.lorri.enable = true; - test = '' - echo checking lorri service in /Library/LaunchAgents >&2 - grep -o "NIX_PATH" ${plistPath} - grep -o "EnvironmentVariables" ${plistPath} - grep -o "nixpkgs=" ${plistPath} - grep -o "KeepAlive" ${plistPath} - grep -o "RunAtLoad" ${plistPath} - grep -o "ProcessType" ${plistPath} - grep -o "Background" ${plistPath} - grep -o "/bin/sh" ${plistPath} - grep -o "org.nixos.lorri" ${plistPath} - grep -o "-c" ${plistPath} - grep -o "exec ${pkgs.lorri}/bin/lorri daemon" ${plistPath} + ${pkgs.xcbuild}/bin/plutil -lint ${plistPath} + [ ${testResult} ]; ''; } +