Repository navigation
fix(docker): update service file when Nix store paths change #1239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ let | |
| gnugrep | ||
| systemd | ||
| coreutils | ||
| diffutils | ||
| ; | ||
| docker_service_file = dockerServiceFile; | ||
| } | ||
|
|
||
| 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 | ||||||
|
|
||||||
|
|
@@ -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 | ||||||
|
|
@@ -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 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For boolean flags in shell scripts, it's more idiomatic to use
Suggested change
|
||||||
| sudo "$SYSTEMCTL" daemon-reload | ||||||
| fi | ||||||
|
Comment on lines
+24
to
+41
|
||||||
|
|
||||||
| # 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 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For boolean flags in shell scripts, it's more idiomatic to use
Suggested change
|
||||||
| echo "Restarting Docker daemon (service file updated)..." | ||||||
| sudo "$SYSTEMCTL" restart docker | ||||||
| echo "Docker daemon restarted" | ||||||
| else | ||||||
| echo "Docker daemon is already running" | ||||||
| fi | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diffutilsis only being pulled in to do a quiet file comparison. Sincecoreutilsis already injected, consider usingcmp -sfrom coreutils instead and dropping thediffutilsdependency/placeholder to keep the closure smaller and the substitution set simpler.