diff options
author | stuebinm <stuebinm@disroot.org> | 2022-04-24 17:16:13 +0200 |
---|---|---|
committer | stuebinm <stuebinm@disroot.org> | 2022-04-24 18:03:58 +0200 |
commit | 095c27c9d5e6b5d4d8f7a067ee413ca0ca47c56b (patch) | |
tree | 3d11a2cafe15dcdfabddf58b5082f397462c0f51 /nixos | |
parent | b5af07194680c15246b5859a6313c028fc8cdd68 (diff) | |
download | nixpkgs-095c27c9d5e6b5d4d8f7a067ee413ca0ca47c56b.tar nixpkgs-095c27c9d5e6b5d4d8f7a067ee413ca0ca47c56b.tar.gz nixpkgs-095c27c9d5e6b5d4d8f7a067ee413ca0ca47c56b.tar.bz2 nixpkgs-095c27c9d5e6b5d4d8f7a067ee413ca0ca47c56b.tar.lz nixpkgs-095c27c9d5e6b5d4d8f7a067ee413ca0ca47c56b.tar.xz nixpkgs-095c27c9d5e6b5d4d8f7a067ee413ca0ca47c56b.tar.zst nixpkgs-095c27c9d5e6b5d4d8f7a067ee413ca0ca47c56b.zip |
services/nixos: decode secret file correctly
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/services/web-apps/nextcloud.nix | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/nixos/modules/services/web-apps/nextcloud.nix b/nixos/modules/services/web-apps/nextcloud.nix index 78fa7e5b9f6..81864608492 100644 --- a/nixos/modules/services/web-apps/nextcloud.nix +++ b/nixos/modules/services/web-apps/nextcloud.nix @@ -477,8 +477,19 @@ in { throw new \RuntimeException(sprintf($error, $file)); } return trim(file_get_contents($file)); + }''} + function nix_decode_json_file($file, $error) { + if (!file_exists($file)) { + throw new \RuntimeException(sprintf($error, $file)); } - ''} + $decoded = json_decode(file_get_contents($file), true); + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new \RuntimeException(sprintf("Cannot decode %s, because: %s", $file, json_last_error_msg())); + } + + return $decoded; + } $CONFIG = [ 'apps_paths' => [ [ 'path' => '${cfg.home}/apps', 'url' => '/apps', 'writable' => false ], @@ -511,18 +522,17 @@ in { ${optionalString (c.defaultPhoneRegion != null) "'default_phone_region' => '${c.defaultPhoneRegion}',"} ]; - $EXTRACONFIG = json_decode(file_get_contents("${jsonFormat.generate "nextcloud-extraOptions.json" cfg.extraOptions}"), true); - - if (json_last_error() !== JSON_ERROR_NONE) { - throw new \RuntimeException(sprintf("Cannot decode %s, because: %s", $filename, json_last_error_msg())); - } + $EXTRACONFIG = nix_decode_json_file( + "${jsonFormat.generate "nextcloud-extraOptions.json" cfg.extraOptions}", + "decoding json extra options file failed" + ); $CONFIG = array_replace_recursive($CONFIG, $EXTRACONFIG); ${optionalString (cfg.secretFile != null) '' - $CONFIG = array_merge($CONFIG, nix_read_file( - ${cfg.secretFile}), + $CONFIG = array_replace_recursive($CONFIG, nix_decode_json_file( + "${cfg.secretFile}", "Cannot start Nextcloud, secrets file %s set by NixOS doesn't exist!" - ); + )); ''} ''; occInstallCmd = let |