]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - flakes/openarc/flake.nix
Use flake for openarc
[perso/Immae/Config/Nix.git] / flakes / openarc / flake.nix
CommitLineData
bb9bc238
IB
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 checks = {
47 build = defaultPackage;
48 } // pkgs.lib.optionalAttrs (builtins.elem system pkgs.lib.systems.doubles.linux) {
49 test =
50 let testing = import (nixpkgs + "/nixos/lib/testing-python.nix") { inherit system; };
51 in testing.makeTest {
52 nodes = {
53 server = { pkgs, ... }: {
54 imports = [ self.nixosModule ];
55 config.services.openarc.enable = true;
56 config.services.openarc.configFile = pkgs.writeText "openarc.conf" ''
57 Domain foo.example.org
58 KeyFile /etc/openarc/foo.key
59 Selector foo
60 '';
61 };
62 };
63 testScript = ''
64 start_all()
65 server.wait_until_fails("openarc.service")
66 server.execute("install -m 0700 -o openarc -g openarc -d /etc/openarc")
67 server.execute("echo some_key > /etc/openarc/foo.key")
68 server.execute("chown openarc:openarc /etc/openarc/foo.key")
69 server.execute("chmod 400 /etc/openarc/foo.key")
70 server.systemctl("restart openarc")
71 server.wait_for_unit("openarc.service")
72 server.succeed("[ -S /run/openarc/openarc.sock ]")
73 '';
74 };
75 };
76 }) // {
77 hydraJobs.build = nixpkgs.lib.genAttrs flake-utils.lib.defaultSystems (system: self.defaultPackage."${system}");
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 {
e8864bbf
IB
120 users.users = lib.optionalAttrs (cfg.user == "openarc") {
121 openarc = {
122 group = cfg.group;
123 uid = myuids.lib.uids.openarc;
124 };
bb9bc238
IB
125 };
126
e8864bbf
IB
127 users.groups = lib.optionalAttrs (cfg.group == "openarc") {
128 openarc.gid = myuids.lib.gids.openarc;
bb9bc238
IB
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 }