summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorSandro Jäckel <sandro.jaeckel@gmail.com>2022-06-03 03:07:11 +0200
committerSandro Jäckel <sandro.jaeckel@sap.com>2022-06-03 11:41:36 +0200
commit48b21f661c6dc1f388b640b4fcef4d52de8cdd44 (patch)
treeb7feee6545d5fce0084c733e94f44f044db922f9 /nixos
parentb450c76786ade693ca3e6b59e7a0f7a66443abb9 (diff)
downloadnixpkgs-48b21f661c6dc1f388b640b4fcef4d52de8cdd44.tar
nixpkgs-48b21f661c6dc1f388b640b4fcef4d52de8cdd44.tar.gz
nixpkgs-48b21f661c6dc1f388b640b4fcef4d52de8cdd44.tar.bz2
nixpkgs-48b21f661c6dc1f388b640b4fcef4d52de8cdd44.tar.lz
nixpkgs-48b21f661c6dc1f388b640b4fcef4d52de8cdd44.tar.xz
nixpkgs-48b21f661c6dc1f388b640b4fcef4d52de8cdd44.tar.zst
nixpkgs-48b21f661c6dc1f388b640b4fcef4d52de8cdd44.zip
nixos/asf: add ipcPasswordFile option, only delete bot configs when managed by nixos, make preStart clearer
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/games/asf.nix42
1 files changed, 28 insertions, 14 deletions
diff --git a/nixos/modules/services/games/asf.nix b/nixos/modules/services/games/asf.nix
index ea2bfd40fff..32294d23e90 100644
--- a/nixos/modules/services/games/asf.nix
+++ b/nixos/modules/services/games/asf.nix
@@ -13,6 +13,8 @@ let
     # is in theory not needed as this is already the default for default builds
     UpdateChannel = 0;
     Headless = true;
+  } // lib.optionalAttrs (cfg.ipcPasswordFile != "") {
+    IPCPassword = "#ipcPassword#";
   });
 
   ipc-config = format.generate "IPC.config" cfg.ipcSettings;
@@ -92,6 +94,11 @@ respectively `0` because NixOS takes care of updating everything.
       default = { };
     };
 
+    ipcPasswordFile = mkOption {
+      type = types.path;
+      description = "Path to a file containig the password. The file must be readable by the <literal>asf</literal> user/group.";
+    };
+
     ipcSettings = mkOption {
       type = format.type;
       description = ''
@@ -202,26 +209,33 @@ respectively `0` because NixOS takes care of updating everything.
           }
         ];
 
-        preStart = ''
+        preStart = let
+          createBotsScript = pkgs.runCommandLocal "ASF-bots" {} ''
+            mkdir -p $out/lib/asf/bots
+            # clean potential removed bots
+            rm -rf $out/lib/asf/bots/*.json
+            for i in ${strings.concatStringsSep " " (lists.map (x: "${getName x},${x}") (attrsets.mapAttrsToList mkBot cfg.bots))}; do IFS=",";
+              set -- $i
+              ln -fs $2 $out/lib/asf/bots/$1
+            done
+          '';
+          replaceSecretBin = "${pkgs.replace-secret}/bin/replace-secret";
+        in ''
           mkdir -p config
-          rm -f www
-          rm -f config/{*.json,*.config}
 
-          ln -s ${asf-config} config/ASF.json
+          cp --no-preserve=mode ${asf-config} config/ASF.json
+          ${replaceSecretBin} '#ipcPassword#' '${cfg.ipcPasswordFile}' config/ASF.json
 
-          ${strings.optionalString (cfg.ipcSettings != {}) ''
-            ln -s ${ipc-config} config/IPC.config
+          ${optionalString (cfg.ipcSettings != {}) ''
+            ln -fs ${ipc-config} config/IPC.config
           ''}
 
-          ln -s ${pkgs.runCommandLocal "ASF-bots" {} ''
-            mkdir -p $out/lib/asf/bots
-            for i in ${strings.concatStringsSep " " (lists.map (x: "${getName x},${x}") (attrsets.mapAttrsToList mkBot cfg.bots))}; do IFS=",";
-              set -- $i
-              ln -s $2 $out/lib/asf/bots/$1
-            done
-          ''}/lib/asf/bots/* config/
+          ${optionalString (cfg.ipcSettings != {}) ''
+            ln -fs ${createBotsScript}/lib/asf/bots/* config/
+          ''}
 
-          ${strings.optionalString cfg.web-ui.enable ''
+          rm -f www
+          ${optionalString cfg.web-ui.enable ''
             ln -s ${cfg.web-ui.package}/lib/dist www
           ''}
         '';