Files
nixos/modules/services/bin.nix
2025-02-10 10:53:28 +02:00

66 lines
1.4 KiB
Nix

{ lib, config, inputs, ... }:
let
cfg = config.modules.services.bin;
fqdn = "${cfg.subdomain}.${config.networking.domain}";
KiB = 1024;
MiB = 1024 * KiB;
GiB = 1024 * MiB;
in
{
imports = [
inputs.hastebin.nixosModules.default
];
options.modules.services.bin = {
enable = lib.mkEnableOption "Enable Rustypaste";
subdomain = lib.mkOption {
type = lib.types.str;
};
port = lib.mkOption {
type = lib.types.int;
default = 3600;
};
};
config = lib.mkIf cfg.enable {
services.hastebin = {
enable = true;
settings = {
port = cfg.port;
host = "::1";
max_size = 1 * GiB;
mime_overrides = {
"text/plain" = [
"log"
"txt"
"diff"
"sh"
"rs"
"toml"
"cr"
"nix"
"rb"
"ts"
"tsx"
"jsx"
];
};
auth_tokens_file = "/var/secrets/hastebin-tokens";
};
};
modules.services.webserver = {
enable = lib.mkDefault true;
vHosts.${fqdn}.locations."/" = {
proxyPort = cfg.port;
extraConfig = ''
client_max_body_size ${toString (config.services.hastebin.settings.max_size / MiB)}m;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
'';
};
};
};
}