financier-nix/module.nix

79 lines
1.6 KiB
Nix
Raw Permalink Normal View History

{ config, lib, ... }:
with lib;
let
cfg = config.services.financier;
in
{
2021-07-31 16:58:29 +02:00
imports = [ ];
options.services.financier = {
enable = mkEnableOption "Financier";
hostName = mkOption {
type = types.str;
description = ''
2021-02-20 03:21:26 +01:00
Name for the virtual host for the web server.
'';
example = "example.org";
};
2021-02-20 03:21:26 +01:00
openFirewall = mkOption {
description = ''
Whether to open ports 80 and 443 in the firewall for the web server that is serving financier.
'';
type = types.bool;
default = true;
};
package = mkOption {
type = types.package;
description = ''
Financier package to use.
'';
};
2021-02-20 03:21:26 +01:00
server = mkOption {
type = types.enum [
"nginx"
"caddy"
];
2021-02-20 03:21:26 +01:00
description = ''
The web server to be used for serving Financier. Either "nginx"
or "caddy".
'';
default = "caddy";
example = "example.org";
};
};
config = mkIf cfg.enable {
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [
80
443
];
2021-02-20 03:21:26 +01:00
services.nginx = mkIf (cfg.server == "nginx") {
enable = true;
virtualHosts."${cfg.hostName}" = {
forceSSL = true;
enableACME = true;
root = cfg.package;
2021-02-20 03:21:26 +01:00
locations."/".tryFiles = "$uri $uri/ /index.html";
};
};
services.caddy = mkIf (cfg.server == "caddy") {
enable = true;
2022-08-04 16:31:59 +02:00
extraConfig = ''
2021-02-20 03:21:26 +01:00
${cfg.hostName} {
root * ${cfg.package}
2021-02-20 03:21:26 +01:00
file_server
try_files {path} {path}/ /index.html
}
'';
};
};
}