2024-07-09 13:05:46 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
utils,
|
|
|
|
...
|
|
|
|
}:
|
2018-12-28 09:53:39 +01:00
|
|
|
let
|
|
|
|
cfg = config.services.nginx.sso;
|
2024-07-09 12:58:14 +00:00
|
|
|
format = pkgs.formats.yaml { };
|
2024-07-09 13:05:46 +00:00
|
|
|
configPath = "/var/lib/nginx-sso/config.yaml";
|
2018-12-28 09:53:39 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.nginx.sso = {
|
2024-12-29 21:50:37 +01:00
|
|
|
enable = lib.mkEnableOption "nginx-sso service";
|
2018-12-28 09:53:39 +01:00
|
|
|
|
2024-12-29 21:50:37 +01:00
|
|
|
package = lib.mkPackageOption pkgs "nginx-sso" { };
|
2020-01-12 14:35:23 +01:00
|
|
|
|
2024-12-29 21:50:37 +01:00
|
|
|
configuration = lib.mkOption {
|
2024-07-09 12:58:14 +00:00
|
|
|
type = format.type;
|
2018-12-28 09:53:39 +01:00
|
|
|
default = { };
|
2024-12-29 21:50:37 +01:00
|
|
|
example = lib.literalExpression ''
|
2018-12-28 09:53:39 +01:00
|
|
|
{
|
|
|
|
listen = { addr = "127.0.0.1"; port = 8080; };
|
|
|
|
|
|
|
|
providers.token.tokens = {
|
2024-07-09 13:05:46 +00:00
|
|
|
myuser = {
|
|
|
|
_secret = "/path/to/secret/token.txt"; # File content should be the secret token
|
|
|
|
};
|
2018-12-28 09:53:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
acl = {
|
|
|
|
rule_sets = [
|
|
|
|
{
|
|
|
|
rules = [ { field = "x-application"; equals = "MyApp"; } ];
|
|
|
|
allow = [ "myuser" ];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
nginx-sso configuration
|
|
|
|
([documentation](https://github.com/Luzifer/nginx-sso/wiki/Main-Configuration))
|
|
|
|
as a Nix attribute set.
|
2024-07-09 13:05:46 +00:00
|
|
|
|
|
|
|
Options containing secret data should be set to an attribute set
|
|
|
|
with the singleton attribute `_secret` - a string value set to the path
|
|
|
|
to the file containing the secret value which should be used in the
|
|
|
|
configuration. This file must be readable by `nginx-sso`.
|
2018-12-28 09:53:39 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-12-29 21:50:37 +01:00
|
|
|
config = lib.mkIf cfg.enable {
|
2018-12-28 09:53:39 +01:00
|
|
|
systemd.services.nginx-sso = {
|
|
|
|
description = "Nginx SSO Backend";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
2024-07-09 13:05:46 +00:00
|
|
|
StateDirectory = "nginx-sso";
|
|
|
|
WorkingDirectory = "/var/lib/nginx-sso";
|
|
|
|
ExecStartPre = pkgs.writeShellScript "merge-nginx-sso-config" ''
|
|
|
|
rm -f '${configPath}'
|
|
|
|
# Relies on YAML being a superset of JSON
|
|
|
|
${utils.genJqSecretsReplacementSnippet cfg.configuration configPath}
|
|
|
|
'';
|
2018-12-28 09:53:39 +01:00
|
|
|
ExecStart = ''
|
2024-07-09 12:59:06 +00:00
|
|
|
${lib.getExe cfg.package} \
|
2024-07-09 13:05:46 +00:00
|
|
|
--config ${configPath} \
|
2024-07-09 12:59:06 +00:00
|
|
|
--frontend-dir ${lib.getBin cfg.package}/share/frontend
|
2018-12-28 09:53:39 +01:00
|
|
|
'';
|
|
|
|
Restart = "always";
|
2024-07-09 13:05:46 +00:00
|
|
|
User = "nginx-sso";
|
|
|
|
Group = "nginx-sso";
|
2018-12-28 09:53:39 +01:00
|
|
|
};
|
|
|
|
};
|
2024-07-09 13:05:46 +00:00
|
|
|
|
|
|
|
users.users.nginx-sso = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "nginx-sso";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.nginx-sso = { };
|
2018-12-28 09:53:39 +01:00
|
|
|
};
|
|
|
|
}
|