aboutsummaryrefslogtreecommitdiff
path: root/programs/colima.nix
blob: 44c86f9852eca88c17ea9763c7ba0b14289266ff (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
{ 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 ];

      # because Colima writes to this file on startup
      home.activation.colimaConfig = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
        mkdir -p ~/.colima/default
        cp -f "${colimaConfig}" ~/.colima/default/colima.yaml
        chmod 644 ~/.colima/default/colima.yaml
      '';
    };
}