-
-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
colima: init #1275
Open
bryanhonof
wants to merge
1
commit into
LnL7:master
Choose a base branch
from
bryanhonof:bryanhonof.add-service-colima
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+241
−0
Open
colima: init #1275
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,192 @@ | ||||||
{ | ||||||
config, | ||||||
lib, | ||||||
pkgs, | ||||||
... | ||||||
}: | ||||||
|
||||||
with lib; | ||||||
let | ||||||
cfg = config.services.colima; | ||||||
user = config.users.users."colima"; | ||||||
group = config.users.groups."_colima"; | ||||||
in | ||||||
{ | ||||||
options.services.colima = { | ||||||
enable = mkEnableOption "Colima, a macOS container runtime"; | ||||||
|
||||||
enableDockerCompatability = mkOption { | ||||||
type = types.bool; | ||||||
default = false; | ||||||
description = '' | ||||||
Create a symlink from Colima's socket to /var/run/docker.sock, and set | ||||||
its permissions so that users part of the _colima group can use it. | ||||||
''; | ||||||
}; | ||||||
|
||||||
package = mkPackageOption pkgs "colima" { }; | ||||||
|
||||||
stateDir = lib.mkOption { | ||||||
type = types.path; | ||||||
default = "/var/lib/colima"; | ||||||
description = "State directory of the Colima process."; | ||||||
}; | ||||||
|
||||||
logFile = mkOption { | ||||||
type = types.path; | ||||||
default = "/var/log/colima.log"; | ||||||
description = "Combined stdout and stderr of the colima process. Set to /dev/null to disable."; | ||||||
}; | ||||||
|
||||||
groupMembers = mkOption { | ||||||
type = types.listOf types.str; | ||||||
default = [ ]; | ||||||
description = '' | ||||||
List of users that should be added to the _colima group. | ||||||
Only has effect with enableDockerCompatability enabled. | ||||||
''; | ||||||
}; | ||||||
|
||||||
runtime = mkOption { | ||||||
type = types.enum [ | ||||||
"docker" | ||||||
"containerd" | ||||||
"incus" | ||||||
]; | ||||||
default = "docker"; | ||||||
description = "The runtime to use with Colima."; | ||||||
}; | ||||||
|
||||||
architectue = mkOption { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And all other occurences of "architectue" -> "architecture" |
||||||
type = types.enum [ | ||||||
"x86_64" | ||||||
"aarch64" | ||||||
"host" | ||||||
]; | ||||||
default = "host"; | ||||||
description = "The architecture to use for the Colima virtual machine."; | ||||||
}; | ||||||
|
||||||
extraFlags = mkOption { | ||||||
type = types.listOf types.str; | ||||||
default = [ ]; | ||||||
example = [ "--vz-rosetta" ]; | ||||||
description = "Extra commandline options to pass to the colima start command."; | ||||||
}; | ||||||
|
||||||
vmType = mkOption { | ||||||
type = types.enum [ | ||||||
"qemu" | ||||||
"vz" | ||||||
]; | ||||||
default = "vz"; | ||||||
description = "Virtual machine type to use with Colima."; | ||||||
}; | ||||||
}; | ||||||
|
||||||
config = mkMerge [ | ||||||
(mkIf cfg.enableDockerCompatability { | ||||||
assertions = [ | ||||||
{ | ||||||
assertion = !cfg.enable; | ||||||
message = "services.colima.enableDockerCompatability doesn't make sense without enabling services.colima.enable"; | ||||||
} | ||||||
]; | ||||||
|
||||||
launchd.daemons.colima-docker-compat = { | ||||||
script = '' | ||||||
# Wait for the docker socket to be created. This is important when | ||||||
# we enabled Colima and Docker compatability at the same time, for | ||||||
# the first time. Colima takes a while creating the VM. | ||||||
until [ -S ${cfg.stateDir}/.colima/default/docker.sock ] | ||||||
do | ||||||
sleep 5 | ||||||
done | ||||||
|
||||||
chmod g+rw ${cfg.stateDir}/.colima/default/docker.sock | ||||||
ln -sf ${cfg.stateDir}/.colima/default/docker.sock /var/run/docker.sock | ||||||
''; | ||||||
|
||||||
serviceConfig = { | ||||||
RunAtLoad = true; | ||||||
EnvironmentVariables.PATH = "/usr/bin:/bin:/usr/sbin:/sbin"; | ||||||
}; | ||||||
}; | ||||||
|
||||||
users.groups."_colima".members = cfg.groupMembers; | ||||||
|
||||||
environment.systemPackages = [ | ||||||
pkgs.docker | ||||||
]; | ||||||
}) | ||||||
|
||||||
(mkIf cfg.enable { | ||||||
launchd.daemons.colima = { | ||||||
script = | ||||||
concatStringsSep " " [ | ||||||
"exec" | ||||||
(getExe cfg.package) | ||||||
"start" | ||||||
"--foreground" | ||||||
"--runtime ${cfg.runtime}" | ||||||
"--arch ${cfg.architectue}" | ||||||
"--vm-type ${cfg.vmType}" | ||||||
] | ||||||
+ escapeShellArgs cfg.extraFlags; | ||||||
|
||||||
serviceConfig = { | ||||||
KeepAlive = true; | ||||||
RunAtLoad = true; | ||||||
StandardErrorPath = cfg.logFile; | ||||||
StandardOutPath = cfg.logFile; | ||||||
GroupName = group.name; | ||||||
UserName = user.name; | ||||||
WorkingDirectory = cfg.stateDir; | ||||||
EnvironmentVariables = { | ||||||
PATH = "${pkgs.colima}/bin:${pkgs.docker}/bin:/usr/bin:/bin:/usr/sbin:/sbin"; | ||||||
COLIMA_HOME = "${cfg.stateDir}/.colima"; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
|
||||||
system.activationScripts.preActivation.text = '' | ||||||
touch '${cfg.logFile}' | ||||||
chown ${toString user.uid}:${toString user.gid} '${cfg.logFile}' | ||||||
''; | ||||||
|
||||||
users = { | ||||||
knownGroups = [ | ||||||
"colima" | ||||||
"_colima" | ||||||
]; | ||||||
knownUsers = [ | ||||||
"colima" | ||||||
"_colima" | ||||||
]; | ||||||
}; | ||||||
|
||||||
users.users."colima" = { | ||||||
uid = config.ids.uids.colima; | ||||||
gid = config.ids.gids._colima; | ||||||
home = cfg.stateDir; | ||||||
# The username isn't allowed to have an underscore in the beginning of | ||||||
# its name, otherwise the VM will fail to start with the following error | ||||||
# > "[hostagent] identifier \"_colima\" must match ^[A-Za-z0-9]+(?:[._-](?:[A-Za-z0-9]+))*$: invalid argument" fields.level=fatal | ||||||
name = "colima"; | ||||||
createHome = true; | ||||||
shell = "/bin/bash"; | ||||||
description = "System user for Colima"; | ||||||
}; | ||||||
|
||||||
users.groups."_colima" = { | ||||||
gid = config.ids.gids._colima; | ||||||
name = "_colima"; | ||||||
description = "System group for Colima"; | ||||||
}; | ||||||
}) | ||||||
]; | ||||||
|
||||||
meta.maintainers = [ | ||||||
lib.maintainers.bryanhonof or "bryanhonof" | ||||||
]; | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ config, pkgs, ... }: | ||
|
||
let | ||
colima = pkgs.runCommand "colima-0.0.0" { } "mkdir $out"; | ||
in | ||
|
||
{ | ||
services.colima = { | ||
enable = true; | ||
enableDockerCompatability = true; | ||
package = colima; | ||
groupMembers = [ "john" "jane" ]; | ||
}; | ||
|
||
test = '' | ||
echo "checking colima service in /Library/LaunchDaemons" >&2 | ||
grep "org.nixos.colima" ${config.out}/Library/LaunchDaemons/org.nixos.colima.plist | ||
grep "${colima}/bin/dnsmasq" ${config.out}/Library/LaunchDaemons/org.nixos.colima.plist | ||
|
||
echo "checking colima docker compat service in /Library/LaunchDaemons" >&2 | ||
grep "org.nixos.colima-docker-compat" ${config.out}/Library/LaunchDaemons/org.nixos.colima-docker-compat.plist | ||
|
||
echo "checking colima config" >&2 | ||
grep -F "--foreground" ${config.out}/Library/LaunchDaemons/org.nixos.colima.plist | ||
grep -F "--runtime docker" ${config.out}/Library/LaunchDaemons/org.nixos.colima.plist | ||
grep -F "--architectue host" ${config.out}/Library/LaunchDaemons/org.nixos.colima.plist | ||
|
||
echo "checking user creation in /activate" >&2 | ||
grep "sysadminctl -addUser ${lib.escapeShellArgs [ "foo" "-UID" config.ids.uids.colima "-GID" config.ids.uids._colima "-fullName" "colima" "-home" "/var/lib/colima" "-shell" "/bin/bash" ]}" ${config.out}/activate | ||
grep "createhomedir -cu ${lib.escapeShellArg "colima"}" ${config.out}/activate | ||
grep "sysadminctl -addUser ${lib.escapeShellArgs [ "colima" "-UID" config.ids.uids.colima ]} .* ${lib.escapeShellArgs [ "-shell" "/bin/bash" ] }" ${config.out}/activate | ||
grep "sysadminctl -addUser ${lib.escapeShellArg "colima"} .* ${lib.escapeShellArgs [ "-home" "/var/lib/colima" ]}" ${config.out}/activate | ||
(! grep "dscl . -delete ${lib.escapeShellArg "/Users/colima"}" ${config.out}/activate) | ||
(! grep "dscl . -delete ${lib.escapeShellArg "/Groups/_colima"}" ${config.out}/activate) | ||
|
||
echo "checking group creation in /activate" >&2 | ||
grep "dscl . -create ${lib.escapeShellArg "/Groups/_colima"} PrimaryGroupID ${builtins.toString config.ids.gids._colima}" ${config.out}/activate | ||
grep "dscl . -create ${lib.escapeShellArg "/Groups/_colima"} RealName ${lib.escapeShellArg "_colima"}" ${config.out}/activate | ||
grep "dscl . -create ${lib.escapeShellArg "/Groups/_colima"} PrimaryGroupID ${builtins.toString config.ids.gids._colima}" ${config.out}/activate | ||
(! grep "dscl . -delete ${lib.escapeShellArg "/Groups/_colima"}" ${config.out}/activate) | ||
|
||
echo "checking group membership in /activate" >&2 | ||
grep "dscl . -create ${lib.escapeShellArg "/Groups/_colima"} GroupMembership ${lib.escapeShellArgs [ "john" "jane" ]}" ${config.out}/activate | ||
''; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And of course all other occurences of "compatability" -> "compatibility"