nixos/modules/services/nginx/applications/vaultwarden.nix

45 lines
1.6 KiB
Nix
Raw Normal View History

2023-10-03 20:11:43 +08:00
inputs:
{
options.nixos.services.nginx.applications.vaultwarden = let inherit (inputs.lib) mkOption types; in
{
enable = mkOption { type = types.bool; default = false; };
hostname = mkOption { type = types.nonEmptyStr; default = "vaultwarden.chn.moe"; };
upstream = mkOption
{
type = types.oneOf [ types.nonEmptyStr (types.submodule { options =
{
address = mkOption { type = types.nonEmptyStr; default = "127.0.0.1"; };
port = mkOption { type = types.ints.unsigned; default = 8000; };
websocketPort = mkOption { type = types.ints.unsigned; default = 3012; };
};})];
default = {};
};
};
config =
let
inherit (inputs.config.nixos.services.nginx.applications) vaultwarden;
inherit (builtins) listToAttrs;
inherit (inputs.lib) mkIf;
in mkIf vaultwarden.enable
{
nixos.services.nginx.http."${vaultwarden.hostname}" =
2023-10-03 20:11:43 +08:00
{
rewriteHttps = true;
locations = let upstream = vaultwarden.upstream; in (listToAttrs (map
(location: { name = location; value =
{
upstream = "http://${upstream.address or upstream}:${builtins.toString upstream.port or 8000}";
setHeaders = { Host = vaultwarden.hostname; Connection = ""; };
};})
[ "/" "/notifications/hub/negotiate" ]))
// { "/notifications/hub" =
{
upstream =
"http://${upstream.address or upstream}:${builtins.toString upstream.websocketPort or 3012}";
websocket = true;
setHeaders.Host = vaultwarden.hostname;
};};
};
};
}