aboutsummaryrefslogtreecommitdiff
path: root/programs/colima.nix
blob: ecf412abe9aec6b8e68cec267a7037a23b3624eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{ 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";
        };
        # 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
        '';
      };
    };
}