You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

74 lines
1.9 KiB

{ lib, pkgs, config, ... }:
with lib;
let
cfg = config.services.gensoc-mc-auth;
mcAuthSrc = ./.;
mcAuthServer = (import "${mcAuthSrc}/default.nix");
in {
options.services.gensoc-mc-auth = {
enable = mkEnableOption "GenSocAuth";
settings = {
name = mkOption {
type = types.str;
default = "GenSocAuth";
};
enableNginx = mkEnableOption "Enable nginx virtual host management";
url = mkOption {
type = types.str;
default = "mcauth.gensokyo.social";
};
server = {
hostname = mkOption {
type = types.str;
default = "0.0.0.0";
};
port = mkOption {
type = types.int;
default = 4010;
};
};
mastodon = {
returnUrl = mkOption {
type = types.str;
default = "https://mcauth.gensokyo.social/success";
};
};
database = {
host = mkOption {
type = types.str;
default = "localhost";
};
port = mkOption {
type = types.int;
default = 28015;
};
db = mkOption {
type = types.str;
default = "gensoc-auth";
};
};
};
};
config = let
configFile = pkgs.writeText "config.json" (builtins.toJSON cfg.settings);
in lib.mkIf cfg.enable {
services.nginx.virtualHosts = lib.mkIf cfg.settings.enableNginx {
"${cfg.settings.url}" = {
enableACME = true;
forceSSL = true;
locations."/" = {
proxyPass = "http://localhost:${toString cfg.settings.server.port}/";
extraConfig = ''
proxy_pass_request_headers on;
'';
};
};
};
systemd.services.gensoc-auth-server = {
wantedBy = [ "multi-user.target" ];
serviceConfig.ExecStart = "${mcAuthServer}/bin/server ${configFile}";
};
};
}