nixos/keycloak: add realmFiles option (#273833)

Changed files
+41 -1
nixos
doc
manual
release-notes
modules
services
web-apps
+2
nixos/doc/manual/release-notes/rl-2505.section.md
···
- `services.soft-serve` now restarts upon config change.
+
- `services.keycloak` now provides a `realmFiles` option that allows to import realms during startup. See https://www.keycloak.org/server/importExport
+
- `bind.cacheNetworks` now only controls access for recursive queries, where it previously controlled access for all queries.
- [`services.mongodb.enableAuth`](#opt-services.mongodb.enableAuth) now uses the newer [mongosh](https://github.com/mongodb-js/mongosh) shell instead of the legacy shell to configure the initial superuser. You can configure the mongosh package to use through the [`services.mongodb.mongoshPackage`](#opt-services.mongodb.mongoshPackage) option.
+39 -1
nixos/modules/services/web-apps/keycloak.nix
···
enum
package
port
+
listOf
;
assertStringPath =
···
different theme types: for example, `account`,
`login` etc. After adding a theme to this option you
can select it by its name in Keycloak administration console.
+
'';
+
};
+
+
realmFiles = mkOption {
+
type = listOf path;
+
example = lib.literalExpression ''
+
[
+
./some/realm.json
+
./another/realm.json
+
]
+
'';
+
default = [ ];
+
description = ''
+
Realm files that the server is going to import during startup.
+
If a realm already exists in the server, the import operation is
+
skipped. Importing the master realm is not supported. All files are
+
expected to be in `json` format. See the
+
[documentation](https://www.keycloak.org/server/importExport) for
+
further information.
'';
};
···
'';
};
+
systemd.tmpfiles.settings."10-keycloak" =
+
let
+
mkTarget =
+
file:
+
let
+
baseName = builtins.baseNameOf file;
+
name = if lib.hasSuffix ".json" baseName then baseName else "${baseName}.json";
+
in
+
"/run/keycloak/data/import/${name}";
+
settingsList = map (f: {
+
name = mkTarget f;
+
value = {
+
"L+".argument = "${f}";
+
};
+
}) cfg.realmFiles;
+
in
+
builtins.listToAttrs settingsList;
+
systemd.services.keycloak =
let
databaseServices =
···
cp $CREDENTIALS_DIRECTORY/ssl_{cert,key} /run/keycloak/ssl/
''
+ ''
-
kc.sh --verbose start --optimized
+
kc.sh --verbose start --optimized ${lib.optionalString (cfg.realmFiles != [ ]) "--import-realm"}
'';
};