|
1 | | -{ config, lib, pkgs, ... }: |
| 1 | +{ config, lib, pkgs, utils, ... }: |
2 | 2 |
|
3 | 3 | with lib; |
4 | 4 |
|
5 | 5 | let |
6 | 6 | cfg = config.services.nginx.sso; |
7 | | - pkg = getBin cfg.package; |
8 | | - configYml = pkgs.writeText "nginx-sso.yml" (builtins.toJSON cfg.configuration); |
| 7 | + format = pkgs.formats.yaml { }; |
| 8 | + configPath = "/var/lib/nginx-sso/config.yaml"; |
9 | 9 | in { |
10 | 10 | options.services.nginx.sso = { |
11 | 11 | enable = mkEnableOption "nginx-sso service"; |
12 | 12 |
|
13 | 13 | package = mkPackageOption pkgs "nginx-sso" { }; |
14 | 14 |
|
15 | 15 | configuration = mkOption { |
16 | | - type = types.attrsOf types.unspecified; |
| 16 | + type = format.type; |
17 | 17 | default = {}; |
18 | 18 | example = literalExpression '' |
19 | 19 | { |
20 | 20 | listen = { addr = "127.0.0.1"; port = 8080; }; |
21 | 21 |
|
22 | 22 | providers.token.tokens = { |
23 | | - myuser = "MyToken"; |
| 23 | + myuser = { |
| 24 | + _secret = "/path/to/secret/token.txt"; # File content should be the secret token |
| 25 | + }; |
24 | 26 | }; |
25 | 27 |
|
26 | 28 | acl = { |
|
37 | 39 | nginx-sso configuration |
38 | 40 | ([documentation](https://github.com/Luzifer/nginx-sso/wiki/Main-Configuration)) |
39 | 41 | as a Nix attribute set. |
| 42 | +
|
| 43 | + Options containing secret data should be set to an attribute set |
| 44 | + with the singleton attribute `_secret` - a string value set to the path |
| 45 | + to the file containing the secret value which should be used in the |
| 46 | + configuration. This file must be readable by `nginx-sso`. |
40 | 47 | ''; |
41 | 48 | }; |
42 | 49 | }; |
|
47 | 54 | after = [ "network.target" ]; |
48 | 55 | wantedBy = [ "multi-user.target" ]; |
49 | 56 | serviceConfig = { |
| 57 | + StateDirectory = "nginx-sso"; |
| 58 | + WorkingDirectory = "/var/lib/nginx-sso"; |
| 59 | + ExecStartPre = pkgs.writeShellScript "merge-nginx-sso-config" '' |
| 60 | + rm -f '${configPath}' |
| 61 | + # Relies on YAML being a superset of JSON |
| 62 | + ${utils.genJqSecretsReplacementSnippet cfg.configuration configPath} |
| 63 | + ''; |
50 | 64 | ExecStart = '' |
51 | | - ${pkg}/bin/nginx-sso \ |
52 | | - --config ${configYml} \ |
53 | | - --frontend-dir ${pkg}/share/frontend |
| 65 | + ${lib.getExe cfg.package} \ |
| 66 | + --config ${configPath} \ |
| 67 | + --frontend-dir ${lib.getBin cfg.package}/share/frontend |
54 | 68 | ''; |
55 | 69 | Restart = "always"; |
56 | | - DynamicUser = true; |
| 70 | + User = "nginx-sso"; |
| 71 | + Group = "nginx-sso"; |
57 | 72 | }; |
58 | 73 | }; |
| 74 | + |
| 75 | + users.users.nginx-sso = { |
| 76 | + isSystemUser = true; |
| 77 | + group = "nginx-sso"; |
| 78 | + }; |
| 79 | + |
| 80 | + users.groups.nginx-sso = { }; |
59 | 81 | }; |
60 | 82 | } |
0 commit comments