nixpkgs/nixos/modules/services/security/nginx-sso.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

87 lines
2.3 KiB
Nix
Raw Normal View History

{
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 { };
configPath = "/var/lib/nginx-sso/config.yaml";
2018-12-28 09:53:39 +01:00
in
{
options.services.nginx.sso = {
enable = lib.mkEnableOption "nginx-sso service";
2018-12-28 09:53:39 +01:00
package = lib.mkPackageOption pkgs "nginx-sso" { };
2020-01-12 14:35:23 +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 = { };
example = lib.literalExpression ''
2018-12-28 09:53:39 +01:00
{
listen = { addr = "127.0.0.1"; port = 8080; };
providers.token.tokens = {
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.
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
'';
};
};
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 = {
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} \
--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";
User = "nginx-sso";
Group = "nginx-sso";
2018-12-28 09:53:39 +01:00
};
};
users.users.nginx-sso = {
isSystemUser = true;
group = "nginx-sso";
};
users.groups.nginx-sso = { };
2018-12-28 09:53:39 +01:00
};
}