summary refs log tree commit diff
path: root/nixos/modules/services/cluster
diff options
context:
space:
mode:
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2021-07-19 18:01:44 +0000
committerGitHub <noreply@github.com>2021-07-19 18:01:44 +0000
commitc455b1a6573b382552403a7fec2ed7d90a4277a3 (patch)
treecbeea06a9ba98b142336247979e50e88569c9a72 /nixos/modules/services/cluster
parent914b93541e67b535c6c6e5588d5ce33b485bfedf (diff)
parentc0cb54f9eeb0c607a08097f84096728aa8ea615d (diff)
downloadnixpkgs-c455b1a6573b382552403a7fec2ed7d90a4277a3.tar
nixpkgs-c455b1a6573b382552403a7fec2ed7d90a4277a3.tar.gz
nixpkgs-c455b1a6573b382552403a7fec2ed7d90a4277a3.tar.bz2
nixpkgs-c455b1a6573b382552403a7fec2ed7d90a4277a3.tar.lz
nixpkgs-c455b1a6573b382552403a7fec2ed7d90a4277a3.tar.xz
nixpkgs-c455b1a6573b382552403a7fec2ed7d90a4277a3.tar.zst
nixpkgs-c455b1a6573b382552403a7fec2ed7d90a4277a3.zip
Merge staging-next into staging
Diffstat (limited to 'nixos/modules/services/cluster')
-rw-r--r--nixos/modules/services/cluster/k3s/default.nix24
1 files changed, 14 insertions, 10 deletions
diff --git a/nixos/modules/services/cluster/k3s/default.nix b/nixos/modules/services/cluster/k3s/default.nix
index d0fb8cc5098..e5c51441690 100644
--- a/nixos/modules/services/cluster/k3s/default.nix
+++ b/nixos/modules/services/cluster/k3s/default.nix
@@ -67,6 +67,12 @@ in
       default = false;
       description = "Only run the server. This option only makes sense for a server.";
     };
+
+    configPath = mkOption {
+      type = types.nullOr types.path;
+      default = null;
+      description = "File path containing the k3s YAML config. This is useful when the config is generated (for example on boot).";
+    };
   };
 
   # implementation
@@ -74,12 +80,12 @@ in
   config = mkIf cfg.enable {
     assertions = [
       {
-        assertion = cfg.role == "agent" -> cfg.serverAddr != "";
-        message = "serverAddr should be set if role is 'agent'";
+        assertion = cfg.role == "agent" -> (cfg.configPath != null || cfg.serverAddr != "");
+        message = "serverAddr or configPath (with 'server' key) should be set if role is 'agent'";
       }
       {
-        assertion = cfg.role == "agent" -> cfg.token != "" || cfg.tokenFile != null;
-        message = "token or tokenFile should be set if role is 'agent'";
+        assertion = cfg.role == "agent" -> cfg.configPath != null || cfg.tokenFile != null || cfg.token != "";
+        message = "token or tokenFile or configPath (with 'token' or 'token-file' keys) should be set if role is 'agent'";
       }
     ];
 
@@ -115,12 +121,10 @@ in
             "${cfg.package}/bin/k3s ${cfg.role}"
           ] ++ (optional cfg.docker "--docker")
           ++ (optional cfg.disableAgent "--disable-agent")
-          ++ (optional (cfg.role == "agent") "--server ${cfg.serverAddr} ${
-            if cfg.tokenFile != null then
-              "--token-file ${cfg.tokenFile}"
-            else
-              "--token ${cfg.token}"
-          }")
+          ++ (optional (cfg.serverAddr != "") "--server ${cfg.serverAddr}")
+          ++ (optional (cfg.token != "") "--token ${cfg.token}")
+          ++ (optional (cfg.tokenFile != null) "--token-file ${cfg.tokenFile}")
+          ++ (optional (cfg.configPath != null) "--config ${cfg.configPath}")
           ++ [ cfg.extraFlags ]
         );
       };