Skip to content

Commit

Permalink
mailcow: add
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Mar 30, 2024
1 parent 9e52985 commit 3b1025a
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
defaults
ethtool-setringmax
prometheus-exporter-gateway
mailcow
];
ansible_default = default ++ [
nix-unify.nixosModules.ansible
Expand Down
31 changes: 31 additions & 0 deletions modules/mailcow.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{ config, pkgs, lib, inputs, ... }:

with lib;
let
cfg = config.services.mailcow;
in
{
options.services.mailcow = {
enable = mkEnableOption "mailcow";
};

config = mkIf cfg.enable {
virtualisation.docker.enable = true;
networking.firewall.trustedInterfaces = [ "br-mailcow" "docker*" ];
environment.systemPackages = with pkgs; [
mailcow
];

# mailcow docker native ipv6 nat
virtualisation.docker.daemon.settings = {
ipv6 = true;
fixed-cidr-v6 = "fd00:dead:beef:c0::/80";
experimental = true;
ip6tables = true;
};
# convince the mailcow script we have enabled ipv6nat
environment.etc."docker/daemon.json".text = ''
{"ipv6":true,"fixed-cidr-v6":"fd00:dead:beef:c0::/80","experimental":true,"ip6tables":true}
'';
};
}
48 changes: 48 additions & 0 deletions pkgs/mailcow/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{ stdenv
, which
, openssl
, bash
, coreutils
, curl
, wget
, docker
, git
, gawk
, gnugrep
, gnused
, iptables-nftables-compat
, lib
}:

let
pathPkgs = [
which
openssl
bash
coreutils
curl
wget
docker # config.virtualisation.docker.package
git
gawk
gnugrep
gnused
iptables-nftables-compat
];
path = lib.makeBinPath pathPkgs;
in
stdenv.mkDerivation {
name = "mailcow";

src = ./src;

buildPhase = ''
substituteInPlace bin.sh \
--subst-var-by path "${path}"
'';

installPhase = ''
install -m 755 -D bin.sh $out/bin/mailcow
ln -s $out/bin/mailcow $out/bin/mailcow-shell
'';
}
34 changes: 34 additions & 0 deletions pkgs/mailcow/src/bin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

set -euo pipefail

export PATH=@path@

MAILCOW_DIR="/root/mailcow"

die() {
echo "ERROR: $*" >&2
exit 2
}

if [ "$(id -u)" -gt 0 ]; then
die "must be root"
fi

if [ ! -e "$MAILCOW_DIR" ]; then
git clone https://github.com/mailcow/mailcow-dockerized "$MAILCOW_DIR"
fi

pushd "$MAILCOW_DIR"

if [ "$(basename "$0")" = "mailcow-shell" ]; then
echo "opening shell..."
exec $SHELL
exit $?
fi

if [ ! -e mailcow.conf ]; then
./generate_config.sh
fi

./update.sh
18 changes: 18 additions & 0 deletions tests/mailcow.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
inputs: mod: { pkgs, lib, ... }:
{
name = "mailcow";

node.specialArgs.inputs = inputs;

nodes = {
server = { lib, pkgs, ... }: {
imports = mod.default;
services.mailcow.enable = true;
};
};

testScript = ''
start_all()
server.wait_for_unit("docker")
'';
}

0 comments on commit 3b1025a

Please sign in to comment.