{ self, lib, ... }:
let
html =
with lib.fileset;
toSource {
root = ./html;
fileset = ./html;
};
in
{
flake.machines.tharos = {
nixos =
{ lib, ... }:
{
services.caddy.virtualHosts.${self.domain} = {
serverAliases = [ "www.${self.domain}" ];
extraConfig = ''
file_server
root * /var/www/${self.domain}
encode gzip
'';
};
systemd.tmpfiles.rules = [
# Verzeichnis für Web-Inhalte sofort anlegen, da der Webserver sonst nicht startet,
# aber nur wenn es noch nicht existiert.
"C /var/www/${self.domain} - - - - ${html}"
];
};
vm =
{
config,
pkgs,
lib,
...
}:
{
services.caddy.virtualHosts = {
"http://www.localhost:${toString config.virtualisation.exposedPorts.http.port}".extraConfig =
config.services.caddy.virtualHosts.${self.domain}.extraConfig;
};
services.getty.helpLine = lib.mkBefore ''
${self.domain}: http://www.localhost:${
with config.virtualisation; toString (portOffset + exposedPorts.http.port)
}
'';
};
};
perSystem =
{
pkgs,
lib,
system,
self',
...
}:
{
# Website-Inhalte auf den Server hochladen
packages.publish = pkgs.writeShellApplication {
name = "publish";
runtimeInputs = with pkgs; [ rsync ];
text = ''
rsync -avi --rsync-path "sudo rsync" --chown caddy:caddy --delete ${self'.packages.html}/ ${self.machines.tharos.deploy-target}:/var/www/${self.domain}/
'';
};
# Lokale Vorschau
packages.html = pkgs.runCommand "source" { } ''
cp -r ${html} $out
'';
packages.preview = pkgs.devmode.override {
buildArgs = ''
"$(${lib.getExe pkgs.git} rev-parse --show-toplevel)" -A packages.${system}.html -vv
'';
};
};
}