Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions home-manager/services/docker/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let
gnugrep
systemd
coreutils
diffutils

Copilot AI Mar 21, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diffutils is only being pulled in to do a quiet file comparison. Since coreutils is already injected, consider using cmp -s from coreutils instead and dropping the diffutils dependency/placeholder to keep the closure smaller and the substitution set simpler.

Suggested change
diffutils

Copilot uses AI. Check for mistakes.
;
docker_service_file = dockerServiceFile;
}
Expand Down
36 changes: 27 additions & 9 deletions home-manager/services/docker/setup-docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Ensures the user is in the docker group and the system Docker daemon is running.
# @shadow@, @gnugrep@, @systemd@, @coreutils@, @docker_service_file@
# @shadow@, @gnugrep@, @systemd@, @coreutils@, @docker_service_file@, @diffutils@
# are substituted by pkgs.replaceVars.
set -euo pipefail

Expand All @@ -10,7 +10,9 @@ GREP=@gnugrep@/bin/grep
USERMOD=@shadow@/bin/usermod
SYSTEMCTL=@systemd@/bin/systemctl
TEE=@coreutils@/bin/tee
DIFF=@diffutils@/bin/diff
DOCKER_SERVICE_FILE=@docker_service_file@
SYSTEM_SERVICE=/etc/systemd/system/docker.service

# Check if docker group exists and user is in it
if ! "$GROUPS_CMD" | "$GREP" -q docker; then
Expand All @@ -19,18 +21,34 @@ if ! "$GROUPS_CMD" | "$GREP" -q docker; then
echo "Added to docker group. Please log out and back in, or run: newgrp docker"
fi

# Check if system docker service exists and is running
# Always ensure the service file is up to date (Nix GC can invalidate store paths)
NEEDS_RELOAD=false
if [ ! -f "$SYSTEM_SERVICE" ]; then
echo "Installing Docker systemd service..."
# shellcheck disable=SC2024
sudo "$TEE" "$SYSTEM_SERVICE" >/dev/null <"$DOCKER_SERVICE_FILE"
sudo "$SYSTEMCTL" enable docker
NEEDS_RELOAD=true
elif ! "$DIFF" -q "$DOCKER_SERVICE_FILE" "$SYSTEM_SERVICE" >/dev/null 2>&1; then
echo "Updating Docker systemd service (Nix store paths changed)..."
# shellcheck disable=SC2024
sudo "$TEE" "$SYSTEM_SERVICE" >/dev/null <"$DOCKER_SERVICE_FILE"
NEEDS_RELOAD=true
fi

if [ "$NEEDS_RELOAD" = true ]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For boolean flags in shell scripts, it's more idiomatic to use true and false commands directly in the if condition rather than string comparison. This makes the code cleaner and less error-prone (e.g., typos in string literals).

Suggested change
if [ "$NEEDS_RELOAD" = true ]; then
if $NEEDS_RELOAD; then

sudo "$SYSTEMCTL" daemon-reload
fi
Comment on lines +24 to +41

Copilot AI Mar 21, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New behavior (diffing the desired vs installed unit, daemon-reload, and conditional restart) isn’t covered by the existing ShellSpec tests for this script. Please extend spec/docker_setup_spec.sh to assert the new @diffutils@ placeholder is present and that the script includes the daemon-reload/restart path when the unit file differs.

Copilot uses AI. Check for mistakes.

# Start or restart Docker as needed
if ! "$SYSTEMCTL" is-active --quiet docker 2>/dev/null; then
echo "Starting Docker daemon..."
if [ ! -f /etc/systemd/system/docker.service ]; then
echo "Installing Docker systemd service..."
# shellcheck disable=SC2024
sudo "$TEE" /etc/systemd/system/docker.service >/dev/null <"$DOCKER_SERVICE_FILE"
sudo "$SYSTEMCTL" daemon-reload
sudo "$SYSTEMCTL" enable docker
fi
sudo "$SYSTEMCTL" start docker
echo "Docker daemon started"
elif [ "$NEEDS_RELOAD" = true ]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For boolean flags in shell scripts, it's more idiomatic to use true and false commands directly in the if condition rather than string comparison. This makes the code cleaner and less error-prone (e.g., typos in string literals).

Suggested change
elif [ "$NEEDS_RELOAD" = true ]; then
elif $NEEDS_RELOAD; then

echo "Restarting Docker daemon (service file updated)..."
sudo "$SYSTEMCTL" restart docker
echo "Docker daemon restarted"
else
echo "Docker daemon is already running"
fi
Loading