summaryrefslogtreecommitdiff
path: root/user-profiles/feeds/module.nix
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2021-09-04 21:52:24 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2021-09-04 21:52:24 +0200
commit09d82350943286abc4a0b66c84287eb30a4b6f43 (patch)
tree9a823767b6fd5d073934a5627190755ff88b4c2c /user-profiles/feeds/module.nix
parent2a7280335e2d290ea96c795dbb5bbc12cdd8061b (diff)
downloadnixos-09d82350943286abc4a0b66c84287eb30a4b6f43.tar
nixos-09d82350943286abc4a0b66c84287eb30a4b6f43.tar.gz
nixos-09d82350943286abc4a0b66c84287eb30a4b6f43.tar.bz2
nixos-09d82350943286abc4a0b66c84287eb30a4b6f43.tar.xz
nixos-09d82350943286abc4a0b66c84287eb30a4b6f43.zip
feeds: imm-notmuch-insert
Diffstat (limited to 'user-profiles/feeds/module.nix')
-rw-r--r--user-profiles/feeds/module.nix114
1 files changed, 114 insertions, 0 deletions
diff --git a/user-profiles/feeds/module.nix b/user-profiles/feeds/module.nix
new file mode 100644
index 00000000..7a29331b
--- /dev/null
+++ b/user-profiles/feeds/module.nix
@@ -0,0 +1,114 @@
1{ config, flakeInputs, pkgs, lib, system, ... }:
2
3with lib;
4
5let
6 inherit (flakeInputs.home-manager.lib) hm;
7
8 configPath = "${config.xdg.configHome}/feeds/notmuchrc";
9 databasePath = "${config.xdg.dataHome}/feeds";
10
11 imm = flakeInputs.imm.defaultPackage.${system};
12 immWrapped = pkgs.runCommand "${imm.name}-wrapped-${config.home.username}"
13 { nativeBuildInputs = with pkgs; [ makeWrapper imm ];
14 } ''
15 mkdir -p $out/bin
16 makeWrapper ${imm}/bin/imm $out/bin/imm \
17 --add-flags --callbacks=${notmuchCallbacks}
18 '';
19
20 notmuchCallbacks = pkgs.writeText "imm-callbacks-${config.home.username}.dhall" ''
21 let Callback : Type =
22 { _executable : Text
23 , _arguments : List Text
24 }
25
26 let notmuchInsert =
27 { _executable = "${immNotmuchInsert}/bin/imm-notmuch-insert"
28 , _arguments = []
29 }
30
31 let config : List Callback = [ notmuchInsert ]
32 in config
33 '';
34
35 immNotmuchInsert = pkgs.stdenv.mkDerivation rec {
36 name = "imm-notmuch-insert-${config.home.username}";
37 src = ./imm-notmuch-insert.py;
38
39 phases = [ "buildPhase" "checkPhase" "installPhase" "fixupPhase" ];
40
41 python = pkgs.python39.withPackages (ps: with ps; [ configparser ]);
42
43 nativeBuildInputs = with pkgs; [ makeWrapper ];
44
45 buildPhase = ''
46 substituteAll $src imm-notmuch-insert
47 '';
48
49 doCheck = true;
50 checkPhase = ''
51 ${python}/bin/python -m py_compile imm-notmuch-insert
52 '';
53
54 installPhase = ''
55 install -m 0755 -D -t $out/bin \
56 imm-notmuch-insert
57 '';
58
59 fixupPhase = ''
60 wrapProgram $out/bin/imm-notmuch-insert \
61 --prefix PATH : ${pkgs.notmuch}/bin \
62 --set NOTMUCH_CONFIG ${configPath}
63 '';
64 };
65
66 mkIniKeyValue = key: value:
67 let
68 tweakVal = v:
69 if isString v then
70 v
71 else if isList v then
72 concatMapStringsSep ";" tweakVal v
73 else if isBool v then
74 (if v then "true" else "false")
75 else
76 toString v;
77 in "${key}=${tweakVal value}";
78
79 notmuchIni = {
80 database = { path = databasePath; };
81
82 maildir = { synchronize_flags = false; };
83
84 new = {
85 ignore = [];
86 tags = ["new"];
87 };
88
89 user = {
90 name = config.home.username;
91 primary_email = "${config.home.username}@imm.invalid";
92 };
93
94 search = { exclude_tags = ["deleted"]; };
95 };
96in {
97 config = {
98 home.packages = [ immWrapped ];
99
100 home.activation.createImm = hm.dag.entryAfter ["writeBoundary"] ''
101 $DRY_RUN_CMD mkdir -p $VERBOSE_ARG ${config.xdg.configHome}/imm
102 '';
103
104 xdg.configFile."feeds/notmuchrc".text =
105 let toIni = generators.toINI { mkKeyValue = mkIniKeyValue; };
106 in ''
107 # Generated by Home Manager.
108 '' + toIni notmuchIni;
109
110 home.activation.createFeedsDatabase = hm.dag.entryAfter ["writeBoundary"] ''
111 $DRY_RUN_CMD mkdir -p $VERBOSE_ARG ${databasePath}
112 '';
113 };
114}