{ config, lib, pkgs, ... }: let cfg = config.programs.colima; yamlFormat = pkgs.formats.yaml { }; settingsType = lib.types.submodule { freeformType = yamlFormat.type; }; in { options.programs.colima = { enable = lib.mkEnableOption "Container runtimes on macOS"; package = lib.mkOption { type = lib.types.package; default = pkgs.colima; defaultText = lib.literalExpression "pkgs.colima"; description = "Package providing {command}`colima`."; }; settings = lib.mkOption { type = settingsType; default = { }; description = "Configuration written to {file}`$XDG_CONFIG_HOME/.colima/default/colima.yaml`."; example = lib.literalExpression '' { cpu = 2; disk = 60; memory = 2; }; ''; }; }; config = let colimaConfig = pkgs.writeTextFile { name = "colima.yaml"; text = lib.generators.toYAML { } cfg.settings; }; in lib.mkIf cfg.enable { home = { packages = [ cfg.package ]; sessionVariables = { DOCKER_HOST = "unix://${config.home.homeDirectory}/.colima/docker.sock"; DOCKER_CLIENT_ADDRESS = "unix://${config.home.homeDirectory}/.colima/docker.sock"; }; # because Colima writes to this file on startup activation.colimaConfig = lib.hm.dag.entryAfter [ "writeBoundary" ] '' mkdir -p ~/.colima/default cp -f "${colimaConfig}" ~/.colima/default/colima.yaml chmod 644 ~/.colima/default/colima.yaml ''; }; }; }