From 43db4ed61b733ca8277cc4e7e882ef43d31064fa Mon Sep 17 00:00:00 2001 From: Defelo Date: Thu, 3 Jul 2025 17:58:34 +0200 Subject: [PATCH] feat: reclaim additional space Use nothing-but-nix on linux and `rm -rf` on darwin Move nix's build-dir into /nix to workaround https://github.com/wimpysworld/nothing-but-nix/issues/18 Co-authored-by: Matt Sturgeon --- .github/actions/setup-nix/action.yml | 67 ++++++++++++++++++++++++++++ .github/workflows/build.yml | 27 ++++++----- .github/workflows/review.yml | 29 ++++++------ 3 files changed, 95 insertions(+), 28 deletions(-) create mode 100644 .github/actions/setup-nix/action.yml diff --git a/.github/actions/setup-nix/action.yml b/.github/actions/setup-nix/action.yml new file mode 100644 index 0000000..4ed924e --- /dev/null +++ b/.github/actions/setup-nix/action.yml @@ -0,0 +1,67 @@ +name: setup-nix + +inputs: + system: + type: string + required: true + sandbox: + type: string + default: "true" + +runs: + using: composite + steps: + - name: reclaim space (linux) + if: runner.os == 'Linux' + uses: wimpysworld/nothing-but-nix@main + with: + hatchet-protocol: rampage + + - name: reclaim space (darwin) + if: runner.os == 'macOS' + shell: bash + run: | + echo "::group::disk space (before)" + sudo df -h + echo "::endgroup::" + + echo "::group::disable mds" + sudo mdutil -i off -a || echo "mdutil failed" + sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist \ + || echo "launchctl unload failed" + echo "::endgroup::" + + echo "Background space expansion started. /nix will grow as space becomes available." + sudo rm -rf \ + /Applications/Xcode_* \ + /Library/Developer/CoreSimulator \ + /Library/Frameworks \ + /Users/runner/.dotnet \ + /Users/runner/.rustup \ + /Users/runner/Library/Android \ + /Users/runner/Library/Caches \ + /Users/runner/Library/Developer/CoreSimulator \ + /Users/runner/hostedtoolcache & + + - name: install nix + uses: cachix/install-nix-action@v31 + with: + # Putting build-dir in /nix is a workaround for https://github.com/wimpysworld/nothing-but-nix/issues/18 + extra_nix_config: | + build-dir = /nix/build + sandbox = ${{ inputs.sandbox }} + system = ${{ inputs.system }} + + - name: create build-dir + shell: bash + run: sudo mkdir -p /nix/build + + - name: post setup-nix + if: runner.os == 'macOS' + uses: srz-zumix/post-run-action@v2 + with: + shell: bash -e {0} + post-run: | + echo "::group::disk space (after)" + sudo df -h + echo "::endgroup::" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 79efec0..e38b140 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -68,21 +68,20 @@ jobs: || (matrix.system == 'aarch64-darwin' && 'macos-latest') }} steps: - - name: prepare /nix - run: sudo mkdir /mnt/nix && sudo mount -m -o bind /mnt/nix /nix - if: ${{ matrix.system == 'x86_64-linux' || matrix.system == 'aarch64-linux' }} - - - name: install nix - uses: cachix/install-nix-action@v31 + - uses: actions/checkout@v4 with: - extra_nix_config: | - system = ${{ matrix.system }} - sandbox = ${{ - (matrix.system == 'x86_64-darwin' && inputs.x86_64-darwin == 'yes_sandbox_false' - || matrix.system == 'aarch64-darwin' && inputs.aarch64-darwin == 'yes_sandbox_false') && 'false' - || (matrix.system == 'x86_64-darwin' && inputs.x86_64-darwin == 'yes_sandbox_relaxed' - || matrix.system == 'aarch64-darwin' && inputs.aarch64-darwin == 'yes_sandbox_relaxed') && 'relaxed' - || 'true' }} + sparse-checkout: .github/actions + + - name: setup nix + uses: ./.github/actions/setup-nix + with: + system: ${{ matrix.system }} + sandbox: ${{ + (matrix.system == 'x86_64-darwin' && inputs.x86_64-darwin == 'yes_sandbox_false' + || matrix.system == 'aarch64-darwin' && inputs.aarch64-darwin == 'yes_sandbox_false') && 'false' + || (matrix.system == 'x86_64-darwin' && inputs.x86_64-darwin == 'yes_sandbox_relaxed' + || matrix.system == 'aarch64-darwin' && inputs.aarch64-darwin == 'yes_sandbox_relaxed') && 'relaxed' + || 'true' }} - name: nix build run: nix build --keep-going -L ${{ inputs.packages }} diff --git a/.github/workflows/review.yml b/.github/workflows/review.yml index 787b725..ea12f1f 100644 --- a/.github/workflows/review.yml +++ b/.github/workflows/review.yml @@ -99,22 +99,21 @@ jobs: fetch_cmd_aarch64-darwin: ${{ steps.report.outputs.fetch_cmd_aarch64-darwin }} steps: - - name: prepare /nix - run: sudo mkdir /mnt/nix && sudo mount -m -o bind /mnt/nix /nix - if: ${{ matrix.system == 'x86_64-linux' || matrix.system == 'aarch64-linux' }} - - - name: install nix - uses: cachix/install-nix-action@v31 + - uses: actions/checkout@v4 with: - extra_nix_config: | - system = ${{ matrix.system }} - sandbox = ${{ - (matrix.system == 'x86_64-darwin' && inputs.x86_64-darwin == 'yes_sandbox_false' - || matrix.system == 'aarch64-darwin' && inputs.aarch64-darwin == 'yes_sandbox_false') && 'false' - || (matrix.system == 'x86_64-darwin' && inputs.x86_64-darwin == 'yes_sandbox_relaxed' - || matrix.system == 'aarch64-darwin' && inputs.aarch64-darwin == 'yes_sandbox_relaxed') && 'relaxed' - || 'true' }} + sparse-checkout: .github/actions + - name: setup nix + uses: ./.github/actions/setup-nix + with: + system: ${{ matrix.system }} + sandbox: ${{ + (matrix.system == 'x86_64-darwin' && inputs.x86_64-darwin == 'yes_sandbox_false' + || matrix.system == 'aarch64-darwin' && inputs.aarch64-darwin == 'yes_sandbox_false') && 'false' + || (matrix.system == 'x86_64-darwin' && inputs.x86_64-darwin == 'yes_sandbox_relaxed' + || matrix.system == 'aarch64-darwin' && inputs.aarch64-darwin == 'yes_sandbox_relaxed') && 'relaxed' + || 'true' }} + - name: install packages run: | pkgs=(coreutils nixpkgs-review jq gnused) @@ -131,6 +130,7 @@ jobs: uses: actions/checkout@v4 with: repository: NixOS/nixpkgs + path: nixpkgs persist-credentials: false - name: run nixpkgs-review ${{ inputs.extra-args }} @@ -143,6 +143,7 @@ jobs: --build-args="-L" \ $EXTRA_ARGS \ || true + working-directory: nixpkgs env: GITHUB_TOKEN: ${{ github.token }} EXTRA_ARGS: ${{ inputs.extra-args }}