From 46dbaee06745ff44326e5ab0b7a71f8c13f7a17d Mon Sep 17 00:00:00 2001 From: Joscha Loos Date: Tue, 11 Oct 2022 23:22:17 +0200 Subject: [PATCH] feat: add support for docker-rootless --- nixos-module.nix | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/nixos-module.nix b/nixos-module.nix index 8a46b32..4c539e2 100644 --- a/nixos-module.nix +++ b/nixos-module.nix @@ -1,9 +1,11 @@ { config, lib, pkgs, ... }: let inherit (lib) + any attrValues mkIf mkOption + mkEnableOption mkMerge types ; @@ -25,26 +27,31 @@ let type = arionSettingsType name; visible = "shallow"; }; + rootless = mkEnableOption "Run this project in rootless mode"; _systemd = mkOption { internal = true; }; }; config = - let service = { - wantedBy = [ "multi-user.target" ]; - after = [ "sockets.target" ]; + let + + service = { + wantedBy = [ "multi-user.target" ]; + after = [ "sockets.target" ]; + + path = [ + cfg.package + cfg.docker.client.package + ]; + environment.ARION_PREBUILT = config.settings.out.dockerComposeYaml; + 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 + ''; + }; - path = [ - cfg.package - 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"; - 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; }) ] );