|
82 | 82 | path
|
83 | 83 | enum
|
84 | 84 | package
|
85 |
| - port; |
| 85 | + port |
| 86 | + listOf; |
86 | 87 |
|
87 | 88 | assertStringPath = optionName: value:
|
88 | 89 | if isPath value then
|
|
272 | 273 | '';
|
273 | 274 | };
|
274 | 275 |
|
| 276 | + realmFiles = mkOption { |
| 277 | + type = listOf path; |
| 278 | + example = lib.literalExpression '' |
| 279 | + [ |
| 280 | + ./some/realm.json |
| 281 | + ./another/realm.json |
| 282 | + ] |
| 283 | + ''; |
| 284 | + default = []; |
| 285 | + description = '' |
| 286 | + Set of realm files that the server is going to try to import |
| 287 | + during startup. If a realm already exists in the server, the import |
| 288 | + operation is skipped. Importing the master realm is not supported. |
| 289 | + All files are expected to be in `json` format. See the |
| 290 | + [documentation](https://www.keycloak.org/server/importExport) for |
| 291 | + further information. |
| 292 | + ''; |
| 293 | + }; |
| 294 | + |
275 | 295 | settings = mkOption {
|
276 | 296 | type = lib.types.submodule {
|
277 | 297 | freeformType = attrsOf (nullOr (oneOf [ str int bool (attrsOf path) ]));
|
|
620 | 640 | replace-secret ${hashString "sha256" file} $CREDENTIALS_DIRECTORY/${baseNameOf file} /run/keycloak/conf/keycloak.conf
|
621 | 641 | '';
|
622 | 642 | secretReplacements = lib.concatMapStrings mkSecretReplacement secretPaths;
|
| 643 | + installRealmFile = file: |
| 644 | + let |
| 645 | + baseName = builtins.baseNameOf file; |
| 646 | + target = if lib.hasSuffix ".json" baseName then baseName else "${baseName}.json"; |
| 647 | + in |
| 648 | + "install -D -m 0600 ${file} /run/keycloak/data/import/${target}"; |
623 | 649 | in
|
624 | 650 | {
|
625 | 651 | after = databaseServices;
|
|
671 | 697 | '' + optionalString (cfg.sslCertificate != null && cfg.sslCertificateKey != null) ''
|
672 | 698 | mkdir -p /run/keycloak/ssl
|
673 | 699 | cp $CREDENTIALS_DIRECTORY/ssl_{cert,key} /run/keycloak/ssl/
|
| 700 | + '' + '' |
| 701 | + ${concatStringsSep "\n" (map installRealmFile cfg.realmFiles)} |
674 | 702 | '' + ''
|
675 | 703 | export KEYCLOAK_ADMIN=admin
|
676 | 704 | export KEYCLOAK_ADMIN_PASSWORD=${escapeShellArg cfg.initialAdminPassword}
|
677 |
| - kc.sh --verbose start --optimized |
| 705 | + kc.sh --verbose start --optimized ${lib.optionalString (cfg.realmFiles != []) "--import-realm"} |
678 | 706 | '';
|
679 | 707 | };
|
680 | 708 |
|
|
0 commit comments