···308308309309The `name` argument is the name of the derivation output, which defaults to `fromImage.name`.
310310311311-## shadowSetup {#ssec-pkgs-dockerTools-shadowSetup}
311311+## Environment Helpers {#ssec-pkgs-dockerTools-helpers}
312312+313313+Some packages expect certain files to be available globally.
314314+When building an image from scratch (i.e. without `fromImage`), these files are missing.
315315+`pkgs.dockerTools` provides some helpers to set up an environment with the necessary files.
316316+You can include them in `copyToRoot` like this:
317317+318318+```nix
319319+buildImage {
320320+ name = "environment-example";
321321+ copyToRoot = with pkgs.dockerTools; [
322322+ usrBinEnv
323323+ binSh
324324+ caCertificates
325325+ fakeNss
326326+ ];
327327+}
328328+```
329329+330330+### usrBinEnv {#sssec-pkgs-dockerTools-helpers-usrBinEnv}
331331+332332+This provides the `env` utility at `/usr/bin/env`.
333333+334334+### binSh {#sssec-pkgs-dockerTools-helpers-binSh}
335335+336336+This provides `bashInteractive` at `/bin/sh`.
337337+338338+### caCertificates {#sssec-pkgs-dockerTools-helpers-caCertificates}
339339+340340+This sets up `/etc/ssl/certs/ca-certificates.crt`.
341341+342342+### fakeNss {#sssec-pkgs-dockerTools-helpers-fakeNss}
343343+344344+Provides `/etc/passwd` and `/etc/group` that contain root and nobody.
345345+Useful when packaging binaries that insist on using nss to look up
346346+username/groups (like nginx).
347347+348348+### shadowSetup {#ssec-pkgs-dockerTools-shadowSetup}
312349313350This constant string is a helper for setting up the base files for managing users and groups, only if such files don't exist already. It is suitable for being used in a [`buildImage` `runAsRoot`](#ex-dockerTools-buildImage-runAsRoot) script for cases like in the example below:
314351
+3-1
lib/modules.nix
···433433 # modules recursively. It returns the final list of unique-by-key modules
434434 filterModules = modulesPath: { disabled, modules }:
435435 let
436436- moduleKey = m: if isString m then toString modulesPath + "/" + m else toString m;
436436+ moduleKey = m: if isString m && (builtins.substring 0 1 m != "/")
437437+ then toString modulesPath + "/" + m
438438+ else toString m;
437439 disabledKeys = map moduleKey disabled;
438440 keyFilter = filter (attrs: ! elem attrs.key disabledKeys);
439441 in map (attrs: attrs.module) (builtins.genericClosure {
+1
lib/tests/modules.sh
···130130set -- config.enable ./define-enable.nix ./declare-enable.nix
131131checkConfigOutput '^true$' "$@"
132132checkConfigOutput '^false$' "$@" ./disable-define-enable.nix
133133+checkConfigOutput '^false$' "$@" ./disable-define-enable-string-path.nix
133134checkConfigError "The option .*enable.* does not exist. Definition values:\n\s*- In .*: true" "$@" ./disable-declare-enable.nix
134135checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-define-enable.nix ./disable-declare-enable.nix
135136checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-enable-modules.nix
···441441 due to upstream dropping support.
442442 </para>
443443 </listitem>
444444+ <listitem>
445445+ <para>
446446+ <literal>k3s</literal> supports <literal>clusterInit</literal>
447447+ option, and it is enabled by default, for servers.
448448+ </para>
449449+ </listitem>
444450 </itemizedlist>
445451 </section>
446452 <section xml:id="sec-release-22.11-notable-changes">
+2
nixos/doc/manual/release-notes/rl-2211.section.md
···154154155155- `k3s` no longer supports docker as runtime due to upstream dropping support.
156156157157+- `k3s` supports `clusterInit` option, and it is enabled by default, for servers.
158158+157159<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
158160159161## Other Notable Changes {#sec-release-22.11-notable-changes}
+52-4
nixos/modules/services/cluster/k3s/default.nix
···2525 role = mkOption {
2626 description = lib.mdDoc ''
2727 Whether k3s should run as a server or agent.
2828- Note that the server, by default, also runs as an agent.
2828+2929+ If it's a server:
3030+3131+ - By default it also runs workloads as an agent.
3232+ - Starts by default as a standalone server using an embedded sqlite datastore.
3333+ - Configure `clusterInit = true` to switch over to embedded etcd datastore and enable HA mode.
3434+ - Configure `serverAddr` to join an already-initialized HA cluster.
3535+3636+ If it's an agent:
3737+3838+ - `serverAddr` is required.
2939 '';
3040 default = "server";
3141 type = types.enum [ "server" "agent" ];
···33433444 serverAddr = mkOption {
3545 type = types.str;
3636- description = lib.mdDoc "The k3s server to connect to. This option only makes sense for an agent.";
4646+ description = lib.mdDoc ''
4747+ The k3s server to connect to.
4848+4949+ Servers and agents need to communicate each other. Read
5050+ [the networking docs](https://rancher.com/docs/k3s/latest/en/installation/installation-requirements/#networking)
5151+ to know how to configure the firewall.
5252+ '';
3753 example = "https://10.0.0.10:6443";
3854 default = "";
3955 };
40565757+ clusterInit = mkOption {
5858+ type = types.bool;
5959+ default = false;
6060+ description = lib.mdDoc ''
6161+ Initialize HA cluster using an embedded etcd datastore.
6262+6363+ If this option is `false` and `role` is `server`
6464+6565+ On a server that was using the default embedded sqlite backend,
6666+ enabling this option will migrate to an embedded etcd DB.
6767+6868+ If an HA cluster using the embedded etcd datastore was already initialized,
6969+ this option has no effect.
7070+7171+ This option only makes sense in a server that is not connecting to another server.
7272+7373+ If you are configuring an HA cluster with an embedded etcd,
7474+ the 1st server must have `clusterInit = true`
7575+ and other servers must connect to it using `serverAddr`.
7676+ '';
7777+ };
7878+4179 token = mkOption {
4280 type = types.str;
4381 description = lib.mdDoc ''
4444- The k3s token to use when connecting to the server. This option only makes sense for an agent.
8282+ The k3s token to use when connecting to a server.
8383+4584 WARNING: This option will expose store your token unencrypted world-readable in the nix store.
4685 If this is undesired use the tokenFile option instead.
4786 '';
···50895190 tokenFile = mkOption {
5291 type = types.nullOr types.path;
5353- description = lib.mdDoc "File path containing k3s token to use when connecting to the server. This option only makes sense for an agent.";
9292+ description = lib.mdDoc "File path containing k3s token to use when connecting to the server.";
5493 default = null;
5594 };
5695···86125 assertion = cfg.role == "agent" -> cfg.configPath != null || cfg.tokenFile != null || cfg.token != "";
87126 message = "token or tokenFile or configPath (with 'token' or 'token-file' keys) should be set if role is 'agent'";
88127 }
128128+ {
129129+ assertion = cfg.role == "agent" -> !cfg.disableAgent;
130130+ message = "disableAgent must be false if role is 'agent'";
131131+ }
132132+ {
133133+ assertion = cfg.role == "agent" -> !cfg.clusterInit;
134134+ message = "clusterInit must be false if role is 'agent'";
135135+ }
89136 ];
9013791138 environment.systemPackages = [ config.services.k3s.package ];
···111158 [
112159 "${cfg.package}/bin/k3s ${cfg.role}"
113160 ]
161161+ ++ (optional cfg.clusterInit "--cluster-init")
114162 ++ (optional cfg.disableAgent "--disable-agent")
115163 ++ (optional (cfg.serverAddr != "") "--server ${cfg.serverAddr}")
116164 ++ (optional (cfg.token != "") "--token ${cfg.token}")
+4-2
nixos/modules/services/web-apps/keycloak.nix
···2525 catAttrs
2626 collect
2727 splitString
2828+ hasPrefix
2829 ;
29303031 inherit (builtins)
···312313313314 http-relative-path = mkOption {
314315 type = str;
315315- default = "";
316316+ default = "/";
316317 example = "/auth";
318318+ apply = x: if !(hasPrefix "/") x then "/" + x else x;
317319 description = ''
318320 The path relative to <literal>/</literal> for serving
319321 resources.
···658660 '' + ''
659661 export KEYCLOAK_ADMIN=admin
660662 export KEYCLOAK_ADMIN_PASSWORD=${cfg.initialAdminPassword}
661661- kc.sh start
663663+ kc.sh start --optimized
662664 '';
663665 };
664666
···792792 ln -s ${bashInteractive}/bin/bash $out/bin/sh
793793 '';
794794795795+ # This provides the ca bundle in common locations
796796+ caCertificates = runCommand "ca-certificates" { } ''
797797+ # Old NixOS compatibility.
798798+ ln -s ${cacert}/etc/ssl/certs/ca-bundle.crt $out/etc/ssl/certs/ca-bundle.crt
799799+ # NixOS canonical location + Debian/Ubuntu/Arch/Gentoo compatibility.
800800+ ln -s ${cacert}/etc/ssl/certs/ca-bundle.crt $out/etc/ssl/certs/ca-certificates.crt
801801+ # CentOS/Fedora compatibility.
802802+ ln -s ${cacert}/etc/ssl/certs/ca-bundle.crt $out/etc/pki/tls/certs/ca-bundle.crt
803803+ '';
804804+795805 # Build an image and populate its nix database with the provided
796806 # contents. The main purpose is to be able to use nix commands in
797807 # the container.