From 5167ce3c6a277bbe25cef3bb0dfb9f0233b0a022 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Sun, 13 Jul 2025 00:57:45 -0400 Subject: [PATCH] nixos/openafs: Merge user-supplied global CellServDB This exposes a new configuration option, `services.openafsClient.globalCellServDBFile`, which can be used to pass an existing CellServDB file (such as the one distributed by grand.central.org). Also, the global CellServDB is now filtered to remove any cells configured in `services.openafsClient.cellServDB`, so local configuration can override the global file. --- .../network-filesystems/openafs/client.nix | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/nixos/modules/services/network-filesystems/openafs/client.nix b/nixos/modules/services/network-filesystems/openafs/client.nix index c1bf6bf627b4..602019723603 100644 --- a/nixos/modules/services/network-filesystems/openafs/client.nix +++ b/nixos/modules/services/network-filesystems/openafs/client.nix @@ -21,17 +21,28 @@ let cfg = config.services.openafsClient; - cellServDB = pkgs.fetchurl { - url = "http://dl.central.org/dl/cellservdb/CellServDB.2018-05-14"; - sha256 = "1wmjn6mmyy2r8p10nlbdzs4nrqxy8a9pjyrdciy5nmppg4053rk2"; - }; - clientServDB = pkgs.writeText "client-cellServDB-${cfg.cellName}" (mkCellServDB cfg.cellServDB); + cellServDB = + let + localCells = builtins.attrNames cfg.cellServDB; + localCellsRegex = lib.concatMapStringsSep "\\|" (lib.replaceStrings [ "." ] [ "\\." ]) localCells; + sedExpr = '':x /^>\(${localCellsRegex}\) / { n; :y /^>/! { n; by }; bx }; p''; + globalCommand = + if cfg.cellServDB != { } then + ''sed -n -e ${lib.escapeShellArg sedExpr} ${cfg.globalCellServDBFile}'' + else + ''cat ${cfg.globalCellServDBFile}''; + in + pkgs.runCommand "CellServDB" { preferLocalBuild = true; } '' + ${lib.optionalString (cfg.globalCellServDBFile != null) ''${globalCommand} > $out''} + cat ${clientServDB} >> $out + ''; + afsConfig = pkgs.runCommand "afsconfig" { preferLocalBuild = true; } '' mkdir -p $out echo ${cfg.cellName} > $out/ThisCell - cat ${cellServDB} ${clientServDB} > $out/CellServDB + cp ${cellServDB} $out/CellServDB echo "${cfg.mountPoint}:${cfg.cache.directory}:${toString cfg.cache.blocks}" > $out/cacheinfo ''; @@ -62,6 +73,20 @@ in example = "grand.central.org"; }; + globalCellServDBFile = mkOption { + default = pkgs.fetchurl { + url = "http://dl.central.org/dl/cellservdb/CellServDB.2023-10-31"; + sha256 = "sha256-fuVHhTJI5FNwObBkAoTMZvZwVY4YEMTJX8fLpOVkQsU="; + }; + type = types.nullOr types.pathInStore; + description = '' + Global CellServDB file to be deployed. Set to `null` to only deploy the + cells in `cellServDB`. Any cells defined in `cellServDB` will override + cells in the global file. + ''; + example = lib.literalExpression "./CellServDB"; + }; + cellServDB = mkOption { default = { }; type = cellServDBType cfg.cellName; @@ -219,9 +244,7 @@ in environment.etc = { clientCellServDB = { - source = pkgs.runCommand "CellServDB" { preferLocalBuild = true; } '' - cat ${cellServDB} ${clientServDB} > $out - ''; + source = cellServDB; target = "openafs/CellServDB"; mode = "0644"; };