TIDE/nix/tests/module.nix

106 lines
4.4 KiB
Nix

{
nixpkgs,
self,
system,
}:
let
pkgs = nixpkgs.legacyPackages.${system};
evaluatedSystem = nixpkgs.lib.nixosSystem {
inherit system;
modules = [
self.nixosModules.tide
{
services.tide = {
enable = true;
secretFiles = {
adminPassword = "/run/secrets/tide-admin-password";
mailPassword = "/run/secrets/tide-mail-password";
secretKeyBase = "/run/secrets/tide-secret-key-base";
borgPassphrase = "/run/secrets/borg-passphrase";
borgPrivateKey = "/run/secrets/borg-private-key";
};
};
}
];
};
evaluatedConfig = evaluatedSystem.config;
landingPage = self.packages.${system}.landing-page;
stylesheetHash = builtins.substring 0 12 (builtins.hashFile "sha256" ../../site/styles.css);
stylesheetFileName = "styles-${stylesheetHash}.css";
landingVirtualHost = evaluatedConfig.services.nginx.virtualHosts."torahimderecheretz.com";
discourseConfig = evaluatedConfig.services.discourse;
backupConfig = evaluatedConfig.services.borgbackup.jobs.discourse;
backupService = evaluatedConfig.systemd.services.borgbackup-job-discourse;
in
assert discourseConfig.enable;
assert discourseConfig.hostname == "discourse.torahimderecheretz.com";
assert discourseConfig.admin.email == "yisroel.d.baum@gmail.com";
assert discourseConfig.admin.fullName == "Yisroel Baum";
assert discourseConfig.admin.username == "yisroeldbaum";
assert discourseConfig.admin.passwordFile == "/run/secrets/tide-admin-password";
assert discourseConfig.mail.notificationEmailAddress == "system@torahimderecheretz.com";
assert discourseConfig.mail.contactEmailAddress == "system@torahimderecheretz.com";
assert discourseConfig.mail.outgoing.passwordFile == "/run/secrets/tide-mail-password";
assert discourseConfig.mail.outgoing.serverAddress == "in-v3.mailjet.com";
assert discourseConfig.mail.outgoing.port == 587;
assert discourseConfig.mail.outgoing.authentication == "login";
assert discourseConfig.siteSettings.required.title == "Torah Im Derech Eretz";
assert discourseConfig.secretKeyBaseFile == "/run/secrets/tide-secret-key-base";
assert evaluatedConfig.services.nginx.enable;
assert landingVirtualHost.root == landingPage;
assert landingVirtualHost.enableACME;
assert landingVirtualHost.forceSSL;
assert landingVirtualHost.locations."/".tryFiles == "$uri $uri/ =404";
assert backupConfig.repo == "ssh://oas17j8p@oas17j8p.repo.borgbase.com/./repo";
assert backupConfig.startAt == "*-*-* 07:15:00";
assert backupConfig.persistentTimer;
assert backupConfig.prune.keep.daily == 7;
assert backupConfig.prune.keep.weekly == 4;
assert backupConfig.prune.keep.monthly == 6;
assert builtins.elem "/var/lib/discourse" backupConfig.paths;
assert builtins.elem "sops-install-secrets.service" backupService.after;
assert !(evaluatedConfig.services.phpfpm.pools ? tide);
assert !(evaluatedConfig.services.nginx.virtualHosts ? "tide.yisroelbaum.com");
assert !(evaluatedConfig.services.nginx.virtualHosts ? "apitide.yisroelbaum.com");
pkgs.runCommand "tide-module-test" { } ''
test -f ${landingPage}/index.html
test -f ${landingPage}/${stylesheetFileName}
test ! -e ${landingPage}/styles.css
test -f ${landingPage}/robots.txt
test -f ${landingPage}/assets/rav-hirsch-1847.jpg
test -f ${landingPage}/assets/rav-hirsch-1847.webp
${pkgs.diffutils}/bin/cmp \
${../../site/styles.css} \
${landingPage}/${stylesheetFileName}
${pkgs.gnugrep}/bin/grep -F \
'href="/${stylesheetFileName}"' \
${landingPage}/index.html
if ${pkgs.gnugrep}/bin/grep -F \
'href="/styles.css"' \
${landingPage}/index.html; then
echo "unexpected unversioned stylesheet reference" >&2
exit 1
fi
${pkgs.gnugrep}/bin/grep -F \
"A Torah vision for the whole of life." \
${landingPage}/index.html
${pkgs.gnugrep}/bin/grep -F \
"https://discourse.torahimderecheretz.com" \
${landingPage}/index.html
${pkgs.gnugrep}/bin/grep -F \
"https://torah-im-derech-eretz.blogspot.com/" \
${landingPage}/index.html
${pkgs.gnugrep}/bin/grep -F \
"https://tide613.substack.com/" \
${landingPage}/index.html
${pkgs.gnugrep}/bin/grep -F \
"https://chat.whatsapp.com/FLdSwkdiChA9wvXxooUV9K" \
${landingPage}/index.html
if ${pkgs.gnugrep}/bin/grep -F \
'class="button button--small"' \
${landingPage}/index.html; then
echo "unexpected small button in landing-page header" >&2
exit 1
fi
touch "$out"
''