sourcehut: initialize OAuth only for enabled services
authorJulien Moutinho <julm@sourcephile.fr>
Wed, 4 Aug 2021 15:33:13 +0000 (17:33 +0200)
committerJulien Moutinho <julm@sourcephile.fr>
Thu, 5 Aug 2021 13:42:33 +0000 (15:42 +0200)
nixos/modules/services/misc/sourcehut/meta.nix

index afcdf145edff46fe549a0b5dfc04d0d2c229c6a1..639820efc5e2c8e774b31a7552a928a988333e67 100644 (file)
@@ -79,18 +79,20 @@ in
         commonPreStart = ''
           # Configure client(s) as "preauthorized"
           ${concatMapStringsSep "\n\n"
-            (attr: ''
-              if ! test -e "${statePath}/${attr}.oauth" || [ "$(cat ${statePath}/${attr}.oauth)" != "${cfgIni."${attr}".oauth-client-id}" ]; then
-                # Configure ${attr}'s OAuth client as "preauthorized"
-                psql ${database} \
-                  -c "UPDATE oauthclient SET preauthorized = true WHERE client_id = '${cfgIni."${attr}".oauth-client-id}'"
+            (srv: ''
+              if ! test -e "${statePath}/${srv}.oauth" || [ "$(cat ${statePath}/${srv}.oauth)" != "${cfgIni.${srv}.oauth-client-id}" ]; then
+                # Configure ${srv}'s OAuth client as "preauthorized"
+                psql '${database}' \
+                  -c "UPDATE oauthclient SET preauthorized = true WHERE client_id = '${cfgIni.${srv}.oauth-client-id}'"
 
-                printf "%s" "${cfgIni."${attr}".oauth-client-id}" > "${statePath}/${attr}.oauth"
+                printf "%s" "${cfgIni.${srv}.oauth-client-id}" > "${statePath}/${srv}.oauth"
               fi
             '')
-            (builtins.attrNames (filterAttrs
-              (k: v: !(hasInfix "::" k) && (v.oauth-client-id or null) != null)
-              cfg.settings))}
+            (builtins.attrNames (filterAttrs (k: v:
+              let srv = builtins.match "^([a-z]*)\\.sr\\.ht$" k; in
+              srv != null && elem (head srv) cfg.services &&
+              ((v.oauth-client-id or null) != null)
+              ) cfg.settings))}
         '';
         in {
         metasrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {