-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor module options and support rootless k3s & nix-snapshotter
- Bumps version to 0.2.0 - Separate `nix run .#vm` and `nix run .#vm-rootless` - Add integration tests for k3s, k3s-external, k3s-rootless - Separate preload-container service into independent modules - Pin k3s to v1.27.9+k3s1 with patches to enable embedded nix-snapshotter - Add k8sResources flake perSystem output and plumb into specialArgs - Services `preload-containerd` & `preload-containerd.rootless`: ```nix config.services.preload-containerd = { enable = true; targets = [{ archives = [ pkgs.nix-snapshotter.buildImage { /* ... */ } ]; namespace = "k8s.io"; address = "/run/k3s/containerd/containerd.sock"; }]; }; ``` - New options for `k3s` & new service `k3s.rootless`: ```nix config.services.k3s = { enable = true; # Sets the snapshotter for embedded containerd. snapshotter = "nix"; # Sets KUBECONFIG env var to point to k3s. setKubeConfig = true; # Sets CONTAINERD_* env vars to point to k3s embedded containerd. setEmbeddedContainerd = true; } ``` - New options for `containerd` & `containerd.rootless`: ```nix config.virtualisation.containerd = { enable = true; # Enable integration with nix-snapshotter. nixSnapshotterIntegration = true; # Set the CONTAINERD_* env vars, but also set automatically by # `nixSnapshotterIntegration` or by `services.k3s.setEmbeddedContainerd`. setAddress = "/run/containerd/containerd.sock"; setNamespace = "default"; setSnapshotter = "nix"; } ``` - New option only for NixOS module `containerd`: ```nix config.virtualisation.containerd = { enable = true; # Enable integration with k3s. This is mutually exclusive with setting # `services.k3s.snapshotter` and `services.k3s.setEmbeddedContainerd`. k3sIntegration = true; }; ``` - Removed `options.services.nix-snapshotter.setContainerdSnapshotter` ```nix # v0.1.x services.nix-snapshotter = { enable = true; setContainerdSnapshotter = true; }; # v0.2.0 (same for rootless) virtualisation.containerd = { enable = true; nixSnapshotterIntegration = true; }; services.nix-snapshotter = { enable = true; }; ``` - Removed `options.services.nix-snapshotter.preloadContainerdImages` ```nix # v0.1.x services.nix-snapshotter = { enable = true; preloadContainerdImages = [ pkgs.nix-snapshotter.buildImage { /* ... */ } ]; }; # v0.2.0 (same for rootless) virtualisation.containerd = { enable = true; nixSnapshotterIntegration = true; } services.nix-snapshotter = { enable = true; }; services.preload-containerd = { targets = [{ archives = [ pkgs.nix-snapshotter.buildImage { /* ... */ } ]; }]; }; ```
- Loading branch information
Showing
46 changed files
with
1,616 additions
and
736 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
{ config, pkgs, lib, ... }: | ||
let | ||
inherit (lib) | ||
mkEnableOption | ||
mkOption | ||
types | ||
; | ||
|
||
inherit (pkgs.go) | ||
GOOS | ||
GOARCH | ||
; | ||
|
||
cfg = config.virtualisation.containerd; | ||
|
||
options = { | ||
k3sIntegration = mkEnableOption "K3s integration"; | ||
|
||
nixSnapshotterIntegration = mkEnableOption "Nix snapshotter integration"; | ||
|
||
setAddress = mkOption { | ||
type = types.str; | ||
default = "/run/containerd/containerd.sock"; | ||
description = lib.mdDoc '' | ||
Set the default containerd address via environment variable | ||
`CONTAINERD_ADDRESS`. | ||
''; | ||
}; | ||
|
||
setNamespace = mkOption { | ||
type = types.str; | ||
default = "default"; | ||
description = lib.mdDoc '' | ||
Set the default containerd namespace via environment variable | ||
`CONTAINERD_NAMESPACE`. | ||
''; | ||
}; | ||
|
||
setSnapshotter = mkOption { | ||
type = types.str; | ||
default = ""; | ||
description = lib.mdDoc '' | ||
Set the default containerd snapshotter via environment variable | ||
`CONTAINERD_SNAPSHOTTER`. | ||
''; | ||
}; | ||
}; | ||
|
||
mkNixSnapshotterSettings = { | ||
plugins."io.containerd.grpc.v1.cri".containerd = { | ||
snapshotter = "nix"; | ||
}; | ||
|
||
plugins."io.containerd.transfer.v1.local".unpack_config = [{ | ||
platform = "${GOOS}/${GOARCH}"; | ||
snapshotter = "nix"; | ||
}]; | ||
|
||
proxy_plugins.nix = { | ||
type = "snapshot"; | ||
address = "/run/nix-snapshotter/nix-snapshotter.sock"; | ||
}; | ||
}; | ||
|
||
in { | ||
options.virtualisation.containerd = { | ||
inherit (options) | ||
k3sIntegration | ||
nixSnapshotterIntegration | ||
setAddress | ||
setNamespace | ||
setSnapshotter | ||
; | ||
|
||
lib = mkOption { | ||
type = types.attrs; | ||
description = lib.mdDoc "Common functions for containerd."; | ||
default = { | ||
inherit | ||
options | ||
mkNixSnapshotterSettings | ||
; | ||
}; | ||
internal = true; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
virtualisation.containerd = lib.mkIf cfg.nixSnapshotterIntegration { | ||
setSnapshotter = lib.mkDefault "nix"; | ||
settings = mkNixSnapshotterSettings; | ||
}; | ||
}; | ||
} |
Oops, something went wrong.