diff --git a/modules/docker/enable-service.nix b/modules/docker/enable-service.nix index e52f579..b6da8d8 100644 --- a/modules/docker/enable-service.nix +++ b/modules/docker/enable-service.nix @@ -1,5 +1,8 @@ { lib, pkgs, vars, ... }: +let + gid = toString vars.dockerAccessGid; +in { virtualisation.docker = { enable = true; @@ -16,4 +19,27 @@ docker-compose docker-buildx ]; + + # NixOS's group activation uses plain `groupmod` without --non-unique. + # When SSSD is active it exposes the IPA "docker-access" group at + # vars.dockerAccessGid via NSS, so groupmod sees that GID as already in + # use and silently skips the change (warning: "not applying GID change"). + # This script runs after the normal "groups" step and applies the change + # with --non-unique (which lets the local docker group share the GID with + # the SSSD-provided IPA group). If the GID actually changed it also + # restarts docker.socket so the socket is recreated with the new GID. + system.activationScripts.docker-group-gid = { + deps = [ "groups" ]; + text = '' + current=$(grep "^docker:" /etc/group | cut -d: -f3) + if [ "$current" != "${gid}" ]; then + ${pkgs.shadow}/bin/groupmod --non-unique -g ${gid} docker + if ${pkgs.systemd}/bin/systemctl is-active --quiet docker.socket; then + ${pkgs.systemd}/bin/systemctl stop docker.service docker.socket + rm -f /var/run/docker.sock + ${pkgs.systemd}/bin/systemctl start docker.socket docker.service + fi + fi + ''; + }; }