feat: add support for docker-rootless

This commit is contained in:
Joscha Loos 2022-10-11 23:22:17 +02:00
parent 3131319c81
commit 46dbaee067

View file

@ -1,9 +1,11 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
inherit (lib) inherit (lib)
any
attrValues attrValues
mkIf mkIf
mkOption mkOption
mkEnableOption
mkMerge mkMerge
types types
; ;
@ -25,10 +27,13 @@ let
type = arionSettingsType name; type = arionSettingsType name;
visible = "shallow"; visible = "shallow";
}; };
rootless = mkEnableOption "Run this project in rootless mode";
_systemd = mkOption { internal = true; }; _systemd = mkOption { internal = true; };
}; };
config = config =
let service = { let
service = {
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
after = [ "sockets.target" ]; after = [ "sockets.target" ];
@ -37,14 +42,16 @@ let
cfg.docker.client.package cfg.docker.client.package
]; ];
environment.ARION_PREBUILT = config.settings.out.dockerComposeYaml; environment.ARION_PREBUILT = config.settings.out.dockerComposeYaml;
environment.DOCKER_HOST = mkIf (cfg.backend == "docker-rootless") "unix:///run/user/1000/docker.sock"; environment.DOCKER_HOST = mkIf config.rootless "unix:///run/user/1000/docker.sock"; # TODO: Do not hardcode path
script = '' script = ''
echo 1>&2 "docker compose file: $ARION_PREBUILT" echo 1>&2 "docker compose file: $ARION_PREBUILT"
arion --prebuilt-file "$ARION_PREBUILT" up arion --prebuilt-file "$ARION_PREBUILT" up
''; '';
}; };
in in
if cfg.backend == "docker-rootless" then if false then
# if false then
{ _systemd.user.services."arion-${name}" = service; } { _systemd.user.services."arion-${name}" = service; }
else else
{ _systemd.services."arion-${name}" = service; }; { _systemd.services."arion-${name}" = service; };
@ -110,14 +117,8 @@ in
virtualisation.docker.enable = true; virtualisation.docker.enable = true;
virtualisation.arion.docker.client.package = pkgs.docker; virtualisation.arion.docker.client.package = pkgs.docker;
}) })
(mkIf (cfg.backend == "docker-rootless") { (mkIf (any (project: project.rootless) (attrValues cfg.projects)) {
virtualisation = { virtualisation.docker.rootless.enable = true;
docker.rootless = {
enable = true;
setSocketVariable = true;
};
};
virtualisation.arion.docker.client.package = pkgs.docker;
}) })
] ]
); );