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, ... }:
let
inherit (lib)
any
attrValues
mkIf
mkOption
mkEnableOption
mkMerge
types
;
@ -25,10 +27,13 @@ let
type = arionSettingsType name;
visible = "shallow";
};
rootless = mkEnableOption "Run this project in rootless mode";
_systemd = mkOption { internal = true; };
};
config =
let service = {
let
service = {
wantedBy = [ "multi-user.target" ];
after = [ "sockets.target" ];
@ -37,14 +42,16 @@ let
cfg.docker.client.package
];
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 = ''
echo 1>&2 "docker compose file: $ARION_PREBUILT"
arion --prebuilt-file "$ARION_PREBUILT" up
'';
};
in
if cfg.backend == "docker-rootless" then
if false then
# if false then
{ _systemd.user.services."arion-${name}" = service; }
else
{ _systemd.services."arion-${name}" = service; };
@ -110,14 +117,8 @@ in
virtualisation.docker.enable = true;
virtualisation.arion.docker.client.package = pkgs.docker;
})
(mkIf (cfg.backend == "docker-rootless") {
virtualisation = {
docker.rootless = {
enable = true;
setSocketVariable = true;
};
};
virtualisation.arion.docker.client.package = pkgs.docker;
(mkIf (any (project: project.rootless) (attrValues cfg.projects)) {
virtualisation.docker.rootless.enable = true;
})
]
);