Signed-off-by: Florian Brandes <florian.brandes@posteo.de>
This commit is contained in:
2024-07-27 18:14:12 +02:00
parent b306ecd228
commit d3055a9e8b
5 changed files with 73 additions and 38 deletions

View File

@@ -1,4 +1,7 @@
{ pkgs ? import <nixpkgs> { }, lib ? pkgs.lib, }: {
pkgs ? import <nixpkgs> { },
lib ? pkgs.lib,
}:
pkgs.python3Packages.buildPythonPackage rec { pkgs.python3Packages.buildPythonPackage rec {
pname = "smtprd-ng"; pname = "smtprd-ng";
@@ -21,10 +24,8 @@ pkgs.python3Packages.buildPythonPackage rec {
meta = { meta = {
description = "SMTP forwarding relay daemon with signing and encryption"; description = "SMTP forwarding relay daemon with signing and encryption";
homepage = homepage = "https://app.radicle.xyz/nodes/seed.radicle.garden/rad:z3gWc1qgaeZaoGwL4WTstLNoqjayM";
"https://app.radicle.xyz/nodes/seed.radicle.garden/rad:z3gWc1qgaeZaoGwL4WTstLNoqjayM";
license = lib.licenses.agpl3Only; license = lib.licenses.agpl3Only;
maintainers = [ lib.maintainers.gador ]; maintainers = [ lib.maintainers.gador ];
}; };
} }

View File

@@ -1,10 +1,24 @@
{ pkgs, lib, config, inputs, ... }: {
pkgs,
lib,
config,
inputs,
...
}:
let req = pkgs.concatText "req" [ ./requirements.txt ./requirements-dev.txt ]; let
req = pkgs.concatText "req" [
in { ./requirements.txt
./requirements-dev.txt
];
in
{
# https://devenv.sh/packages/ # https://devenv.sh/packages/
packages = [ pkgs.file pkgs.swig4 pkgs.openssl ]; packages = [
pkgs.file
pkgs.swig4
pkgs.openssl
];
# https://devenv.sh/languages/ # https://devenv.sh/languages/
languages.nix.enable = true; languages.nix.enable = true;
@@ -19,6 +33,7 @@ in {
# https://devenv.sh/pre-commit-hooks/ # https://devenv.sh/pre-commit-hooks/
pre-commit.hooks = { pre-commit.hooks = {
nixfmt.enable = true; nixfmt.enable = true;
nixfmt.package = pkgs.nixfmt-rfc-style;
# remove unused imports # remove unused imports
autoflake.enable = true; autoflake.enable = true;
# formatter # formatter
@@ -31,6 +46,5 @@ in {
pylint.enable = true; pylint.enable = true;
detect-private-keys.enable = true; detect-private-keys.enable = true;
detect-private-keys.excludes = [ "tests/" ]; detect-private-keys.excludes = [ "tests/" ];
}; };
} }

View File

@@ -7,15 +7,32 @@
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
}; };
outputs = { self, nixpkgs, flake-utils, pre-commit-hooks, }: outputs =
let supportedSystems = [ "x86_64-linux" "aarch64-darwin" ]; {
in { self,
nixpkgs,
flake-utils,
pre-commit-hooks,
}:
let
supportedSystems = [
"x86_64-linux"
"aarch64-darwin"
];
in
{
nixosModules.smtprd-ng = import ./module.nix; nixosModules.smtprd-ng = import ./module.nix;
overlays.default = import ./overlay.nix { inherit self; }; overlays.default = import ./overlay.nix { inherit self; };
} // flake-utils.lib.eachSystem supportedSystems (system: }
let pkgs = import nixpkgs { inherit system; }; // flake-utils.lib.eachSystem supportedSystems (
in { system:
packages = { smtprd-ng = pkgs.callPackage ./. { }; }; let
pkgs = import nixpkgs { inherit system; };
in
{
packages = {
smtprd-ng = pkgs.callPackage ./. { };
};
packages.default = self.packages.${system}.smtprd-ng; packages.default = self.packages.${system}.smtprd-ng;
@@ -24,12 +41,12 @@
src = ./.; src = ./.;
hooks = { hooks = {
nixfmt.enable = true; nixfmt.enable = true;
nixfmt.package = pkgs.nixfmt-rfc-style;
autoflake.enable = true; autoflake.enable = true;
black.enable = true; black.enable = true;
isort.enable = true; isort.enable = true;
isort.settings.flags = "--profile black"; isort.settings.flags = "--profile black";
pylint.enable = pylint.enable = false; # doesn't work correctly with module imports in flake
false; # doesn't work correctly with module imports in flake
detect-private-keys.enable = true; detect-private-keys.enable = true;
detect-private-keys.excludes = [ "tests/" ]; detect-private-keys.excludes = [ "tests/" ];
}; };
@@ -41,5 +58,6 @@
type = "app"; type = "app";
program = "${self.packages.${system}.smtprd-ng}/bin/smtprd-ng"; program = "${self.packages.${system}.smtprd-ng}/bin/smtprd-ng";
}; };
}); }
);
} }

View File

@@ -1,4 +1,9 @@
{ config, lib, pkgs, ... }: {
config,
lib,
pkgs,
...
}:
with lib; with lib;
let let
cfg = config.services.smtprd-ng; cfg = config.services.smtprd-ng;
@@ -13,23 +18,23 @@ let
hostname = cfg.client.hostname; hostname = cfg.client.hostname;
port = cfg.client.port; port = cfg.client.port;
username = cfg.client.username; username = cfg.client.username;
password_file = if cfg.client.password_file != "" then password_file =
"/run/credentials/smtprd-ng.service/password_file" if cfg.client.password_file != "" then "/run/credentials/smtprd-ng.service/password_file" else "";
else
"";
sender = cfg.client.sender; sender = cfg.client.sender;
use_tls = cfg.client.use_tls; use_tls = cfg.client.use_tls;
start_tls = cfg.client.start_tls; start_tls = cfg.client.start_tls;
smime_cert = cfg.client.smime_cert; smime_cert = cfg.client.smime_cert;
smime_cert_private = if cfg.client.smime_cert_private != "" then smime_cert_private =
"/run/credentials/smtprd-ng.service/smime_cert_private" if cfg.client.smime_cert_private != "" then
else "/run/credentials/smtprd-ng.service/smime_cert_private"
""; else
"";
}; };
emails = cfg.emails; emails = cfg.emails;
}; };
confFile = pkgs.writeText "config.ini" cfgText; confFile = pkgs.writeText "config.ini" cfgText;
in { in
{
options.services.smtprd-ng = { options.services.smtprd-ng = {
enable = mkEnableOption "smtprd-ng"; enable = mkEnableOption "smtprd-ng";
@@ -148,10 +153,10 @@ in {
message = "Use either TLS or STARTTLS, not both."; message = "Use either TLS or STARTTLS, not both.";
} }
{ {
assertion = cfg.client.smime_cert == null || (cfg.client.smime_cert assertion =
!= null && cfg.client.smime_cert_private != null); cfg.client.smime_cert == null
message = || (cfg.client.smime_cert != null && cfg.client.smime_cert_private != null);
"If a S/MIME certificate should be used to sign messages, the private key to this certificate must be supplied."; message = "If a S/MIME certificate should be used to sign messages, the private key to this certificate must be supplied.";
} }
{ {
assertion = cfg.emails != null; assertion = cfg.emails != null;

View File

@@ -1,4 +1 @@
{ self }: { self }: _final: prev: { smtprd-ng = self.packages.${prev.system}.smtprd-ng; }
_final: prev: {
smtprd-ng = self.packages.${prev.system}.smtprd-ng;
}