]>
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 | inputs.openarc = { | |
12 | url = "github:trusteddomainproject/OpenARC"; | |
13 | flake = false; | |
14 | }; | |
15 | ||
16 | outputs = { self, myuids, openarc, flake-utils, nixpkgs }: flake-utils.lib.eachDefaultSystem (system: | |
17 | let | |
18 | lock = builtins.fromJSON (builtins.readFile ./flake.lock); | |
19 | pkgs = import nixpkgs { inherit system; overlays = []; }; | |
20 | inherit (pkgs) stdenv automake autoconf libbsd libtool openssl pkg-config libmilter file; | |
21 | in rec { | |
22 | packages.openarc = stdenv.mkDerivation rec { | |
23 | pname = "openarc"; | |
24 | version = "master-${builtins.substring 0 7 lock.nodes.openarc.locked.rev}"; | |
25 | src = openarc; | |
26 | buildInputs = [ automake autoconf libbsd libtool openssl pkg-config libmilter ]; | |
27 | ||
28 | configureFlags = [ | |
29 | "--with-milter=${libmilter}" | |
30 | ]; | |
31 | preConfigure = '' | |
32 | autoreconf --force --install | |
33 | sed -i -e "s@/usr/bin/file@${file}/bin/file@" ./configure | |
34 | ''; | |
35 | meta = { | |
36 | description = "Open source ARC implementation"; | |
37 | homepage = "https://github.com/trusteddomainproject/OpenARC"; | |
38 | platforms = stdenv.lib.platforms.unix; | |
39 | }; | |
40 | }; | |
41 | ||
42 | defaultPackage = packages.openarc; | |
43 | legacyPackages.openarc = packages.openarc; | |
44 | apps.openarc = flake-utils.lib.mkApp { drv = packages.openarc; }; | |
45 | defaultApp = apps.openarc; | |
46 | hydraJobs = checks; | |
47 | checks = { | |
48 | build = defaultPackage; | |
49 | } // pkgs.lib.optionalAttrs (builtins.elem system pkgs.lib.systems.doubles.linux) { | |
50 | test = | |
51 | let testing = import (nixpkgs + "/nixos/lib/testing-python.nix") { inherit system; }; | |
52 | in testing.makeTest { | |
53 | nodes = { | |
54 | server = { pkgs, ... }: { | |
55 | imports = [ self.nixosModule ]; | |
56 | config.services.openarc.enable = true; | |
57 | config.services.openarc.configFile = pkgs.writeText "openarc.conf" '' | |
58 | Domain foo.example.org | |
59 | KeyFile /etc/openarc/foo.key | |
60 | Selector foo | |
61 | ''; | |
62 | }; | |
63 | }; | |
64 | testScript = '' | |
65 | start_all() | |
66 | server.wait_until_fails("openarc.service") | |
67 | server.execute("install -m 0700 -o openarc -g openarc -d /etc/openarc") | |
68 | server.execute("echo some_key > /etc/openarc/foo.key") | |
69 | server.execute("chown openarc:openarc /etc/openarc/foo.key") | |
70 | server.execute("chmod 400 /etc/openarc/foo.key") | |
71 | server.systemctl("restart openarc") | |
72 | server.wait_for_unit("openarc.service") | |
73 | server.succeed("[ -S /run/openarc/openarc.sock ]") | |
74 | ''; | |
75 | }; | |
76 | }; | |
77 | }) // { | |
78 | nixosModule = { config, lib, pkgs, ... }: | |
79 | let | |
80 | cfg = config.services.openarc; | |
81 | defaultSock = "local:/run/openarc/openarc.sock"; | |
82 | args = [ "-f" "-p" cfg.socket ] ++ lib.optionals (cfg.configFile != null) [ "-c" cfg.configFile ]; | |
83 | in { | |
84 | options = { | |
85 | services.openarc = { | |
86 | enable = lib.mkOption { | |
87 | type = lib.types.bool; | |
88 | default = false; | |
89 | description = "Whether to enable the OpenARC sender authentication system."; | |
90 | }; | |
91 | ||
92 | socket = lib.mkOption { | |
93 | type = lib.types.str; | |
94 | default = defaultSock; | |
95 | description = "Socket which is used for communication with OpenARC."; | |
96 | }; | |
97 | ||
98 | user = lib.mkOption { | |
99 | type = lib.types.str; | |
100 | default = "openarc"; | |
101 | description = "User for the daemon."; | |
102 | }; | |
103 | ||
104 | group = lib.mkOption { | |
105 | type = lib.types.str; | |
106 | default = "openarc"; | |
107 | description = "Group for the daemon."; | |
108 | }; | |
109 | ||
110 | configFile = lib.mkOption { | |
111 | type = lib.types.nullOr lib.types.path; | |
112 | default = null; | |
113 | description = "Additional OpenARC configuration."; | |
114 | }; | |
115 | ||
116 | }; | |
117 | }; | |
118 | ||
119 | config = lib.mkIf cfg.enable { | |
120 | users.users = lib.optionalAttrs (cfg.user == "openarc") { | |
121 | openarc = { | |
122 | group = cfg.group; | |
123 | uid = myuids.lib.uids.openarc; | |
124 | }; | |
125 | }; | |
126 | ||
127 | users.groups = lib.optionalAttrs (cfg.group == "openarc") { | |
128 | openarc.gid = myuids.lib.gids.openarc; | |
129 | }; | |
130 | ||
131 | environment.systemPackages = [ self.defaultPackage."${pkgs.system}" ]; | |
132 | ||
133 | systemd.services.openarc = { | |
134 | description = "OpenARC daemon"; | |
135 | after = [ "network.target" ]; | |
136 | wantedBy = [ "multi-user.target" ]; | |
137 | ||
138 | serviceConfig = { | |
139 | ExecStart = "${self.defaultApp."${pkgs.system}".program} ${lib.escapeShellArgs args}"; | |
140 | User = cfg.user; | |
141 | Group = cfg.group; | |
142 | RuntimeDirectory = lib.optional (cfg.socket == defaultSock) "openarc"; | |
143 | PermissionsStartOnly = true; | |
144 | }; | |
145 | }; | |
146 | }; | |
147 | }; | |
148 | }; | |
149 | } |