2023-03-25 04:04:13 +00:00
|
|
|
{
|
|
|
|
options,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
format,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.aa.services.nix-serve;
|
|
|
|
in {
|
|
|
|
options.aa.services.nix-serve = with types; {
|
|
|
|
enable = mkEnableOption "nix-serve";
|
|
|
|
domain_name = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "The domain to use.";
|
|
|
|
};
|
|
|
|
subdomain_name = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "The subdomain to use.";
|
|
|
|
};
|
2023-07-16 17:53:02 +00:00
|
|
|
acmeCertName = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
If set to a non-empty string, forces SSL with the supplied acme
|
|
|
|
certificate.
|
|
|
|
'';
|
|
|
|
};
|
2023-03-25 04:04:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2023-06-15 03:30:26 +00:00
|
|
|
nix.settings = {
|
|
|
|
allowed-users = ["nix-serve"];
|
|
|
|
trusted-users = ["nix-serve"];
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [pkgs.nix-serve];
|
2023-04-16 17:07:42 +00:00
|
|
|
|
2023-03-25 04:04:13 +00:00
|
|
|
services = {
|
|
|
|
nix-serve = {
|
|
|
|
enable = true;
|
|
|
|
# TODO: Document this or automate the inital creation.
|
|
|
|
secretKeyFile = "/var/gospelCache";
|
|
|
|
};
|
|
|
|
|
|
|
|
nginx = {
|
|
|
|
enable = true;
|
2023-07-16 17:53:02 +00:00
|
|
|
virtualHosts."${cfg.subdomain_name}.${cfg.domain_name}" =
|
|
|
|
{
|
2023-03-25 16:19:01 +00:00
|
|
|
serverAliases = ["${cfg.subdomain_name}"];
|
2023-03-25 04:04:13 +00:00
|
|
|
locations."/".extraConfig = ''
|
|
|
|
proxy_pass http://localhost:${toString config.services.nix-serve.port};
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
'';
|
2023-07-16 17:53:02 +00:00
|
|
|
}
|
|
|
|
// lib.optionalAttrs (cfg.acmeCertName != "") {
|
|
|
|
forceSSL = true;
|
|
|
|
useACMEHost = cfg.acmeCertName;
|
2023-03-25 04:04:13 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall = {
|
2023-07-16 17:53:02 +00:00
|
|
|
allowedTCPPorts = [80 443];
|
2023-03-25 04:04:13 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|