-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: extract inline Nix scripts to external files #1175
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fd13a8f
refactor: extract inline Nix scripts to external files with testing a…
shunkakinoki ca41c57
fix: resolve ruff lint errors and apply treefmt formatting
shunkakinoki 14b535d
fix: address CI failures and PR review comments
shunkakinoki 4bdd234
fix: use actions/setup-python@v6 with python-version-file
shunkakinoki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| name: Python | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| workflow_dispatch: | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.sha }} | ||
| cancel-in-progress: true | ||
| jobs: | ||
| python-test: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v7 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version-file: "pyproject.toml" | ||
| - name: Run tests | ||
| env: | ||
| PYTHONPATH: ${{ github.workspace }} | ||
| run: uv run --with pytest --no-project pytest tests | ||
| python-lint: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v7 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version-file: "pyproject.toml" | ||
| - name: Install ruff | ||
| run: uv pip install --system ruff | ||
| - name: Lint code with Ruff | ||
| run: ruff check --output-format=github | ||
| - name: Check code formatting with Ruff | ||
| run: ruff format --check --diff | ||
| python-check: | ||
| if: always() | ||
| needs: | ||
| - python-test | ||
| - python-lint | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| steps: | ||
| - name: Alls Green | ||
| uses: re-actors/alls-green@release/v1 | ||
| with: | ||
| jobs: ${{ toJSON(needs) }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/usr/bin/env bash | ||
| # Thin shim that delegates to the Nix-store install-yek script. | ||
| # @bash@ and @install_yek_script@ are substituted by pkgs.replaceVars. | ||
| exec @bash@/bin/bash @install_yek_script@ "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/usr/bin/env bash | ||
| # Thin shim that delegates to the Nix-store yek wrapper script. | ||
| # @bash@ and @yek_wrapper_script@ are substituted by pkgs.replaceVars. | ||
| exec @bash@/bin/bash @yek_wrapper_script@ "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #!/usr/bin/env bash | ||
| # Smart wrapper that handles both NixOS and non-NixOS Linux. | ||
| # On NixOS: docker group is properly inherited, or use /run/wrappers/bin/sg. | ||
| # On non-NixOS: systemd user session may lack docker group, use /usr/bin/sg. | ||
| # @bash@, @start_script@, @docker@ are substituted by pkgs.replaceVars. | ||
| SCRIPT="@bash@/bin/bash @start_script@" | ||
|
|
||
| # Try docker directly first (works on NixOS or when user has docker group) | ||
| if @docker@/bin/docker info >/dev/null 2>&1; then | ||
| exec $SCRIPT | ||
| fi | ||
|
|
||
| # Docker not accessible directly, try sg to switch group | ||
| if [ -x /run/wrappers/bin/sg ]; then | ||
| exec /run/wrappers/bin/sg docker -c "$SCRIPT" | ||
| elif [ -x /usr/bin/sg ]; then | ||
| exec /usr/bin/sg docker -c "$SCRIPT" | ||
| else | ||
| echo "ERROR: Cannot access Docker. User not in docker group and no sg binary found." >&2 | ||
| exit 1 | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
home-manager/services/docker-postgres/start-postgres-wrapper.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #!/usr/bin/env bash | ||
| # Smart wrapper that handles both NixOS and non-NixOS Linux. | ||
| # On NixOS: docker group is properly inherited, or use /run/wrappers/bin/sg (SUID wrapper). | ||
| # On non-NixOS: systemd user session may lack docker group, use /usr/bin/sg (system binary with SUID). | ||
| # @bash@, @start_script@, @docker@ are substituted by pkgs.replaceVars. | ||
| SCRIPT="@bash@/bin/bash @start_script@" | ||
|
|
||
| # Try docker directly first (works on NixOS or when user has docker group) | ||
| if @docker@/bin/docker info >/dev/null 2>&1; then | ||
| exec $SCRIPT | ||
| fi | ||
|
|
||
| # Docker not accessible directly, try sg to switch group | ||
| if [ -x /run/wrappers/bin/sg ]; then | ||
| exec /run/wrappers/bin/sg docker -c "$SCRIPT" | ||
| elif [ -x /usr/bin/sg ]; then | ||
| exec /usr/bin/sg docker -c "$SCRIPT" | ||
| else | ||
| echo "ERROR: Cannot access Docker. User not in docker group and no sg binary found." >&2 | ||
| exit 1 | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,64 +1,37 @@ | ||
| { pkgs, lib, ... }: | ||
| let | ||
| # Systemd service file for Docker daemon | ||
| dockerServiceFile = pkgs.writeText "docker.service" '' | ||
| [Unit] | ||
| Description=Docker Application Container Engine | ||
| Documentation=https://docs.docker.com | ||
| After=network-online.target | ||
| Wants=network-online.target | ||
|
|
||
| [Service] | ||
| Type=notify | ||
| ExecStart=${pkgs.docker}/bin/dockerd | ||
| ExecReload=${pkgs.coreutils}/bin/kill -s HUP $MAINPID | ||
| Restart=always | ||
| RestartSec=10s | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target | ||
| ''; | ||
| dockerServiceFile = pkgs.writeText "docker.service" ( | ||
| builtins.readFile ( | ||
| pkgs.replaceVars ./docker.service { | ||
| docker = pkgs.docker; | ||
| coreutils = pkgs.coreutils; | ||
| } | ||
| ) | ||
| ); | ||
|
|
||
| # Script to ensure user is in docker group and system docker is running | ||
| setupDockerScript = pkgs.writeShellScript "setup-docker" '' | ||
| set -euo pipefail | ||
|
|
||
| # Define paths | ||
| GROUPS=${pkgs.shadow}/bin/groups | ||
| GREP=${pkgs.gnugrep}/bin/grep | ||
| USERMOD=${pkgs.shadow}/bin/usermod | ||
| SYSTEMCTL=${pkgs.systemd}/bin/systemctl | ||
| TEE=${pkgs.coreutils}/bin/tee | ||
| DOCKER_SERVICE_FILE=${dockerServiceFile} | ||
|
|
||
| # Check if docker group exists and user is in it | ||
| if ! $GROUPS | $GREP -q docker; then | ||
| echo "Adding user to docker group..." | ||
| sudo $USERMOD -aG docker $USER | ||
| 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 | ||
| 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..." | ||
| 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" | ||
| else | ||
| echo "✅ Docker daemon is already running" | ||
| fi | ||
| ''; | ||
| setupDockerScript = pkgs.writeShellScript "setup-docker" ( | ||
| builtins.readFile ( | ||
| pkgs.replaceVars ./setup-docker.sh { | ||
| shadow = pkgs.shadow; | ||
| gnugrep = pkgs.gnugrep; | ||
| systemd = pkgs.systemd; | ||
| coreutils = pkgs.coreutils; | ||
| docker_service_file = dockerServiceFile; | ||
| } | ||
| ) | ||
| ); | ||
| in | ||
| { | ||
| # Provide setup script for system Docker | ||
| home.packages = lib.mkIf pkgs.stdenv.isLinux [ | ||
| (pkgs.writeShellScriptBin "docker-setup" '' | ||
| exec ${setupDockerScript} | ||
| '') | ||
| (pkgs.writeShellScriptBin "docker-setup" ( | ||
| builtins.readFile ( | ||
| pkgs.replaceVars ./docker-setup.sh { | ||
| setup_docker_script = setupDockerScript; | ||
| } | ||
| ) | ||
| )) | ||
| ]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/usr/bin/env bash | ||
| # Thin wrapper exposing setup-docker as a user-facing command. | ||
| # @setup_docker_script@ is substituted by pkgs.replaceVars. | ||
| exec @setup_docker_script@ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| [Unit] | ||
| Description=Docker Application Container Engine | ||
| Documentation=https://docs.docker.com | ||
| After=network-online.target | ||
| Wants=network-online.target | ||
|
|
||
| [Service] | ||
| Type=notify | ||
| ExecStart=@docker@/bin/dockerd | ||
| ExecReload=@coreutils@/bin/kill -s HUP $MAINPID | ||
| Restart=always | ||
| RestartSec=10s | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using
python-version-file: pyproject.tomlwithactions/setup-python@v6as intended. This is supported — v6 readsrequires-pythonfrom pyproject.toml.