summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorpennae <82953136+pennae@users.noreply.github.com>2022-04-18 16:55:45 +0000
committerGitHub <noreply@github.com>2022-04-18 16:55:45 +0000
commit529ce4161a07f0b5a4a6d6cc4339d50f7cec77b5 (patch)
tree3238b3d30d2aa96dc541fcbd2f05d98ab6ffc628 /nixos/modules
parenta719f5fb9d19c639860176981b9c9ec1ae457c25 (diff)
parent46464911756ced488d10404769e2bb45434765ac (diff)
downloadnixpkgs-529ce4161a07f0b5a4a6d6cc4339d50f7cec77b5.tar
nixpkgs-529ce4161a07f0b5a4a6d6cc4339d50f7cec77b5.tar.gz
nixpkgs-529ce4161a07f0b5a4a6d6cc4339d50f7cec77b5.tar.bz2
nixpkgs-529ce4161a07f0b5a4a6d6cc4339d50f7cec77b5.tar.lz
nixpkgs-529ce4161a07f0b5a4a6d6cc4339d50f7cec77b5.tar.xz
nixpkgs-529ce4161a07f0b5a4a6d6cc4339d50f7cec77b5.tar.zst
nixpkgs-529ce4161a07f0b5a4a6d6cc4339d50f7cec77b5.zip
Merge pull request #169176 from scvalex/fix-nbd-section-ordering
nixos/nbd: fix nbd-server config section ordering
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/services/networking/nbd.nix43
1 files changed, 28 insertions, 15 deletions
diff --git a/nixos/modules/services/networking/nbd.nix b/nixos/modules/services/networking/nbd.nix
index 87f8c41a8e5..df3358f5187 100644
--- a/nixos/modules/services/networking/nbd.nix
+++ b/nixos/modules/services/networking/nbd.nix
@@ -4,28 +4,34 @@ with lib;
 
 let
   cfg = config.services.nbd;
-  configFormat = pkgs.formats.ini { };
   iniFields = with types; attrsOf (oneOf [ bool int float str ]);
-  serverConfig = configFormat.generate "nbd-server-config"
-    ({
-      generic =
-        (cfg.server.extraOptions // {
-          user = "root";
-          group = "root";
-          port = cfg.server.listenPort;
-        } // (optionalAttrs (cfg.server.listenAddress != null) {
-          listenaddr = cfg.server.listenAddress;
-        }));
-    }
-    // (mapAttrs
+  # The `[generic]` section must come before all the others in the
+  # config file.  This means we can't just dump an attrset to INI
+  # because that sorts the sections by name.  Instead, we serialize it
+  # on its own first.
+  genericSection = {
+    generic = (cfg.server.extraOptions // {
+      user = "root";
+      group = "root";
+      port = cfg.server.listenPort;
+    } // (optionalAttrs (cfg.server.listenAddress != null) {
+      listenaddr = cfg.server.listenAddress;
+    }));
+  };
+  exportSections =
+    mapAttrs
       (_: { path, allowAddresses, extraOptions }:
         extraOptions // {
           exportname = path;
         } // (optionalAttrs (allowAddresses != null) {
           authfile = pkgs.writeText "authfile" (concatStringsSep "\n" allowAddresses);
         }))
-      cfg.server.exports)
-    );
+      cfg.server.exports;
+  serverConfig =
+    pkgs.writeText "nbd-server-config" ''
+      ${lib.generators.toINI {} genericSection}
+      ${lib.generators.toINI {} exportSections}
+    '';
   splitLists =
     partition
       (path: hasPrefix "/dev/" path)
@@ -103,6 +109,13 @@ in
   };
 
   config = mkIf cfg.server.enable {
+    assertions = [
+      {
+        assertion = !(cfg.server.exports ? "generic");
+        message = "services.nbd.server exports must not be named 'generic'";
+      }
+    ];
+
     boot.kernelModules = [ "nbd" ];
 
     systemd.services.nbd-server = {