mirror of
https://github.com/libracoder/kiri.git
synced 2026-12-06 23:32:31 +09:00
- Recognise cross-volume Copy-Item CLI plugin copies via byte-size and SHA-256 content equality when no file-ID hardlink or .kiri-cli-plugins.json stamp matches, stamp managed plugins from setup-tools.ps1 and kiri.ps1, re-heal ~/.docker/cli-plugins live in kiri-win when Docker Desktop is installed or uninstalled, and include /opt/homebrew/lib/docker/cli-plugins and NixOS plugin paths in setup.rs SYSTEM_PLUGIN_DIRS (#1150, #1054 follow-up). - Guard macOS set_start_at_login when brew services is active so Kiri never falls through to writing a duplicate dev.kiri.daemon.plist when homebrew.mxcl.kiri.plist is absent or lacks RunAtLoad (#1134 follow-up). - Persist /etc/kiri/no-docker-sock when WSL socket integration is disabled on a user engine distro and honour it in kiri.service ExecStartPost and daemon::maybe_link_docker_sock across restarts (#1131 follow-up). - Pass kDNSServiceFlagsReturnIntermediates to DNSServiceGetAddrInfo, skip unusable IPv6 lookups on IPv4-only Macs, and distinguish clean NoSuchRecord results from lookup failures so DoH/DoT Supplemental domains with no UDP servers return NXDOMAIN (or NODATA when the sibling address family exists) instead of SERVFAIL (#1145 follow-up).
237 lines
9.3 KiB
Nix
237 lines
9.3 KiB
Nix
{
|
|
description = "Kiri container engine";
|
|
|
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
|
|
outputs = { self, nixpkgs }:
|
|
let
|
|
systems = [ "x86_64-linux" "aarch64-linux" ];
|
|
forAllSystems = nixpkgs.lib.genAttrs systems;
|
|
manifestVersion = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version;
|
|
kiriVersion =
|
|
if manifestVersion != "0.0.0" then manifestVersion
|
|
else "0.0.0-${self.shortRev or self.dirtyShortRev or "dev"}";
|
|
|
|
mkPackages = pkgs:
|
|
let
|
|
kiri-lite = pkgs.rustPlatform.buildRustPackage {
|
|
pname = "kiri-lite";
|
|
version = kiriVersion;
|
|
src = self;
|
|
|
|
cargoLock.lockFile = ./Cargo.lock;
|
|
cargoBuildFlags = [ "-p" "kiri" "-p" "kiri-init" ];
|
|
cargoTestFlags = [ "-p" "kiri" "-p" "kiri-init" ];
|
|
|
|
# Some unit tests inspect /home or require real root namespaces absent in the Nix build sandbox.
|
|
doCheck = false;
|
|
|
|
postInstall = ''
|
|
ln -sf kiri "$out/bin/kiri-forge"
|
|
ln -sf kiri-forge "$out/bin/kfg"
|
|
install -Dm644 packaging/linux/dev.kiri.host-access.policy \
|
|
"$out/share/polkit-1/actions/dev.kiri.host-access.policy"
|
|
substituteInPlace "$out/share/polkit-1/actions/dev.kiri.host-access.policy" \
|
|
--replace-fail "/usr/bin/kiri" "$out/bin/kiri"
|
|
install -Dm644 packaging/linux/kiri-nm.conf \
|
|
"$out/lib/NetworkManager/conf.d/kiri.conf"
|
|
'';
|
|
|
|
meta = {
|
|
description = "Small, fast container runtime (engine only)";
|
|
homepage = "https://runkiri.com/";
|
|
license = pkgs.lib.licenses.asl20;
|
|
platforms = systems;
|
|
mainProgram = "kiri";
|
|
};
|
|
};
|
|
|
|
kiri = pkgs.runCommand "kiri-${kiriVersion}" {
|
|
pname = "kiri";
|
|
version = kiriVersion;
|
|
meta = kiri-lite.meta // {
|
|
description = "Small, fast container runtime with bundled Docker CLI, Compose and buildx";
|
|
# Lower priority (higher number) than pkgs.docker (5) so enabling
|
|
# virtualisation.docker alongside Kiri never causes a bin/docker collision.
|
|
priority = 6;
|
|
};
|
|
} ''
|
|
mkdir -p \
|
|
"$out/bin" \
|
|
"$out/libexec/kiri/bin" \
|
|
"$out/libexec/kiri/cli-plugins" \
|
|
"$out/libexec/docker/cli-plugins" \
|
|
"$out/share/polkit-1/actions" \
|
|
"$out/lib/NetworkManager/conf.d"
|
|
|
|
# Copy the engine binaries so /proc/self/exe resolves inside $out and
|
|
# finds ../libexec/kiri/{bin,cli-plugins} directly beside this store path.
|
|
install -m755 "${kiri-lite}/bin/kiri" "$out/bin/kiri"
|
|
install -m755 "${kiri-lite}/bin/kiri-init" "$out/bin/kiri-init"
|
|
ln -sf kiri "$out/bin/kiri-forge"
|
|
ln -sf kiri-forge "$out/bin/kfg"
|
|
|
|
install -m644 "${self}/packaging/linux/dev.kiri.host-access.policy" \
|
|
"$out/share/polkit-1/actions/dev.kiri.host-access.policy"
|
|
substituteInPlace "$out/share/polkit-1/actions/dev.kiri.host-access.policy" \
|
|
--replace-fail "/usr/bin/kiri" "$out/bin/kiri"
|
|
install -m644 "${self}/packaging/linux/kiri-nm.conf" \
|
|
"$out/lib/NetworkManager/conf.d/kiri.conf"
|
|
|
|
ln -sf "${pkgs.docker-client}/bin/docker" "$out/libexec/kiri/bin/docker"
|
|
|
|
compose_bin="${pkgs.docker-compose}/libexec/docker/cli-plugins/docker-compose"
|
|
if [ ! -x "$compose_bin" ]; then
|
|
compose_bin="${pkgs.docker-compose}/bin/docker-compose"
|
|
fi
|
|
ln -sf "$compose_bin" "$out/libexec/kiri/cli-plugins/docker-compose"
|
|
ln -sf "$compose_bin" "$out/libexec/docker/cli-plugins/docker-compose"
|
|
|
|
buildx_bin="${pkgs.docker-buildx}/libexec/docker/cli-plugins/docker-buildx"
|
|
if [ ! -x "$buildx_bin" ]; then
|
|
buildx_bin="${pkgs.docker-buildx}/bin/docker-buildx"
|
|
fi
|
|
ln -sf "$buildx_bin" "$out/libexec/kiri/cli-plugins/docker-buildx"
|
|
ln -sf "$buildx_bin" "$out/libexec/docker/cli-plugins/docker-buildx"
|
|
|
|
substitute "${self}/packaging/linux/docker-wrapper" "$out/bin/docker" \
|
|
--replace-fail "#!/bin/sh" "#!${pkgs.runtimeShell}" \
|
|
--replace-fail "/usr/libexec/kiri/bin/docker" "$out/libexec/kiri/bin/docker"
|
|
chmod 755 "$out/bin/docker"
|
|
'';
|
|
in
|
|
{
|
|
inherit kiri kiri-lite;
|
|
};
|
|
|
|
nixosModule = { config, lib, pkgs, ... }:
|
|
let
|
|
cfg = config.services.kiri;
|
|
in
|
|
{
|
|
options.services.kiri = {
|
|
enable = lib.mkEnableOption "the Kiri container engine";
|
|
|
|
package = lib.mkOption {
|
|
type = lib.types.package;
|
|
default = self.packages.${pkgs.stdenv.hostPlatform.system}.kiri;
|
|
defaultText = lib.literalExpression "inputs.kiri.packages.\${pkgs.stdenv.hostPlatform.system}.kiri";
|
|
description = "The Kiri package to run and install (`kiri` with bundled Docker CLI, or `kiri-lite`).";
|
|
};
|
|
|
|
enableDockerCli = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = !(config.virtualisation.docker.enable or false);
|
|
defaultText = lib.literalExpression "!config.virtualisation.docker.enable";
|
|
description = "Whether to install `docker-client`, `docker-compose`, and `docker-buildx` into `environment.systemPackages`.";
|
|
};
|
|
|
|
users = lib.mkOption {
|
|
type = lib.types.listOf lib.types.str;
|
|
default = [ ];
|
|
example = [ "alice" ];
|
|
description = "User accounts added declaratively to `services.kiri.socketGroup` so they can access `/run/kiri/docker.sock`.";
|
|
};
|
|
|
|
socketGroup = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "kiri";
|
|
description = "Unix group granted read/write access to `/run/kiri/docker.sock`.";
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
environment.systemPackages =
|
|
[ cfg.package ]
|
|
++ lib.optionals cfg.enableDockerCli [
|
|
(lib.lowPrio pkgs.docker-client)
|
|
(lib.lowPrio pkgs.docker-compose)
|
|
(lib.lowPrio pkgs.docker-buildx)
|
|
];
|
|
|
|
environment.pathsToLink = [ "/libexec/docker/cli-plugins" ];
|
|
|
|
users.groups.${cfg.socketGroup} = {
|
|
members = cfg.users;
|
|
};
|
|
|
|
boot.kernelModules = [
|
|
"overlay"
|
|
"br_netfilter"
|
|
"nf_tables"
|
|
"tun"
|
|
"loop"
|
|
"veth"
|
|
];
|
|
|
|
boot.kernel.sysctl."net.ipv4.ip_forward" = lib.mkDefault true;
|
|
|
|
security.polkit.enable = lib.mkDefault true;
|
|
|
|
environment.etc."NetworkManager/conf.d/kiri.conf" = lib.mkIf config.networking.networkmanager.enable {
|
|
source = ./packaging/linux/kiri-nm.conf;
|
|
};
|
|
|
|
systemd.services.kiri = {
|
|
description = "Kiri container engine";
|
|
documentation = [ "https://runkiri.com" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
wants = [ "network-online.target" ];
|
|
after = [ "network-online.target" "docker.service" ];
|
|
path = [
|
|
pkgs.kmod
|
|
pkgs.iproute2
|
|
pkgs.util-linux
|
|
pkgs.e2fsprogs
|
|
pkgs.nftables
|
|
pkgs.iptables
|
|
pkgs.coreutils
|
|
pkgs.procps
|
|
pkgs.gnutar
|
|
pkgs.gzip
|
|
];
|
|
serviceConfig = {
|
|
ExecStart = "${cfg.package}/bin/kiri daemon";
|
|
ExecStartPost = "-${pkgs.runtimeShell} -c '[ -e /etc/kiri/no-docker-sock ] || [ \"$(readlink /run/docker.sock)\" = /run/kiri/docker.sock ] || [ -e /run/docker.sock ] || [ -L /run/docker.sock ] || ln -s /run/kiri/docker.sock /run/docker.sock'";
|
|
ExecStopPost = "-${pkgs.runtimeShell} -c '[ \"$(readlink /run/docker.sock)\" != /run/kiri/docker.sock ] || rm -f /run/docker.sock'";
|
|
Environment = [
|
|
"KIRI_SOCKET=/run/kiri/docker.sock"
|
|
"KIRI_SOCKET_GROUP=${cfg.socketGroup}"
|
|
"HOME=/var/lib/kiri-daemon"
|
|
];
|
|
Delegate = true;
|
|
LimitNPROC = "infinity";
|
|
LimitCORE = "infinity";
|
|
TasksMax = "infinity";
|
|
KillMode = "mixed";
|
|
Restart = "on-failure";
|
|
RuntimeDirectory = "kiri";
|
|
RuntimeDirectoryMode = "0755";
|
|
StateDirectory = "kiri-daemon";
|
|
StateDirectoryMode = "0700";
|
|
UMask = "0027";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
in
|
|
{
|
|
packages = forAllSystems (system:
|
|
let
|
|
pkgs = import nixpkgs { inherit system; };
|
|
built = mkPackages pkgs;
|
|
in
|
|
{
|
|
inherit (built) kiri kiri-lite;
|
|
default = built.kiri;
|
|
});
|
|
|
|
overlays.default = final: _prev: mkPackages final;
|
|
|
|
nixosModules = {
|
|
default = nixosModule;
|
|
kiri = nixosModule;
|
|
};
|
|
};
|
|
}
|