From 1eb2dcf3a940b25acad4caef51584c2d4136da72 Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 23 Dec 2020 22:13:05 +0100 Subject: [PATCH] lieer: add path to notmuch config This fetches the notmuch configuration path from the `NOTMUCH_CONFIG` session variable, if it is set. Specifically, this makes the lieer service find the configuration generated by the notmuch module. --- modules/services/lieer.nix | 2 + ...r-service.nix => account-with-notmuch.nix} | 17 +++++- .../lieer/account-without-notmuch.nix | 60 +++++++++++++++++++ tests/modules/services/lieer/default.nix | 5 +- .../lieer/lieer-service-expected.service | 8 --- 5 files changed, 82 insertions(+), 10 deletions(-) rename tests/modules/services/lieer/{lieer-service.nix => account-with-notmuch.nix} (55%) create mode 100644 tests/modules/services/lieer/account-without-notmuch.nix delete mode 100644 tests/modules/services/lieer/lieer-service-expected.service diff --git a/modules/services/lieer.nix b/modules/services/lieer.nix index 571e2af75..eb4198409 100644 --- a/modules/services/lieer.nix +++ b/modules/services/lieer.nix @@ -26,6 +26,8 @@ let Type = "oneshot"; ExecStart = "${pkgs.gmailieer}/bin/gmi sync"; WorkingDirectory = account.maildir.absPath; + Environment = mkIf (config.home.sessionVariables ? NOTMUCH_CONFIG) + "NOTMUCH_CONFIG=${config.home.sessionVariables.NOTMUCH_CONFIG}"; }; }; }; diff --git a/tests/modules/services/lieer/lieer-service.nix b/tests/modules/services/lieer/account-with-notmuch.nix similarity index 55% rename from tests/modules/services/lieer/lieer-service.nix rename to tests/modules/services/lieer/account-with-notmuch.nix index af3074b0f..b6c85384c 100644 --- a/tests/modules/services/lieer/lieer-service.nix +++ b/tests/modules/services/lieer/account-with-notmuch.nix @@ -6,6 +6,7 @@ with lib; imports = [ ../../accounts/email-test-accounts.nix ]; config = { + programs.notmuch.enable = true; services.lieer.enable = true; accounts.email.accounts = { @@ -24,6 +25,8 @@ with lib; gmailieer = pkgs.writeScriptBin "dummy-gmailieer" "" // { outPath = "@lieer@"; }; + + notmuch = pkgs.writeScriptBin "dummy-notmuch" ""; }) ]; @@ -32,7 +35,19 @@ with lib; assertFileExists home-files/.config/systemd/user/lieer-hm-example-com.timer assertFileContent home-files/.config/systemd/user/lieer-hm-example-com.service \ - ${./lieer-service-expected.service} + ${ + pkgs.writeText "lieer-service-expected.service" '' + [Service] + Environment=NOTMUCH_CONFIG=/home/hm-user/.config/notmuch/notmuchrc + ExecStart=@lieer@/bin/gmi sync + Type=oneshot + WorkingDirectory=/home/hm-user/Mail/hm@example.com + + [Unit] + ConditionPathExists=/home/hm-user/Mail/hm@example.com/.gmailieer.json + Description=lieer Gmail synchronization for hm@example.com + '' + } assertFileContent home-files/.config/systemd/user/lieer-hm-example-com.timer \ ${./lieer-service-expected.timer} ''; diff --git a/tests/modules/services/lieer/account-without-notmuch.nix b/tests/modules/services/lieer/account-without-notmuch.nix new file mode 100644 index 000000000..e20395515 --- /dev/null +++ b/tests/modules/services/lieer/account-without-notmuch.nix @@ -0,0 +1,60 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + imports = [ ../../accounts/email-test-accounts.nix ]; + + config = { + services.lieer.enable = true; + + accounts.email.accounts = { + "hm@example.com".lieer.enable = true; + "hm@example.com".lieer.sync.enable = true; + }; + + nixpkgs.overlays = [ + (self: super: { + gmailieer = pkgs.writeScriptBin "dummy-gmailieer" "" // { + outPath = "@lieer@"; + }; + }) + ]; + + test.asserts.warnings.expected = ['' + lieer is enabled for the following email accounts, but notmuch is not: + + hm@example.com + + Notmuch can be enabled with: + + accounts.email.accounts.hm@example.com.notmuch.enable = true; + + If you have configured notmuch outside of Home Manager, you can suppress this + warning with: + + programs.lieer.notmuchSetupWarning = false; + '']; + + nmt.script = '' + assertFileExists home-files/.config/systemd/user/lieer-hm-example-com.service + assertFileExists home-files/.config/systemd/user/lieer-hm-example-com.timer + + assertFileContent home-files/.config/systemd/user/lieer-hm-example-com.service \ + ${ + pkgs.writeText "lieer-service-expected.service" '' + [Service] + ExecStart=@lieer@/bin/gmi sync + Type=oneshot + WorkingDirectory=/home/hm-user/Mail/hm@example.com + + [Unit] + ConditionPathExists=/home/hm-user/Mail/hm@example.com/.gmailieer.json + Description=lieer Gmail synchronization for hm@example.com + '' + } + assertFileContent home-files/.config/systemd/user/lieer-hm-example-com.timer \ + ${./lieer-service-expected.timer} + ''; + }; +} diff --git a/tests/modules/services/lieer/default.nix b/tests/modules/services/lieer/default.nix index 1d6b435a1..864c5f2e7 100644 --- a/tests/modules/services/lieer/default.nix +++ b/tests/modules/services/lieer/default.nix @@ -1 +1,4 @@ -{ lieer-service = ./lieer-service.nix; } +{ + lieer-account-with-notmuch = ./account-with-notmuch.nix; + lieer-account-without-notmuch = ./account-without-notmuch.nix; +} diff --git a/tests/modules/services/lieer/lieer-service-expected.service b/tests/modules/services/lieer/lieer-service-expected.service deleted file mode 100644 index 1110e85c4..000000000 --- a/tests/modules/services/lieer/lieer-service-expected.service +++ /dev/null @@ -1,8 +0,0 @@ -[Service] -ExecStart=@lieer@/bin/gmi sync -Type=oneshot -WorkingDirectory=/home/hm-user/Mail/hm@example.com - -[Unit] -ConditionPathExists=/home/hm-user/Mail/hm@example.com/.gmailieer.json -Description=lieer Gmail synchronization for hm@example.com