2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.nginx.sso;
|
2020-07-18 16:06:22 +00:00
|
|
|
pkg = getBin cfg.package;
|
2020-04-24 23:36:52 +00:00
|
|
|
configYml = pkgs.writeText "nginx-sso.yml" (builtins.toJSON cfg.configuration);
|
|
|
|
in {
|
|
|
|
options.services.nginx.sso = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "nginx-sso service";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "nginx-sso" { };
|
2020-07-18 16:06:22 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
configuration = mkOption {
|
|
|
|
type = types.attrsOf types.unspecified;
|
|
|
|
default = {};
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
listen = { addr = "127.0.0.1"; port = 8080; };
|
|
|
|
|
|
|
|
providers.token.tokens = {
|
|
|
|
myuser = "MyToken";
|
|
|
|
};
|
|
|
|
|
|
|
|
acl = {
|
|
|
|
rule_sets = [
|
|
|
|
{
|
|
|
|
rules = [ { field = "x-application"; equals = "MyApp"; } ];
|
|
|
|
allow = [ "myuser" ];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
nginx-sso configuration
|
2022-08-12 12:06:08 +00:00
|
|
|
([documentation](https://github.com/Luzifer/nginx-sso/wiki/Main-Configuration))
|
2020-04-24 23:36:52 +00:00
|
|
|
as a Nix attribute set.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.nginx-sso = {
|
|
|
|
description = "Nginx SSO Backend";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = ''
|
|
|
|
${pkg}/bin/nginx-sso \
|
|
|
|
--config ${configYml} \
|
|
|
|
--frontend-dir ${pkg}/share/frontend
|
|
|
|
'';
|
|
|
|
Restart = "always";
|
|
|
|
DynamicUser = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|