Personal-use NixOS configuration
1# https://github.com/NixOS/nixpkgs/pull/503383
2
3{
4 lib,
5 stdenv,
6 buildGoModule,
7 fetchFromGitHub,
8 pam,
9 coreutils,
10 installShellFiles,
11 scdoc,
12 nixosTests,
13}:
14
15buildGoModule (finalAttrs: {
16 pname = "maddy";
17 version = "0.9.3";
18
19 src = fetchFromGitHub {
20 owner = "foxcpp";
21 repo = "maddy";
22 rev = "v${finalAttrs.version}";
23 sha256 = "sha256-rhQh8aNPv1pPGO6pMFX/1+w78SRho7puz39gejx+lpI=";
24 };
25
26 vendorHash = "sha256-URD2Q9Qo+huzRNIpOTKweleDzAxWtqHlxJks+eH2gsQ=";
27
28 tags = [ "libpam" ];
29
30 ldflags = [
31 "-s"
32 "-w"
33 "-X github.com/foxcpp/maddy.Version=${finalAttrs.version}"
34 ];
35
36 subPackages = [ "cmd/maddy" ];
37
38 buildInputs = [ pam ];
39
40 nativeBuildInputs = [
41 installShellFiles
42 scdoc
43 ];
44
45 postInstall = ''
46 for f in docs/man/*.scd; do
47 local page="docs/man/$(basename "$f" .scd)"
48 scdoc < "$f" > "$page"
49 installManPage "$page"
50 done
51
52 ln -s "$out/bin/maddy" "$out/bin/maddyctl"
53
54 mkdir -p $out/lib/systemd/system
55
56 substitute dist/systemd/maddy.service $out/lib/systemd/system/maddy.service \
57 --replace "/usr/local/bin/maddy" "$out/bin/maddy" \
58 --replace "/bin/kill" "${coreutils}/bin/kill"
59
60 substitute dist/systemd/maddy@.service $out/lib/systemd/system/maddy@.service \
61 --replace "/usr/local/bin/maddy" "$out/bin/maddy" \
62 --replace "/bin/kill" "${coreutils}/bin/kill"
63 '';
64
65 env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-Wno-error=strict-prototypes";
66
67 passthru.tests.nixos = nixosTests.maddy;
68
69 meta = {
70 description = "Composable all-in-one mail server";
71 homepage = "https://maddy.email";
72 license = lib.licenses.gpl3Plus;
73 maintainers = with lib.maintainers; [ nickcao ];
74 };
75})