]>
Commit | Line | Data |
---|---|---|
1 | { | |
2 | description = "Open source ARC implementation"; | |
3 | ||
4 | inputs.myuids = { | |
5 | url = "https://git.immae.eu/perso/Immae/Config/Nix.git"; | |
6 | type = "git"; | |
7 | dir = "flakes/myuids"; | |
8 | }; | |
9 | inputs.flake-utils.url = "github:numtide/flake-utils"; | |
10 | inputs.nixpkgs.url = "github:NixOS/nixpkgs"; | |
11 | ||
12 | outputs = { self, myuids, flake-utils, nixpkgs }: flake-utils.lib.eachSystem ["aarch64-linux" "i686-linux" "x86_64-linux"] (system: | |
13 | let | |
14 | pkgs = import nixpkgs { inherit system; overlays = []; }; | |
15 | in rec { | |
16 | packages.opendmarc = pkgs.callPackage ./. {}; | |
17 | defaultPackage = packages.opendmarc; | |
18 | legacyPackages.opendmarc = packages.opendmarc; | |
19 | apps.opendmarc = flake-utils.lib.mkApp { drv = packages.opendmarc; }; | |
20 | defaultApp = apps.opendmarc; | |
21 | hydraJobs = checks; | |
22 | checks = { | |
23 | build = defaultPackage; | |
24 | } // pkgs.lib.optionalAttrs (builtins.elem system pkgs.lib.systems.doubles.linux) { | |
25 | test = | |
26 | let testing = import (nixpkgs + "/nixos/lib/testing-python.nix") { inherit system; }; | |
27 | in testing.makeTest { | |
28 | nodes = { | |
29 | server = { pkgs, ... }: { | |
30 | imports = [ self.nixosModule ]; | |
31 | config.services.opendmarc.enable = true; | |
32 | }; | |
33 | }; | |
34 | testScript = '' | |
35 | start_all() | |
36 | server.wait_for_unit("opendmarc.service") | |
37 | server.succeed("[ -S /run/opendmarc/opendmarc.sock ]") | |
38 | ''; | |
39 | }; | |
40 | }; | |
41 | }) // rec { | |
42 | overlays = { | |
43 | opendmarc = final: prev: { | |
44 | opendmarc = self.defaultPackage."${final.system}"; | |
45 | }; | |
46 | }; | |
47 | overlay = overlays.opendmarc; | |
48 | nixosModule = { config, lib, pkgs, ... }: | |
49 | let | |
50 | cfg = config.services.opendmarc; | |
51 | defaultSock = "/run/opendmarc/opendmarc.sock"; | |
52 | args = [ "-f" "-l" "-p" "local:${cfg.socket}" ] ++ lib.optionals (cfg.configFile != null) [ "-c" cfg.configFile ]; | |
53 | in { | |
54 | options = { | |
55 | services.opendmarc = { | |
56 | enable = lib.mkOption { | |
57 | type = lib.types.bool; | |
58 | default = false; | |
59 | description = "Whether to enable the OpenDMARC sender authentication system."; | |
60 | }; | |
61 | ||
62 | socket = lib.mkOption { | |
63 | type = lib.types.str; | |
64 | default = defaultSock; | |
65 | description = "Socket which is used for communication with OpenDMARC."; | |
66 | }; | |
67 | ||
68 | user = lib.mkOption { | |
69 | type = lib.types.str; | |
70 | default = "opendmarc"; | |
71 | description = "User for the daemon."; | |
72 | }; | |
73 | ||
74 | group = lib.mkOption { | |
75 | type = lib.types.str; | |
76 | default = "opendmarc"; | |
77 | description = "Group for the daemon."; | |
78 | }; | |
79 | ||
80 | configFile = lib.mkOption { | |
81 | type = lib.types.nullOr lib.types.path; | |
82 | default = null; | |
83 | description = "Additional OpenDMARC configuration."; | |
84 | }; | |
85 | ||
86 | }; | |
87 | }; | |
88 | ||
89 | config = lib.mkIf cfg.enable { | |
90 | nixpkgs.overlays = [ self.overlay ]; | |
91 | users.users = lib.optionalAttrs (cfg.user == "opendmarc") { | |
92 | opendmarc = { | |
93 | group = cfg.group; | |
94 | uid = myuids.lib.uids.opendmarc; | |
95 | }; | |
96 | }; | |
97 | ||
98 | users.groups = lib.optionalAttrs (cfg.group == "opendmarc") { | |
99 | opendmarc.gid = myuids.lib.gids.opendmarc; | |
100 | }; | |
101 | ||
102 | environment.systemPackages = [ pkgs.opendmarc ]; | |
103 | ||
104 | systemd.services.opendmarc = { | |
105 | description = "OpenDMARC daemon"; | |
106 | after = [ "network.target" ]; | |
107 | wantedBy = [ "multi-user.target" ]; | |
108 | ||
109 | serviceConfig = { | |
110 | ExecStart = "${self.defaultApp."${pkgs.system}".program} ${lib.escapeShellArgs args}"; | |
111 | User = cfg.user; | |
112 | Group = cfg.group; | |
113 | RuntimeDirectory = lib.optional (cfg.socket == defaultSock) "opendmarc"; | |
114 | PermissionsStartOnly = true; | |
115 | }; | |
116 | }; | |
117 | }; | |
118 | }; | |
119 | }; | |
120 | } |