X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FConfig%2FNix.git;a=blobdiff_plain;f=flakes%2Fopendmarc%2Fflake.nix;fp=flakes%2Fopendmarc%2Fflake.nix;h=4d6354b845dc5bfba8ad388c30192e3140358c6e;hp=0000000000000000000000000000000000000000;hb=a1a2455f53bde1235b221a842d3c888c51fcecac;hpb=749623765bef80615fc21e73aff89521d262e277 diff --git a/flakes/opendmarc/flake.nix b/flakes/opendmarc/flake.nix new file mode 100644 index 0000000..4d6354b --- /dev/null +++ b/flakes/opendmarc/flake.nix @@ -0,0 +1,145 @@ +{ + description = "Open source ARC implementation"; + + inputs.myuids = { + url = "https://git.immae.eu/perso/Immae/Config/Nix.git"; + type = "git"; + dir = "flakes/myuids"; + }; + inputs.libspf2 = { + url = "https://git.immae.eu/perso/Immae/Config/Nix.git"; + type = "git"; + dir = "flakes/libspf2"; + }; + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs"; + + outputs = { self, myuids, libspf2, flake-utils, nixpkgs }: flake-utils.lib.eachSystem ["aarch64-linux" "i686-linux" "x86_64-linux"] (system: + let + libspf2' = libspf2.defaultPackage."${system}"; + pkgs = import nixpkgs { inherit system; overlays = []; }; + inherit (pkgs) fetchurl stdenv libbsd perl openssl libmilter file libnsl; + in rec { + packages.opendmarc = stdenv.mkDerivation rec { + pname = "opendmarc"; + version = "1.3.2"; + + src = fetchurl { + url = "mirror://sourceforge/opendmarc/files/${pname}-${version}.tar.gz"; + sha256 = "1yrggj8yq0915y2i34gfz2xpl1w2lgb1vggp67rwspgzm40lng11"; + }; + + configureFlags= [ + "--with-spf" + "--with-spf2-include=${libspf2'}/include/spf2" + "--with-spf2-lib=${libspf2'}/lib/" + "--with-milter=${libmilter}" + ]; + + buildInputs = [ libspf2' libbsd openssl libmilter perl libnsl ]; + + meta = { + description = "Free open source software implementation of the DMARC specification"; + homepage = "http://www.trusteddomain.org/opendmarc/"; + platforms = stdenv.lib.platforms.unix; + }; + }; + + defaultPackage = packages.opendmarc; + legacyPackages.opendmarc = packages.opendmarc; + apps.opendmarc = flake-utils.lib.mkApp { drv = packages.opendmarc; }; + defaultApp = apps.opendmarc; + hydraJobs = checks; + checks = { + build = defaultPackage; + } // pkgs.lib.optionalAttrs (builtins.elem system pkgs.lib.systems.doubles.linux) { + test = + let testing = import (nixpkgs + "/nixos/lib/testing-python.nix") { inherit system; }; + in testing.makeTest { + nodes = { + server = { pkgs, ... }: { + imports = [ self.nixosModule ]; + config.services.opendmarc.enable = true; + }; + }; + testScript = '' + start_all() + server.wait_for_unit("opendmarc.service") + server.succeed("[ -S /run/opendmarc/opendmarc.sock ]") + ''; + }; + }; + }) // { + nixosModules = (if builtins.pathExists ../private/opendmarc.nix then import ../private/opendmarc.nix nixpkgs else {}); + nixosModule = { config, lib, pkgs, ... }: + let + cfg = config.services.opendmarc; + defaultSock = "local:/run/opendmarc/opendmarc.sock"; + args = [ "-f" "-l" "-p" cfg.socket ] ++ lib.optionals (cfg.configFile != null) [ "-c" cfg.configFile ]; + in { + options = { + services.opendmarc = { + enable = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Whether to enable the OpenDMARC sender authentication system."; + }; + + socket = lib.mkOption { + type = lib.types.str; + default = defaultSock; + description = "Socket which is used for communication with OpenDMARC."; + }; + + user = lib.mkOption { + type = lib.types.str; + default = "opendmarc"; + description = "User for the daemon."; + }; + + group = lib.mkOption { + type = lib.types.str; + default = "opendmarc"; + description = "Group for the daemon."; + }; + + configFile = lib.mkOption { + type = lib.types.nullOr lib.types.path; + default = null; + description = "Additional OpenDMARC configuration."; + }; + + }; + }; + + config = lib.mkIf cfg.enable { + users.users = lib.optionalAttrs (cfg.user == "opendmarc") { + opendmarc = { + group = cfg.group; + uid = myuids.lib.uids.opendmarc; + }; + }; + + users.groups = lib.optionalAttrs (cfg.group == "opendmarc") { + opendmarc.gid = myuids.lib.gids.opendmarc; + }; + + environment.systemPackages = [ self.defaultPackage."${pkgs.system}" ]; + + systemd.services.opendmarc = { + description = "OpenDMARC daemon"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + ExecStart = "${self.defaultApp."${pkgs.system}".program} ${lib.escapeShellArgs args}"; + User = cfg.user; + Group = cfg.group; + RuntimeDirectory = lib.optional (cfg.socket == defaultSock) "opendmarc"; + PermissionsStartOnly = true; + }; + }; + }; + }; + }; + }