LnL7 / nix-darwin

nix modules for darwin
MIT License
3.21k stars 459 forks source link

Add a `colima` module #1182

Open lloeki opened 1 week ago

lloeki commented 1 week ago

This would be nice to have:

Note that there seems to be a potential issue with sandboxing: https://github.com/abiosoft/colima/issues/490

There's this one upstream which requests a way to have a LaunchAgent or LaunchDaemon set up by colima but that would not be declarative: https://github.com/abiosoft/colima/issues/262

lloeki commented 1 week ago

Turns out, this worked fine:

  launchd.agents."colima.default" = {
    command = "${pkgs.colima}/bin/colima start --foreground";
    serviceConfig = {
      Label = "com.colima.default";
      RunAtLoad = true;
      KeepAlive = true;

      # not sure where to put these paths and not reference a hard-coded `$HOME`; `/var/log`?
      StandardOutPath = "/Users/loic.nageleisen/.colima/default/daemon/launchd.stdout.log";
      StandardErrorPath = "/Users/loic.nageleisen/.colima/default/daemon/launchd.stderr.log";

      # not using launchd.agents.<name>.path because colima needs the system ones as well
      EnvironmentVariables = {
        PATH = "${pkgs.colima}/bin:${pkgs.docker}/bin:/usr/bin:/bin:/usr/sbin:/sbin";
      };
    };
  };
$ darwin-rebuild switch
$ launchctl load -w /Library/LaunchAgents/com.colima.default.plist
$ launchctl print gui/$(id -u)/com.colima.default
$ colima status

Note that one may have some sandbox allowance popups the first time you access some directories from within the VM.