k3s: extend USAGE.md with package override instructions

closes #415969

RockWolf 36a45fd6 41fad9f8

+34
+34
pkgs/applications/networking/cluster/k3s/docs/USAGE.md
··· 64 64 K3s has a config setting `prefer-bundled-bin` (and CLI flag `--prefer-bundled-bin`) that makes k3s use binaries from the `/var/lib/rancher/k3s/data/current/bin/aux/` directory, as unpacked by the k3s binary, before the system `$PATH`. 65 65 This works with the official distribution of k3s but not with the package from nixpkgs, as it does not bundle the upstream binaries from [`k3s-root`](https://github.com/k3s-io/k3s-root) into the k3s binary. 66 66 Thus the `prefer-bundled-bin` setting **cannot** be used to work around issues (like [this `mount` regression](https://github.com/util-linux/util-linux/issues/3474)) with binaries used/called by the kubelet. 67 + 68 + ### Building from a different source 69 + 70 + Because the package is split into multiple derivations and the build process is generally more complex, it is not very obvious how to build k3s from a different source (fork or arbitrary commit). 71 + 72 + To build k3s from a different source, you must use `.override` together with `overrideBundleAttrs` (for the k3sBundle derivation) and another `.overrideAttrs` (for the final derivation): 73 + 74 + ```nix 75 + { fetchgit, k3s }: 76 + let 77 + k3sRepo = fetchgit { 78 + url = "https://github.com/k3s-io/k3s"; 79 + rev = "99d91538b1327da933356c318dc8040335fbb66c"; 80 + hash = "sha256-vVqZzVp0Tea27s8HDVq4SgqlbHBdZcFzNKmPFi0Yktk="; 81 + }; 82 + vendorHash = "sha256-jrPVY+FVZV9wlbik/I35W8ChcLrHlYbLAwUYU16mJLM="; 83 + in 84 + (k3s.override { 85 + overrideBundleAttrs = { 86 + src = k3sRepo; 87 + inherit vendorHash; 88 + }; 89 + }).overrideAttrs 90 + { 91 + src = k3sRepo; 92 + inherit vendorHash; 93 + } 94 + ``` 95 + 96 + - Additionally to `overrideBundleAttrs` there are also: `overrideCniPluginsAttrs` and `overrideContainerdAttrs`. 97 + - `k3s --version` still prints the commit SHA (`k3sCommit` passed into `builder.nix`) from the "base" package instead of the actually used `rev`. 98 + - Depending on the changes made in the fork / commit, the `k3s.override` (without the `overrideAttrs` of the final derivation) might already be enough. 99 + - If the commit is for a different version of k3s, make sure to use the correct "base" package, e.g., `k3s_1_31.override`. Otherwise the build fails with `Tagged version 'v1.33.1+k3s1' does not match expected version 'v1.31.9[+-]*'` 100 + - When adding an entirely new k3s version by calling `builder.nix`, keep in mind that the `k3sCommit` parameter is not used as the `k3sRepo` `rev` (it uses `v${k3sVersion}`). Therefore, you additionally must override the package, as shown above.