Commit 784f09e4efd7

Vincent Demeester <vincent@sbr.pm>
2026-01-13 13:42:02
fix(imapfilter): read password from agenix secret file in Lua config
imapfilter doesn't support password files via command line flags. Instead, read the password directly in the Lua config from the agenix secret file. Changes: - Add read_password() function in Lua config - Read password from /run/agenix/icloud-vdemeester-password - Simplify systemd service (no need for bash wrapper) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 307e923
Changed files (2)
home/common/services/imapfilter-config.lua
@@ -7,10 +7,25 @@ options.subscribe = true
 ----------
 -- Accounts
 ----------
+
+-- Read password from agenix secret file
+function read_password(filepath)
+	local file = io.open(filepath, "r")
+	if not file then
+		error("Could not open password file: " .. filepath)
+	end
+	local password = file:read("*all"):match("^%s*(.-)%s*$")  -- Trim whitespace
+	file:close()
+	return password
+end
+
+local password_file = "/run/agenix/icloud-vdemeester-password"
+local icloud_password = read_password(password_file)
+
 account = IMAP {
 	server = 'imap.mail.me.com',
 	username = 'vdemeester@icloud.com',
-	-- Password will be provided via command line (-p flag)
+	password = icloud_password,
 	ssl = 'tls1.2',
 }
 
home/common/services/imapfilter.nix
@@ -13,11 +13,11 @@
 
     Service = {
       Type = "oneshot";
-      # Use agenix secret for password
+      # Password is read from agenix secret file in Lua config
       # Verbose mode enabled for testing new filters
-      ExecStart = "${pkgs.imapfilter}/bin/imapfilter -v -c ${./imapfilter-config.lua} -p /run/agenix/icloud-vdemeester-password";
+      ExecStart = "${pkgs.imapfilter}/bin/imapfilter -v -c ${./imapfilter-config.lua}";
       # Standard mode (use after testing is complete)
-      # ExecStart = "${pkgs.imapfilter}/bin/imapfilter -c ${./imapfilter-config.lua} -p /run/agenix/icloud-vdemeester-password";
+      # ExecStart = "${pkgs.imapfilter}/bin/imapfilter -c ${./imapfilter-config.lua}";
     };
   };