git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #130633 from zimbatm/k3s-configPath

nixos/k3s: add configPath option

commit58128d690dce9e88936be24c314b0f66875550a7 authorJörg Thalheim <Mic92@users.noreply.github.com> dateMon 19 Jul 2021, 15:22 (5 years ago) parentd53846eefbd199
1 file changed+14−10
nixos/modules/services/cluster/k3s/default.nix+14−10
nixos/modules/services/cluster/k3s/default.nix+14−10
@@ -67,6 +67,12 @@ in
6767 default = false;
6868 description = "Only run the server. This option only makes sense for a server.";
6969 };
70+
71+ configPath = mkOption {
72+ type = types.nullOr types.path;
73+ default = null;
74+ description = "File path containing the k3s YAML config. This is useful when the config is generated (for example on boot).";
75+ };
7076 };
7177
7278 # implementation
@@ -74,12 +80,12 @@ in
7480 config = mkIf cfg.enable {
7581 assertions = [
7682 {
77− assertion = cfg.role == "agent" -> cfg.serverAddr != "";
78− message = "serverAddr should be set if role is 'agent'";
83+ assertion = cfg.role == "agent" -> (cfg.configPath != null || cfg.serverAddr != "");
84+ message = "serverAddr or configPath (with 'server' key) should be set if role is 'agent'";
7985 }
8086 {
81− assertion = cfg.role == "agent" -> cfg.token != "" || cfg.tokenFile != null;
82− message = "token or tokenFile should be set if role is 'agent'";
87+ assertion = cfg.role == "agent" -> cfg.configPath != null || cfg.tokenFile != null || cfg.token != "";
88+ message = "token or tokenFile or configPath (with 'token' or 'token-file' keys) should be set if role is 'agent'";
8389 }
8490 ];
8591
@@ -115,12 +121,10 @@ in
115121 "${cfg.package}/bin/k3s ${cfg.role}"
116122 ] ++ (optional cfg.docker "--docker")
117123 ++ (optional cfg.disableAgent "--disable-agent")
118− ++ (optional (cfg.role == "agent") "--server ${cfg.serverAddr} ${
119− if cfg.tokenFile != null then
120− "--token-file ${cfg.tokenFile}"
121− else
122− "--token ${cfg.token}"
123− }")
124+ ++ (optional (cfg.serverAddr != "") "--server ${cfg.serverAddr}")
125+ ++ (optional (cfg.token != "") "--token ${cfg.token}")
126+ ++ (optional (cfg.tokenFile != null) "--token-file ${cfg.tokenFile}")
127+ ++ (optional (cfg.configPath != null) "--config ${cfg.configPath}")
124128 ++ [ cfg.extraFlags ]
125129 );
126130 };