home

My NixOS systems configurations.
Log | Files | Refs | LICENSE

commit 7719b92c0dbea6274b90f72842480d32f6121c11
parent e371299aac27cc903bbb981b27851dc806ef304c
Author: Vincent Demeester <vincent@sbr.pm>
Date:   Wed, 23 Feb 2022 16:21:02 +0100

system/modules: refactor buildkit module…

… similar to upstream containerd, with settings and the buildkitd toml
config.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Diffstat:
Msystems/modules/profiles/docker.nix | 23++++++++++++++++++++---
Msystems/modules/virtualisation/buildkit.nix | 65++++++++++++++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 68 insertions(+), 20 deletions(-)

diff --git a/systems/modules/profiles/docker.nix b/systems/modules/profiles/docker.nix @@ -24,12 +24,29 @@ in virtualisation = { containerd = { enable = true; - # autostart = false; }; buildkitd = { enable = true; - extraOptions = "--oci-worker=false --containerd-worker=true"; - # autostart = false; + settings = { + worker.oci = { + enabled = false; + }; + worker.containerd = { + enable = true; + platforms = [ "linux/amd64" "linux/arm64" ]; + namespace = "buildkit"; + }; + registry = { + "r.svc.home:5000" = { + http = true; + insecure = true; + }; + "r.svc.home" = { + http = true; + insecure = true; + }; + }; + }; }; docker = { enable = true; diff --git a/systems/modules/virtualisation/buildkit.nix b/systems/modules/virtualisation/buildkit.nix @@ -1,22 +1,28 @@ { config, lib, pkgs, ... }: let cfg = config.virtualisation.buildkitd; - inherit (lib) mkOption mkIf types; + inherit (lib) mkOption mkIf; + inherit (lib.types) attrsOf str nullOr path bool package listOf; + + configFile = + if cfg.configFile == null then + settingsFormat.generate "buildkitd.toml" cfg.settings + else + cfg.configFile; + + settingsFormat = pkgs.formats.toml { }; in { options.virtualisation.buildkitd = { enable = mkOption { - type = types.bool; + type = bool; default = false; - description = - '' - This option enables buildkitd - ''; + description = ''This option enables buildkitd''; }; package = mkOption { default = pkgs.buildkit; - type = types.package; + type = package; example = pkgs.buildkit; description = '' Buildkitd package to be used in the module @@ -24,19 +30,32 @@ in }; packages = mkOption { - type = types.listOf types.package; + type = listOf package; default = [ pkgs.runc pkgs.git ]; description = "List of packages to be added to buildkitd service path"; }; - extraOptions = mkOption { - type = types.separatedString " "; - default = ""; - description = - '' - The extra command-line options to pass to - <command>buildkitd</command> daemon. - ''; + configFile = lib.mkOption { + default = null; + description = '' + Path to containerd config file. + Setting this option will override any configuration applied by the settings option. + ''; + type = nullOr path; + }; + + args = lib.mkOption { + default = { }; + description = "extra args to append to the containerd cmdline"; + type = attrsOf str; + }; + + settings = lib.mkOption { + type = settingsFormat.type; + default = { }; + description = '' + Verbatim lines to add to containerd.toml + ''; }; }; @@ -44,11 +63,23 @@ in users.groups.buildkit.gid = 350; environment.systemPackages = [ cfg.package ]; systemd.packages = [ cfg.package ]; + + virtualisation.buildkitd = { + args = { + addr = "unix:///run/buildkit/buildkitd.sock"; + group = "buildkit"; + config = toString configFile; + }; + settings = { + debug = false; + }; + }; + systemd.services.buildkitd = { after = [ "network.target" "containerd.service" ]; wantedBy = [ "multi-user.target" ]; serviceConfig = { - ExecStart = ''${cfg.package}/bin/buildkitd --addr=unix:///run/buildkit/buildkitd.sock --group=buildkit ${cfg.extraOptions}''; + ExecStart = ''${cfg.package}/bin/buildkitd ${lib.concatStringsSep " " (lib.cli.toGNUCommandLine {} cfg.args)}''; Delegate = "yes"; KillMode = "process"; Type = "notify";