2020-12-15 16:01:40 +01:00
|
|
|
{
|
|
|
|
description = "A complete and Simple Nixos Mailserver";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
utils.url = "github:numtide/flake-utils";
|
|
|
|
nixpkgs.url = "flake:nixpkgs/nixos-unstable";
|
2022-06-14 15:44:15 +02:00
|
|
|
nixpkgs-22_05.url = "flake:nixpkgs/nixos-22.05";
|
2021-07-10 16:05:25 +02:00
|
|
|
blobs = {
|
|
|
|
url = "gitlab:simple-nixos-mailserver/blobs";
|
|
|
|
flake = false;
|
|
|
|
};
|
2020-12-15 16:01:40 +01:00
|
|
|
};
|
|
|
|
|
2022-06-14 15:44:15 +02:00
|
|
|
outputs = { self, utils, blobs, nixpkgs, nixpkgs-22_05 }: let
|
2021-07-10 16:05:25 +02:00
|
|
|
system = "x86_64-linux";
|
2020-12-15 16:01:40 +01:00
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
2021-07-10 16:05:25 +02:00
|
|
|
releases = [
|
|
|
|
{
|
|
|
|
name = "unstable";
|
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
}
|
2022-06-14 15:44:15 +02:00
|
|
|
{
|
|
|
|
name = "22.05";
|
|
|
|
pkgs = nixpkgs-22_05.legacyPackages.${system};
|
|
|
|
}
|
2021-07-10 16:05:25 +02:00
|
|
|
];
|
|
|
|
testNames = [
|
|
|
|
"internal"
|
|
|
|
"external"
|
|
|
|
"clamav"
|
|
|
|
"multiple"
|
|
|
|
];
|
|
|
|
genTest = testName: release: {
|
|
|
|
"name"= "${testName}-${release.name}";
|
|
|
|
"value"= import (./tests/. + "/${testName}.nix") {
|
|
|
|
pkgs = release.pkgs;
|
|
|
|
inherit blobs;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
# Generate an attribute set such as
|
|
|
|
# {
|
|
|
|
# external-unstable = <derivation>;
|
|
|
|
# external-21_05 = <derivation>;
|
|
|
|
# ...
|
|
|
|
# }
|
|
|
|
allTests = pkgs.lib.listToAttrs (
|
|
|
|
pkgs.lib.flatten (map (t: map (r: genTest t r) releases) testNames));
|
|
|
|
|
2021-07-14 10:06:58 +02:00
|
|
|
mailserverModule = import ./.;
|
|
|
|
|
2022-01-21 13:02:15 +01:00
|
|
|
# Generate a rst file describing options of the NixOS mailserver module
|
2021-07-14 10:06:58 +02:00
|
|
|
generateRstOptions = let
|
|
|
|
eval = import (pkgs.path + "/nixos/lib/eval-config.nix") {
|
|
|
|
inherit system;
|
|
|
|
modules = [
|
|
|
|
mailserverModule
|
|
|
|
{
|
2021-07-23 21:25:14 +02:00
|
|
|
# Because the blockbook package is currently broken (we
|
|
|
|
# don't care about this package but it is part of the
|
|
|
|
# NixOS module evaluation)
|
|
|
|
nixpkgs.config.allowBroken = true;
|
2021-10-03 14:31:43 +02:00
|
|
|
mailserver = {
|
|
|
|
fqdn = "mx.example.com";
|
|
|
|
domains = [
|
|
|
|
"example.com"
|
|
|
|
];
|
|
|
|
dmarcReporting = {
|
|
|
|
organizationName = "Example Corp";
|
|
|
|
domain = "example.com";
|
|
|
|
};
|
|
|
|
};
|
2021-07-14 10:06:58 +02:00
|
|
|
}
|
|
|
|
];
|
2022-01-21 13:02:15 +01:00
|
|
|
|
2021-07-14 10:06:58 +02:00
|
|
|
};
|
|
|
|
options = pkgs.nixosOptionsDoc {
|
|
|
|
options = eval.options;
|
|
|
|
};
|
|
|
|
in pkgs.runCommand "options.rst" { buildInputs = [pkgs.python3]; } ''
|
|
|
|
echo Generating options.rst from ${options.optionsJSON}/share/doc/nixos/options.json
|
|
|
|
python ${./scripts/generate-rst-options.py} ${options.optionsJSON}/share/doc/nixos/options.json > $out
|
|
|
|
'';
|
|
|
|
|
|
|
|
# This is a script helping users to generate this file in the docs directory
|
|
|
|
generateRstOptionsScript = pkgs.writeScriptBin "generate-rst-options" ''
|
|
|
|
cp -v ${generateRstOptions} ./docs/options.rst
|
|
|
|
'';
|
|
|
|
|
|
|
|
# This is to ensure we don't forget to update the options.rst file
|
|
|
|
testRstOptions = pkgs.runCommand "test-rst-options" {} ''
|
|
|
|
if ! diff -q ${./docs/options.rst} ${generateRstOptions}
|
|
|
|
then
|
|
|
|
echo "The file ./docs/options.rst is not up-to-date and needs to be regenerated!"
|
|
|
|
echo " hint: run 'nix-shell --run generate-rst-options' to generate this file"
|
2021-10-14 09:07:32 +02:00
|
|
|
exit 1
|
2021-07-14 10:06:58 +02:00
|
|
|
fi
|
|
|
|
echo "test: ok" > $out
|
|
|
|
'';
|
|
|
|
|
2021-07-23 21:25:14 +02:00
|
|
|
documentation = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "documentation";
|
|
|
|
src = pkgs.lib.sourceByRegex ./docs ["logo.png" "conf.py" "Makefile" ".*rst$"];
|
|
|
|
buildInputs = [(
|
|
|
|
pkgs.python3.withPackages(p: [
|
|
|
|
p.sphinx
|
|
|
|
p.sphinx_rtd_theme
|
|
|
|
])
|
|
|
|
)];
|
|
|
|
buildPhase = ''
|
|
|
|
cp ${generateRstOptions} options.rst
|
|
|
|
mkdir -p _static
|
|
|
|
# Workaround for https://github.com/sphinx-doc/sphinx/issues/3451
|
|
|
|
export SOURCE_DATE_EPOCH=$(${pkgs.coreutils}/bin/date +%s)
|
|
|
|
make html
|
|
|
|
'';
|
|
|
|
installPhase = ''
|
|
|
|
cp -r _build/html $out
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-07-14 10:06:58 +02:00
|
|
|
in rec {
|
|
|
|
nixosModules.mailserver = mailserverModule ;
|
2021-07-10 16:05:25 +02:00
|
|
|
nixosModule = self.nixosModules.mailserver;
|
2021-07-14 10:06:58 +02:00
|
|
|
hydraJobs.${system} = allTests // {
|
|
|
|
test-rst-options = testRstOptions;
|
2021-07-23 21:25:14 +02:00
|
|
|
inherit documentation;
|
2021-07-14 10:06:58 +02:00
|
|
|
};
|
2021-07-10 16:05:25 +02:00
|
|
|
checks.${system} = allTests;
|
|
|
|
devShell.${system} = pkgs.mkShell {
|
2020-12-15 16:01:40 +01:00
|
|
|
buildInputs = with pkgs; [
|
2021-07-14 10:06:58 +02:00
|
|
|
generateRstOptionsScript
|
2020-12-15 16:01:40 +01:00
|
|
|
(python3.withPackages (p: with p; [
|
|
|
|
sphinx
|
|
|
|
sphinx_rtd_theme
|
|
|
|
]))
|
|
|
|
jq
|
|
|
|
clamav
|
|
|
|
];
|
|
|
|
};
|
2021-07-10 16:05:25 +02:00
|
|
|
};
|
2020-12-15 16:01:40 +01:00
|
|
|
}
|