Skip to content

fix(docker): update service file when Nix store paths change - #1239

Merged
shunkakinoki merged 1 commit into
mainfrom
fix/docker-service-gc-resilience
Mar 21, 2026
Merged

fix(docker): update service file when Nix store paths change#1239
shunkakinoki merged 1 commit into
mainfrom
fix/docker-service-gc-resilience

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Mar 21, 2026

Copy link
Copy Markdown
Owner

Summary

  • docker-setup now always compares the installed service file against the desired one
  • If Nix store paths have changed (e.g. after nix-collect-garbage), the service file is updated and Docker is restarted
  • Previously, the service file was only installed when missing — a stale file with GC'd paths would persist and prevent Docker from starting

Test plan

  • Run make build && make switch to get new docker-setup script
  • Run docker-setup — should say "Docker daemon is already running" if paths match
  • Run nix-collect-garbage -d, then docker-setup — should detect stale paths and update the service file

Summary by cubic

Keep the Docker systemd service in sync with current Nix store paths to prevent daemon startup failures after nix-collect-garbage. The setup script now updates the service file when paths change, reloads systemd, and restarts Docker if needed.

  • Bug Fixes
    • Compare desired service file with /etc/systemd/system/docker.service; install or update when different.
    • Reload systemd when the service file changes; start or restart Docker accordingly.
    • Add diffutils for reliable file comparison.

Written for commit a8ac711. Summary will update on new commits.

After nix-collect-garbage, the Docker systemd service file can reference
deleted Nix store paths, preventing Docker from starting. The setup
script only installed the service file when missing, not when stale.

Now docker-setup always compares the current service file against the
desired one and updates it if paths have changed, then restarts Docker.
Copilot AI review requested due to automatic review settings March 21, 2026 11:39
@mesa-dot-dev

mesa-dot-dev Bot commented Mar 21, 2026

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@coderabbitai

coderabbitai Bot commented Mar 21, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 58d402de-a3d9-425a-bc91-f85aa5b71726

📥 Commits

Reviewing files that changed from the base of the PR and between b3ba3a6 and a8ac711.

📒 Files selected for processing (2)
  • home-manager/services/docker/default.nix
  • home-manager/services/docker/setup-docker.sh

📝 Walkthrough

Summary by CodeRabbit

Bug Fixes

  • Improved detection of Docker service configuration changes using file comparison
  • Docker service now automatically restarts when its configuration is updated
  • Enhanced reliability of service file initialization and updates

Walkthrough

The Docker service module in home-manager is enhanced by adding diffutils as a dependency and updating the setup script to detect when the systemd service file has changed. The script now compares the existing file with the expected content and conditionally reloads the systemd daemon and restarts Docker only when necessary.

Changes

Cohort / File(s) Summary
Docker Module Configuration
home-manager/services/docker/default.nix
Added diffutils to the package inheritance list passed to the setup script.
Docker Setup Script
home-manager/services/docker/setup-docker.sh
Introduced diffutils-based file comparison using diff -q to detect if the systemd service file is missing or differs from expected content. Added NEEDS_RELOAD state variable to control whether systemctl daemon-reload and Docker restart should execute. Reordered installation logic to ensure the service file is always set up before daemon status checks.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly Related PRs

Suggested Labels

bug

Poem

🐰 A diff to spot what's out of place,
With diffutils keeping up the pace,
NEEDS_RELOAD holds the key,
Docker restartsings so gracefully,
Systemd blooms in harmony!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: updating the Docker service file when Nix store paths change, which directly aligns with the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem being solved and the solution implemented with sufficient detail.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/docker-service-gc-resilience

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Docker setup process by ensuring the systemd service file remains synchronized with the current Nix store paths. It introduces a robust mechanism to detect and rectify outdated service configurations, particularly after Nix garbage collection, thereby improving the reliability of Docker daemon startup and operation within a Nix-managed environment.

Highlights

  • Service File Comparison: The docker-setup script now consistently compares the installed Docker service file against the desired configuration.
  • Automatic Service File Update: If Nix store paths have changed (e.g., after nix-collect-garbage), the service file is automatically updated, and Docker is restarted to reflect these changes.
  • Preventing Stale Configurations: This change resolves an issue where a stale service file with garbage-collected paths could persist and prevent Docker from starting, as the file was previously only installed if missing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@mesa-dot-dev

mesa-dot-dev Bot commented Mar 21, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Fixes an issue where stale Docker service files, containing garbage-collected Nix paths, prevented Docker from starting by ensuring the docker-setup script always updates the service file if paths change.

What changed?

  • The docker-setup script now proactively compares the installed Docker service file against the desired configuration.
  • If Nix store paths change (e.g., after nix-collect-garbage), the service file is updated and Docker is restarted.
  • This resolves a bug where a stale service file with invalidated paths would persist and prevent Docker from starting, as the script previously only installed the file if it was entirely missing.

Description generated by Mesa. Update settings

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces a fix for the docker-setup script to handle stale Nix store paths in the Docker systemd service file. The changes are well-implemented: the script now compares the installed service file with the desired one using diff and, if they differ, updates the file and restarts the Docker daemon. This robustly addresses the issue of Docker failing to start after nix-collect-garbage. My review includes a couple of suggestions to use a more idiomatic shell scripting pattern for boolean flags, which would improve code clarity and maintainability.

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

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

No issues found across 2 files

Copilot AI left a comment

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.

Pull request overview

This PR improves the reliability of the Home Manager Docker setup flow by ensuring the installed systemd unit is kept in sync with the desired Nix-generated unit, preventing failures after Nix store paths change (e.g., due to garbage collection).

Changes:

  • Always compare /etc/systemd/system/docker.service against the Nix-generated desired service file and reinstall if they differ.
  • Trigger systemctl daemon-reload and restart Docker when the unit file is updated.
  • Add diffutils to the Nix substitution inputs to support the unit-file comparison.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
home-manager/services/docker/setup-docker.sh Adds unit-file comparison/update logic plus daemon-reload and conditional restart behavior.
home-manager/services/docker/default.nix Adds diffutils to the replaceVars inputs used to build setup-docker.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.
Comment on lines +24 to +41
# 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
sudo "$SYSTEMCTL" daemon-reload
fi

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.
@shunkakinoki
shunkakinoki merged commit 4176375 into main Mar 21, 2026
42 of 44 checks passed
@shunkakinoki
shunkakinoki deleted the fix/docker-service-gc-resilience branch March 21, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants