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 = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "nginx-sso service");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-07-18 16:06:22 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.nginx-sso;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.nginx-sso";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-07-18 16:06:22 +00:00
|
|
|
The nginx-sso package that should be used.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
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" ];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|