From d677f3a33279b5f9d961d994b2f6f47b63e80635 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Fri, 17 May 2024 16:52:30 -0300 Subject: [PATCH 01/22] Add integration test workflow --- .editorconfig | 10 ++++++++++ .github/workflows/test.yaml | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/workflows/test.yaml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a56f2d2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +# https://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..dc13483 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,36 @@ +name: Integration tests + +on: + pull_request: + push: + branches: [main] + +jobs: + checks: + runs-on: ubuntu-22.04 + permissions: + contents: read + id-token: write + env: + FLAKEHUB_API_ENDPOINT: "api.flakehub.com" + FLAKEHUB_WEB_ENDPOINT: "https://flakehub.com" + steps: + - uses: actions/checkout@v3 + + - name: Get JWT + id: jwt + run: | + REQUEST_TOKEN="${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" + ROOT_URL="${ACTIONS_ID_TOKEN_REQUEST_URL}" + JWT_ID_TOKEN=$(curl \ + --header "authorization: bearer ${REQUEST_TOKEN}" \ + --header "accept: application/json;api-version=2.0" \ + --header "content-type: application/json" \ + --header "user-agent: magic-nix-cache" \ + "${ROOT_URL}&audience=${{ env.FLAKEHUB_API_ENDPOINT }}") + + echo "::set-output name=token::${JWT_ID_TOKEN}" + + - name: Display token + run: | + echo "${{ steps.jwt.outputs.token }}" From 986b5798dd43f5e27264416e157673187f101035 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Fri, 17 May 2024 16:59:39 -0300 Subject: [PATCH 02/22] More setup steps --- .github/workflows/test.yaml | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index dc13483..3f7b30d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,14 +12,19 @@ jobs: contents: read id-token: write env: - FLAKEHUB_API_ENDPOINT: "api.flakehub.com" - FLAKEHUB_WEB_ENDPOINT: "https://flakehub.com" + FLAKEHUB_API_ENDPOINT: api.flakehub.com + FLAKEHUB_WEB_ENDPOINT: https://flakehub.com + NIX_CONF: /etc/nix/nix.conf + FLAKEHUB_CACHE: "https://cache.flakehub.com" steps: - uses: actions/checkout@v3 - - name: Get JWT - id: jwt + - name: Setup + id: setup run: | + TMP=$(mktemp -d) + NETRC="${TMP}/netrc" + REQUEST_TOKEN="${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" ROOT_URL="${ACTIONS_ID_TOKEN_REQUEST_URL}" JWT_ID_TOKEN=$(curl \ @@ -30,7 +35,23 @@ jobs: "${ROOT_URL}&audience=${{ env.FLAKEHUB_API_ENDPOINT }}") echo "::set-output name=token::${JWT_ID_TOKEN}" + echo "::set-output name=netrc::${NETRC}" - - name: Display token + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + + - name: Set up netrc file + env: + NETRC: ${{ steps.setup.outputs.netrc }} + TOKEN: ${{ steps.setup.outputs.token }} run: | - echo "${{ steps.jwt.outputs.token }}" + echo "machine ${{ env.FLAKEHUB_WEB_ENDPOINT }} login flakehub password ${{ env.TOKEN }}" > "${{ env.NETRC }}" + echo "machine ${{ env.FLAKEHUB_API_ENDPOINT }} login flakehub password ${{ env.TOKEN }}" >> "${{ env.NETRC }}" + echo "extra-substituters = ${{ env.FLAKEHUB_CACHE }}/?trusted=1" >> "${{ env.NIX_CONF }}" + echo "netrc-file = ${{ env.NETRC }}" >> "${{ env.NIX_CONF }}" + + echo "netrc file:" + cat "${{ env.NETRC }}" + + echo "Nix config:" + cat "${{ env.NIX_CONF }}" From bb7e2fbfa37c1a5bdf6fba87d8365a41d00f7656 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Fri, 17 May 2024 17:01:32 -0300 Subject: [PATCH 03/22] Make nix.conf writable --- .github/workflows/test.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3f7b30d..5c4f965 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -19,12 +19,17 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + - name: Setup id: setup run: | TMP=$(mktemp -d) NETRC="${TMP}/netrc" + sudo chmod a+rw "${{ env.NIX_CONF }}" + REQUEST_TOKEN="${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" ROOT_URL="${ACTIONS_ID_TOKEN_REQUEST_URL}" JWT_ID_TOKEN=$(curl \ @@ -37,9 +42,6 @@ jobs: echo "::set-output name=token::${JWT_ID_TOKEN}" echo "::set-output name=netrc::${NETRC}" - - name: Install Nix - uses: DeterminateSystems/nix-installer-action@main - - name: Set up netrc file env: NETRC: ${{ steps.setup.outputs.netrc }} From 7fc2455f30d4e46eec1c0f5db4b9a0449fcd97a2 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Fri, 17 May 2024 17:03:09 -0300 Subject: [PATCH 04/22] Use GITHUB_STATE mechanism for state --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5c4f965..90bbaf7 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -39,8 +39,8 @@ jobs: --header "user-agent: magic-nix-cache" \ "${ROOT_URL}&audience=${{ env.FLAKEHUB_API_ENDPOINT }}") - echo "::set-output name=token::${JWT_ID_TOKEN}" - echo "::set-output name=netrc::${NETRC}" + echo "token=${JWT_ID_TOKEN}" >> $GITHUB_STATE + echo "netrc=${NETRC}" >> $GITHUB_STATE - name: Set up netrc file env: From 7474dbd6273db6c530624cdedb2931cfb23b6465 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Fri, 17 May 2024 17:04:12 -0300 Subject: [PATCH 05/22] Use GITHUB_OUTPUT instead of GITHUB_STATE --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 90bbaf7..5eb0bb0 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -39,8 +39,8 @@ jobs: --header "user-agent: magic-nix-cache" \ "${ROOT_URL}&audience=${{ env.FLAKEHUB_API_ENDPOINT }}") - echo "token=${JWT_ID_TOKEN}" >> $GITHUB_STATE - echo "netrc=${NETRC}" >> $GITHUB_STATE + echo "token=${JWT_ID_TOKEN}" >> $GITHUB_OUTPUT + echo "netrc=${NETRC}" >> $GITHUB_OUTPUT - name: Set up netrc file env: From 5b98d04c9e127376d37385ce345531c909404545 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Fri, 17 May 2024 17:14:03 -0300 Subject: [PATCH 06/22] Test build of mnc using source-binary --- .github/workflows/test.yaml | 61 +++++++++++++++---------------------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5eb0bb0..e4a3ec2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -6,54 +6,41 @@ on: branches: [main] jobs: - checks: + build-linux: runs-on: ubuntu-22.04 permissions: contents: read id-token: write - env: - FLAKEHUB_API_ENDPOINT: api.flakehub.com - FLAKEHUB_WEB_ENDPOINT: https://flakehub.com - NIX_CONF: /etc/nix/nix.conf - FLAKEHUB_CACHE: "https://cache.flakehub.com" steps: - uses: actions/checkout@v3 - name: Install Nix uses: DeterminateSystems/nix-installer-action@main - - name: Setup - id: setup - run: | - TMP=$(mktemp -d) - NETRC="${TMP}/netrc" + - uses: DeterminateSystems/magic-nix-cache-action@main - sudo chmod a+rw "${{ env.NIX_CONF }}" + - name: Build package + run: "nix build .# -L --fallback && nix-store --export $(nix-store -qR ./result) | xz -9 > magic-nix-cache.closure.xz" - REQUEST_TOKEN="${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" - ROOT_URL="${ACTIONS_ID_TOKEN_REQUEST_URL}" - JWT_ID_TOKEN=$(curl \ - --header "authorization: bearer ${REQUEST_TOKEN}" \ - --header "accept: application/json;api-version=2.0" \ - --header "content-type: application/json" \ - --header "user-agent: magic-nix-cache" \ - "${ROOT_URL}&audience=${{ env.FLAKEHUB_API_ENDPOINT }}") + - name: Cache magix-nix-cache closure + uses: actions/cache/save@v4 + with: + path: magic-nix-cache.closure.xz + key: magic-nix-cache-${{ github.sha }} - echo "token=${JWT_ID_TOKEN}" >> $GITHUB_OUTPUT - echo "netrc=${NETRC}" >> $GITHUB_OUTPUT + test-linux: + runs-on: ubuntu-22.04 + permissions: + contents: read + id-token: write + steps: + - name: Restore magix-nix-cache closure + uses: actions/cache/restore@v4 + with: + path: magic-nix-cache.closure.xz + key: magic-nix-cache-${{ github.sha }} + fail-on-cache-miss: true - - name: Set up netrc file - env: - NETRC: ${{ steps.setup.outputs.netrc }} - TOKEN: ${{ steps.setup.outputs.token }} - run: | - echo "machine ${{ env.FLAKEHUB_WEB_ENDPOINT }} login flakehub password ${{ env.TOKEN }}" > "${{ env.NETRC }}" - echo "machine ${{ env.FLAKEHUB_API_ENDPOINT }} login flakehub password ${{ env.TOKEN }}" >> "${{ env.NETRC }}" - echo "extra-substituters = ${{ env.FLAKEHUB_CACHE }}/?trusted=1" >> "${{ env.NIX_CONF }}" - echo "netrc-file = ${{ env.NETRC }}" >> "${{ env.NIX_CONF }}" - - echo "netrc file:" - cat "${{ env.NETRC }}" - - echo "Nix config:" - cat "${{ env.NIX_CONF }}" + - uses: DeterminateSystems/magic-nix-cache-action@main + with: + source-binary: "magic-nix-cache.closure.xz" From 1407ae42a2015f3fd93fab849b012987c5c07d7d Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Fri, 17 May 2024 17:14:50 -0300 Subject: [PATCH 07/22] Make sure build job runs first --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e4a3ec2..8118d2e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -29,6 +29,7 @@ jobs: key: magic-nix-cache-${{ github.sha }} test-linux: + needs: build-linux runs-on: ubuntu-22.04 permissions: contents: read From 6f4ce1d570775fd0add0d15f51b626af55c52a56 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Fri, 17 May 2024 17:17:18 -0300 Subject: [PATCH 08/22] Install Nix prior to test --- .github/workflows/test.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8118d2e..f069c84 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -28,7 +28,7 @@ jobs: path: magic-nix-cache.closure.xz key: magic-nix-cache-${{ github.sha }} - test-linux: + test-magic-nix-cache-action: needs: build-linux runs-on: ubuntu-22.04 permissions: @@ -42,6 +42,9 @@ jobs: key: magic-nix-cache-${{ github.sha }} fail-on-cache-miss: true + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main with: source-binary: "magic-nix-cache.closure.xz" From e85ce917714faa43348294bf88ff7ef6d4d3f154 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Fri, 17 May 2024 17:28:37 -0300 Subject: [PATCH 09/22] Extract closure in prior step --- .github/workflows/test.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f069c84..777caca 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -45,6 +45,15 @@ jobs: - name: Install Nix uses: DeterminateSystems/nix-installer-action@main + - name: Extract + id: extract + run: | + OUTPUT=$(cat magic-nix-cache.closure.xz | xz -d | nix-store --import) + MNC_BIN_PATH=$(echo "${OUTPUT}" | tail -n 1) + MAGIC_NIX_CACHE="${MNC_BIN_PATH}/bin/magic-nix-cache" + + echo "mnc-path=${MAGIC_NIX_CACHE}" >> "$GITHUB_OUTPUT" + - uses: DeterminateSystems/magic-nix-cache-action@main with: - source-binary: "magic-nix-cache.closure.xz" + source-binary: "${{ steps.extract.outputs.mnc-path }}" From cce0d218c81c6c9d67b4c604b54174b4ded35ade Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Fri, 17 May 2024 17:36:46 -0300 Subject: [PATCH 10/22] Use matrix strategy --- .github/workflows/test.yaml | 42 ++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 777caca..4dd7d63 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -6,11 +6,21 @@ on: branches: [main] jobs: - build-linux: - runs-on: ubuntu-22.04 + build-closure: + strategy: + matrix: + runner: + - ubuntu-22.04 + - namespace-profile-default-arm64 + - macos-12 + - macos-latest-xlarge + runs-on: ${{ matrix.runner }} permissions: contents: read id-token: write + env: + CLOSURE_FILE: magic-nix-cache.${{ matrix.runner }}.closure.xz + CLOSURE_KEY: magic-nix-cache-${{ matrix.runner }}-${{ github.sha }} steps: - uses: actions/checkout@v3 @@ -20,26 +30,38 @@ jobs: - uses: DeterminateSystems/magic-nix-cache-action@main - name: Build package - run: "nix build .# -L --fallback && nix-store --export $(nix-store -qR ./result) | xz -9 > magic-nix-cache.closure.xz" + run: | + nix build .# -L --fallback && \ + nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.CLOSURE_FILE }}" - name: Cache magix-nix-cache closure uses: actions/cache/save@v4 with: - path: magic-nix-cache.closure.xz - key: magic-nix-cache-${{ github.sha }} + path: ${{ env.CLOSURE_FILE }} + key: ${{ env.CLOSURE_KEY }} test-magic-nix-cache-action: - needs: build-linux - runs-on: ubuntu-22.04 + needs: build-closure + strategy: + matrix: + runner: + - ubuntu-22.04 + - namespace-profile-default-arm64 + - macos-12 + - macos-latest-xlarge + runs-on: ${{ matrix.runner }} permissions: contents: read id-token: write + env: + CLOSURE_FILE: magic-nix-cache.${{ matrix.runner }}.closure.xz + CLOSURE_KEY: magic-nix-cache-${{ matrix.runner }}-${{ github.sha }} steps: - name: Restore magix-nix-cache closure uses: actions/cache/restore@v4 with: - path: magic-nix-cache.closure.xz - key: magic-nix-cache-${{ github.sha }} + path: ${{ env.CLOSURE_FILE }} + key: ${{ env.CLOSURE_KEY }} fail-on-cache-miss: true - name: Install Nix @@ -48,7 +70,7 @@ jobs: - name: Extract id: extract run: | - OUTPUT=$(cat magic-nix-cache.closure.xz | xz -d | nix-store --import) + OUTPUT=$(cat ${{ env.CLOSURE_FILE }} | xz -d | nix-store --import) MNC_BIN_PATH=$(echo "${OUTPUT}" | tail -n 1) MAGIC_NIX_CACHE="${MNC_BIN_PATH}/bin/magic-nix-cache" From 01e147381bca8193d3155600edd41a3279372fed Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Sat, 18 May 2024 16:21:53 -0300 Subject: [PATCH 11/22] Streamline build logic --- .github/workflows/build.yaml | 11 ++++- .github/workflows/checks.yaml | 4 -- .github/workflows/flakehub-cache.yml | 32 ------------- .github/workflows/test.yaml | 70 ++++++++-------------------- 4 files changed, 28 insertions(+), 89 deletions(-) delete mode 100644 .github/workflows/flakehub-cache.yml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0cffe12..a917b3b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -7,6 +7,9 @@ on: jobs: build-artifacts: runs-on: ${{ matrix.systems.runner }} + env: + CLOSURE_FILE: magic-nix-cache.closure.xz + CLOSURE_KEY: magic-nix-cache-${{ matrix.systems.runner }}-${{ github.sha }} strategy: matrix: systems: @@ -30,12 +33,16 @@ jobs: - uses: DeterminateSystems/nix-installer-action@main - uses: DeterminateSystems/magic-nix-cache-action@main - name: Build package - run: "nix build .# -L --fallback && nix-store --export $(nix-store -qR ./result) | xz -9 > magic-nix-cache.closure.xz" + run: | + # Cache dev shell + nix build .#devShells.${{ matrix.systems.nix-system }} + + nix build .# -L --fallback && nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.CLOSURE_FILE }}" - name: Upload a Build Artifact uses: actions/upload-artifact@v3.1.2 with: # Artifact name name: magic-nix-cache-${{ matrix.systems.system }} - path: magic-nix-cache.closure.xz + path: ${{ env.CLOSURE_FILE }} retention-days: 1 diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index a2295da..89acd01 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -28,7 +28,3 @@ jobs: - name: Clippy run: nix develop --command cargo clippy - - build: - uses: ./.github/workflows/build.yaml - secrets: inherit diff --git a/.github/workflows/flakehub-cache.yml b/.github/workflows/flakehub-cache.yml deleted file mode 100644 index c7969de..0000000 --- a/.github/workflows/flakehub-cache.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Push dev shell to FlakeHub Cache - -on: - push: - branches: [main] - -jobs: - push-dev-shell-to-flakehub-cache: - env: - ACTIONS_STEP_DEBUG: true - runs-on: ${{ matrix.systems.runner }} - permissions: - id-token: "write" - contents: "read" - strategy: - matrix: - systems: - - nix-system: "aarch64-darwin" - runner: "macos-latest-xlarge" - - nix-system: "x86_64-darwin" - runner: "macos-12" - - nix-system: "x86_64-linux" - runner: "ubuntu-22.04" - steps: - - uses: actions/checkout@v3 - - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main - with: - use-flakehub: true - - name: Build dev shell for ${{ matrix.systems.nix-system }} on ${{ matrix.systems.runner }} - run: | - nix build .#devShells.${{ matrix.systems.nix-system }}.default diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4dd7d63..aa8887f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,68 +1,36 @@ name: Integration tests on: - pull_request: - push: - branches: [main] + workflow_run: + workflows: ["Build artifacts"] + types: + - completed jobs: - build-closure: - strategy: - matrix: - runner: - - ubuntu-22.04 - - namespace-profile-default-arm64 - - macos-12 - - macos-latest-xlarge - runs-on: ${{ matrix.runner }} - permissions: - contents: read - id-token: write - env: - CLOSURE_FILE: magic-nix-cache.${{ matrix.runner }}.closure.xz - CLOSURE_KEY: magic-nix-cache-${{ matrix.runner }}-${{ github.sha }} - steps: - - uses: actions/checkout@v3 - - - name: Install Nix - uses: DeterminateSystems/nix-installer-action@main - - - uses: DeterminateSystems/magic-nix-cache-action@main - - - name: Build package - run: | - nix build .# -L --fallback && \ - nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.CLOSURE_FILE }}" - - - name: Cache magix-nix-cache closure - uses: actions/cache/save@v4 - with: - path: ${{ env.CLOSURE_FILE }} - key: ${{ env.CLOSURE_KEY }} - test-magic-nix-cache-action: - needs: build-closure + runs-on: ${{ matrix.systems.runner }} + env: + CLOSURE_FILE: magic-nix-cache-${{ matrix.systems.system }} strategy: matrix: - runner: - - ubuntu-22.04 - - namespace-profile-default-arm64 - - macos-12 - - macos-latest-xlarge - runs-on: ${{ matrix.runner }} + systems: + - system: X64-Linux + runner: ubuntu-22.04 + - system: ARM64-Linux + runner: namespace-profile-default-arm64 + - system: X64-macOS + runner: macos-12 + - system: ARM64-macOS + runner: macos-latest-xlarge permissions: contents: read id-token: write - env: - CLOSURE_FILE: magic-nix-cache.${{ matrix.runner }}.closure.xz - CLOSURE_KEY: magic-nix-cache-${{ matrix.runner }}-${{ github.sha }} steps: - - name: Restore magix-nix-cache closure - uses: actions/cache/restore@v4 + - name: Download artifact + uses: actions/download-artifact@v3 with: + name: ${{ env.CLOSURE_FILE }} path: ${{ env.CLOSURE_FILE }} - key: ${{ env.CLOSURE_KEY }} - fail-on-cache-miss: true - name: Install Nix uses: DeterminateSystems/nix-installer-action@main From 867cfad681b81fa9fa3e25762520e9e45308fa43 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Sat, 18 May 2024 16:23:35 -0300 Subject: [PATCH 12/22] Fix broken dev shell build --- .github/workflows/build.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a917b3b..24bcf75 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -32,11 +32,13 @@ jobs: - uses: actions/checkout@v3 - uses: DeterminateSystems/nix-installer-action@main - uses: DeterminateSystems/magic-nix-cache-action@main - - name: Build package - run: | - # Cache dev shell - nix build .#devShells.${{ matrix.systems.nix-system }} + - name: Build and cache dev shell + run: | + nix build ".#devShells.${{ matrix.systems.nix-system }}.default" + + - name: Build package and create closure + run: | nix build .# -L --fallback && nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.CLOSURE_FILE }}" - name: Upload a Build Artifact From 6eaa23c96328d580ad0415ffe39f3cdc1cc27c76 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Sat, 18 May 2024 16:41:44 -0300 Subject: [PATCH 13/22] Rework integration test --- .github/workflows/build.yaml | 3 +- .../{test.yaml => check-and-test.yaml} | 38 ++++++++++++++++--- .github/workflows/checks.yaml | 30 --------------- 3 files changed, 35 insertions(+), 36 deletions(-) rename .github/workflows/{test.yaml => check-and-test.yaml} (61%) delete mode 100644 .github/workflows/checks.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 24bcf75..98ba772 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -39,7 +39,8 @@ jobs: - name: Build package and create closure run: | - nix build .# -L --fallback && nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.CLOSURE_FILE }}" + nix build .# -L --fallback && \ + nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.CLOSURE_FILE }}" - name: Upload a Build Artifact uses: actions/upload-artifact@v3.1.2 diff --git a/.github/workflows/test.yaml b/.github/workflows/check-and-test.yaml similarity index 61% rename from .github/workflows/test.yaml rename to .github/workflows/check-and-test.yaml index aa8887f..133ac0c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/check-and-test.yaml @@ -1,14 +1,42 @@ -name: Integration tests +name: Run checks and integration test on: - workflow_run: - workflows: ["Build artifacts"] - types: - - completed + pull_request: + push: + branches: [main] jobs: + checks: + runs-on: ubuntu-22.04 + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v3 + + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + + - name: Check health of flake.lock + uses: DeterminateSystems/flake-checker-action@main + with: + fail-mode: true + + - name: Check Rust formatting + run: nix develop --command cargo fmt --check + + - name: Clippy + run: nix develop --command cargo clippy + + build: + needs: checks + uses: ./.github/workflows/build.yaml + secrets: inherit + test-magic-nix-cache-action: runs-on: ${{ matrix.systems.runner }} + needs: build env: CLOSURE_FILE: magic-nix-cache-${{ matrix.systems.system }} strategy: diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml deleted file mode 100644 index 89acd01..0000000 --- a/.github/workflows/checks.yaml +++ /dev/null @@ -1,30 +0,0 @@ -name: Rust checks - -on: - pull_request: - push: - branches: [main] - -jobs: - checks: - runs-on: ubuntu-22.04 - permissions: - contents: read - id-token: write - steps: - - uses: actions/checkout@v3 - - - name: Install Nix - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main - - - name: Check health of flake.lock - uses: DeterminateSystems/flake-checker-action@main - with: - fail-mode: true - - - name: Check Rust formatting - run: nix develop --command cargo fmt --check - - - name: Clippy - run: nix develop --command cargo clippy From e02976750d8ce46a95ffd7e9a3d61ea67f0ac5a0 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Sat, 18 May 2024 16:47:37 -0300 Subject: [PATCH 14/22] Remove unused env var --- .github/workflows/build.yaml | 1 - .github/workflows/check-and-test.yaml | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 98ba772..4d1870c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -9,7 +9,6 @@ jobs: runs-on: ${{ matrix.systems.runner }} env: CLOSURE_FILE: magic-nix-cache.closure.xz - CLOSURE_KEY: magic-nix-cache-${{ matrix.systems.runner }}-${{ github.sha }} strategy: matrix: systems: diff --git a/.github/workflows/check-and-test.yaml b/.github/workflows/check-and-test.yaml index 133ac0c..516d826 100644 --- a/.github/workflows/check-and-test.yaml +++ b/.github/workflows/check-and-test.yaml @@ -7,6 +7,7 @@ on: jobs: checks: + name: Nix and Rust checks runs-on: ubuntu-22.04 permissions: contents: read @@ -30,11 +31,13 @@ jobs: run: nix develop --command cargo clippy build: + name: Build artifacts needs: checks uses: ./.github/workflows/build.yaml secrets: inherit - test-magic-nix-cache-action: + action-integration-test: + name: Integration test for magic-nix-cache-action runs-on: ${{ matrix.systems.runner }} needs: build env: From 3708b7cec62f1765a3437eed06ca98f5f30fb22b Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Sat, 18 May 2024 16:52:47 -0300 Subject: [PATCH 15/22] Fix download artifact declaration --- .github/workflows/build.yaml | 9 +++++---- .github/workflows/check-and-test.yaml | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 4d1870c..c5be325 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -8,7 +8,8 @@ jobs: build-artifacts: runs-on: ${{ matrix.systems.runner }} env: - CLOSURE_FILE: magic-nix-cache.closure.xz + CLOSURE_NAME: magic-nix-cache-${{ matrix.systems.system }} + CLOSURE_PATH: magic-nix-cache.closure.xz strategy: matrix: systems: @@ -39,12 +40,12 @@ jobs: - name: Build package and create closure run: | nix build .# -L --fallback && \ - nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.CLOSURE_FILE }}" + nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.CLOSURE_PATH }}" - name: Upload a Build Artifact uses: actions/upload-artifact@v3.1.2 with: # Artifact name - name: magic-nix-cache-${{ matrix.systems.system }} - path: ${{ env.CLOSURE_FILE }} + name: ${{ env.CLOSURE_NAME }} + path: ${{ env.CLOSURE_PATH }} retention-days: 1 diff --git a/.github/workflows/check-and-test.yaml b/.github/workflows/check-and-test.yaml index 516d826..c08c8c5 100644 --- a/.github/workflows/check-and-test.yaml +++ b/.github/workflows/check-and-test.yaml @@ -41,7 +41,8 @@ jobs: runs-on: ${{ matrix.systems.runner }} needs: build env: - CLOSURE_FILE: magic-nix-cache-${{ matrix.systems.system }} + CLOSURE_NAME: magic-nix-cache-${{ matrix.systems.system }} + CLOSURE_PATH: magic-nix-cache.closure.xz strategy: matrix: systems: @@ -60,8 +61,8 @@ jobs: - name: Download artifact uses: actions/download-artifact@v3 with: - name: ${{ env.CLOSURE_FILE }} - path: ${{ env.CLOSURE_FILE }} + name: ${{ env.CLOSURE_NAME }} + path: ${{ env.CLOSURE_PATH }} - name: Install Nix uses: DeterminateSystems/nix-installer-action@main @@ -69,7 +70,7 @@ jobs: - name: Extract id: extract run: | - OUTPUT=$(cat ${{ env.CLOSURE_FILE }} | xz -d | nix-store --import) + OUTPUT=$(cat ${{ env.CLOSURE_PATH }} | xz -d | nix-store --import) MNC_BIN_PATH=$(echo "${OUTPUT}" | tail -n 1) MAGIC_NIX_CACHE="${MNC_BIN_PATH}/bin/magic-nix-cache" From 03d4aa5f666ae527ea6f7b93f55aaaa07b72192f Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Sat, 18 May 2024 17:07:04 -0300 Subject: [PATCH 16/22] Fix naming issue --- .github/workflows/build.yaml | 6 +++--- .github/workflows/check-and-test.yaml | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c5be325..3f3b885 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ${{ matrix.systems.runner }} env: CLOSURE_NAME: magic-nix-cache-${{ matrix.systems.system }} - CLOSURE_PATH: magic-nix-cache.closure.xz + ARCHIVE: magic-nix-cache.closure.xz strategy: matrix: systems: @@ -40,12 +40,12 @@ jobs: - name: Build package and create closure run: | nix build .# -L --fallback && \ - nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.CLOSURE_PATH }}" + nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.ARCHIVE }}" - name: Upload a Build Artifact uses: actions/upload-artifact@v3.1.2 with: # Artifact name name: ${{ env.CLOSURE_NAME }} - path: ${{ env.CLOSURE_PATH }} + path: ${{ env.ARCHIVE }} retention-days: 1 diff --git a/.github/workflows/check-and-test.yaml b/.github/workflows/check-and-test.yaml index c08c8c5..3a5bb6f 100644 --- a/.github/workflows/check-and-test.yaml +++ b/.github/workflows/check-and-test.yaml @@ -42,7 +42,8 @@ jobs: needs: build env: CLOSURE_NAME: magic-nix-cache-${{ matrix.systems.system }} - CLOSURE_PATH: magic-nix-cache.closure.xz + CLOSURE_PATH: magic-nix-cache + ARCHIVE: magic-nix-cache.closure.xz strategy: matrix: systems: @@ -70,7 +71,8 @@ jobs: - name: Extract id: extract run: | - OUTPUT=$(cat ${{ env.CLOSURE_PATH }} | xz -d | nix-store --import) + ARTIFACT="${{ env.CLOSURE_PATH }}/${{ env.ARCHIVE }}" + OUTPUT=$(cat ${ARTIFACT} | xz -d | nix-store --import) MNC_BIN_PATH=$(echo "${OUTPUT}" | tail -n 1) MAGIC_NIX_CACHE="${MNC_BIN_PATH}/bin/magic-nix-cache" From 66317827ea6ad51df347e6c5f3da4579c0acdc35 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Sat, 18 May 2024 17:21:03 -0300 Subject: [PATCH 17/22] Some final cleanup --- .github/workflows/build.yaml | 28 ++++++++++++++------------- .github/workflows/check-and-test.yaml | 20 +++++++++---------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3f3b885..32403b5 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -7,9 +7,12 @@ on: jobs: build-artifacts: runs-on: ${{ matrix.systems.runner }} + permissions: + contents: read + id-token: write env: - CLOSURE_NAME: magic-nix-cache-${{ matrix.systems.system }} - ARCHIVE: magic-nix-cache.closure.xz + ARTIFACT_KEY: magic-nix-cache-${{ matrix.systems.system }} + ARCHIVE_NAME: magic-nix-cache.closure.xz strategy: matrix: systems: @@ -25,27 +28,26 @@ jobs: - nix-system: aarch64-darwin system: ARM64-macOS runner: macos-latest-xlarge - permissions: - contents: read - id-token: write steps: - uses: actions/checkout@v3 - - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main + - name: Install Nix on ${{ matrix.systems.system }} + uses: DeterminateSystems/nix-installer-action@main + - name: Magic Nix Cache + uses: DeterminateSystems/magic-nix-cache-action@main - - name: Build and cache dev shell + - name: Build and cache dev shell for ${{ matrix.systems.nix-system }} run: | nix build ".#devShells.${{ matrix.systems.nix-system }}.default" - - name: Build package and create closure + - name: Build package and create closure for ${{ matrix.systems.system }} run: | nix build .# -L --fallback && \ - nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.ARCHIVE }}" + nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.ARCHIVE_NAME }}" - - name: Upload a Build Artifact + - name: Upload magic-nix-cache closure for ${{ matrix.systems.system }} uses: actions/upload-artifact@v3.1.2 with: # Artifact name - name: ${{ env.CLOSURE_NAME }} - path: ${{ env.ARCHIVE }} + name: ${{ env.ARTIFACT_KEY }} + path: ${{ env.ARCHIVE_NAME }} retention-days: 1 diff --git a/.github/workflows/check-and-test.yaml b/.github/workflows/check-and-test.yaml index 3a5bb6f..d1a2ad0 100644 --- a/.github/workflows/check-and-test.yaml +++ b/.github/workflows/check-and-test.yaml @@ -41,9 +41,8 @@ jobs: runs-on: ${{ matrix.systems.runner }} needs: build env: - CLOSURE_NAME: magic-nix-cache-${{ matrix.systems.system }} - CLOSURE_PATH: magic-nix-cache - ARCHIVE: magic-nix-cache.closure.xz + ARTIFACT_KEY: magic-nix-cache-${{ matrix.systems.system }} + ARCHIVE_NAME: magic-nix-cache.closure.xz strategy: matrix: systems: @@ -59,25 +58,26 @@ jobs: contents: read id-token: write steps: - - name: Download artifact + - name: Download closure for ${{ matrix.systems.system }} uses: actions/download-artifact@v3 with: - name: ${{ env.CLOSURE_NAME }} - path: ${{ env.CLOSURE_PATH }} + name: ${{ env.ARTIFACT_KEY }} + path: ${{ env.ARTIFACT_KEY }} - - name: Install Nix + - name: Install Nix on ${{ matrix.systems.system }} uses: DeterminateSystems/nix-installer-action@main - - name: Extract + - name: Extract closure for ${{ matrix.systems.system }} id: extract run: | - ARTIFACT="${{ env.CLOSURE_PATH }}/${{ env.ARCHIVE }}" + ARTIFACT="${{ env.ARTIFACT_KEY }}/${{ env.ARCHIVE_NAME }}" OUTPUT=$(cat ${ARTIFACT} | xz -d | nix-store --import) MNC_BIN_PATH=$(echo "${OUTPUT}" | tail -n 1) MAGIC_NIX_CACHE="${MNC_BIN_PATH}/bin/magic-nix-cache" echo "mnc-path=${MAGIC_NIX_CACHE}" >> "$GITHUB_OUTPUT" - - uses: DeterminateSystems/magic-nix-cache-action@main + - name: Test magic-nix-cache-action@main on ${{ matrix.systems.runner }} + uses: DeterminateSystems/magic-nix-cache-action@main with: source-binary: "${{ steps.extract.outputs.mnc-path }}" From 49afb020c1c512881a679167a942f32d47a50dae Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Sat, 18 May 2024 17:24:45 -0300 Subject: [PATCH 18/22] Build only when label is applied --- .github/workflows/release-prs.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release-prs.yml b/.github/workflows/release-prs.yml index 9d6a26e..7364c74 100644 --- a/.github/workflows/release-prs.yml +++ b/.github/workflows/release-prs.yml @@ -10,13 +10,7 @@ on: jobs: build: - uses: ./.github/workflows/build.yaml - secrets: inherit - - release: - needs: build - - concurrency: release + # We want to build artifacts only if the `upload to s3` label is applied # Only intra-repo PRs are allowed to have PR artifacts uploaded # We only want to trigger once the upload once in the case the upload label is added, not when any label is added if: | @@ -25,6 +19,12 @@ jobs: (github.event.action == 'labeled' && github.event.label.name == 'upload to s3') || (github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, 'upload to s3')) ) + uses: ./.github/workflows/build.yaml + secrets: inherit + + release: + needs: build + concurrency: release runs-on: ubuntu-latest permissions: id-token: write # In order to request a JWT for AWS auth From f92c44ab59ef92d6ccb0a740107618abbbb75fcb Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Mon, 20 May 2024 07:16:32 -0300 Subject: [PATCH 19/22] Spawn daemon in separate process (this should fail in CI) --- .github/workflows/build.yaml | 4 ++-- magic-nix-cache/src/main.rs | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 32403b5..b292cc3 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -41,8 +41,8 @@ jobs: - name: Build package and create closure for ${{ matrix.systems.system }} run: | - nix build .# -L --fallback && \ - nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.ARCHIVE_NAME }}" + nix build .# -L --fallback + nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.ARCHIVE_NAME }}" - name: Upload magic-nix-cache closure for ${{ matrix.systems.system }} uses: actions/upload-artifact@v3.1.2 diff --git a/magic-nix-cache/src/main.rs b/magic-nix-cache/src/main.rs index e0af249..fb97e3c 100644 --- a/magic-nix-cache/src/main.rs +++ b/magic-nix-cache/src/main.rs @@ -26,6 +26,7 @@ use std::io::Write; use std::net::SocketAddr; use std::os::unix::fs::PermissionsExt; use std::path::{Path, PathBuf}; +use std::process::exit; use std::sync::Arc; use ::attic::nix_store::NixStore; @@ -370,6 +371,21 @@ async fn main_cli() -> Result<()> { tracing::info!("Listening on {}", args.listen); + let server = axum::Server::bind(&args.listen) + .serve(app.into_make_service()) + .with_graceful_shutdown(async move { + shutdown_receiver.await.ok(); + tracing::info!("Shutting down"); + }); + + // Spawn here so that post-startup tasks can proceed + tokio::spawn(async move { + if let Err(e) = server.await { + tracing::error!("failed to start up daemon: {e}"); + exit(1); + } + }); + // Notify of startup via HTTP if let Some(startup_notification_url) = args.startup_notification_url { tracing::debug!("Startup notification via HTTP POST to {startup_notification_url}"); @@ -411,21 +427,11 @@ async fn main_cli() -> Result<()> { tracing::debug!("Created startup notification file at {startup_notification_file_path:?}"); } - let ret = axum::Server::bind(&args.listen) - .serve(app.into_make_service()) - .with_graceful_shutdown(async move { - shutdown_receiver.await.ok(); - tracing::info!("Shutting down"); - }) - .await; - // Notify diagnostics endpoint if let Some(diagnostic_endpoint) = diagnostic_endpoint { state.metrics.send(diagnostic_endpoint).await; } - ret?; - Ok(()) } From 23356ead9772461784ffd89d8265c43ff7028731 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Mon, 20 May 2024 07:44:54 -0300 Subject: [PATCH 20/22] Test Action in strict mode --- .github/workflows/check-and-test.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-and-test.yaml b/.github/workflows/check-and-test.yaml index d1a2ad0..8a47d6b 100644 --- a/.github/workflows/check-and-test.yaml +++ b/.github/workflows/check-and-test.yaml @@ -77,7 +77,8 @@ jobs: echo "mnc-path=${MAGIC_NIX_CACHE}" >> "$GITHUB_OUTPUT" - - name: Test magic-nix-cache-action@main on ${{ matrix.systems.runner }} - uses: DeterminateSystems/magic-nix-cache-action@main + - name: Test magic-nix-cache-action@test-fail-mode on ${{ matrix.systems.runner }} + uses: DeterminateSystems/magic-nix-cache-action@test-fail-mode with: source-binary: "${{ steps.extract.outputs.mnc-path }}" + strict-mode: true From 645dabfe82d13ce1c32b12abda2e1de92e45c4e1 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Mon, 20 May 2024 07:58:47 -0300 Subject: [PATCH 21/22] Add nix build to test --- .github/workflows/check-and-test.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/check-and-test.yaml b/.github/workflows/check-and-test.yaml index 8a47d6b..bace43e 100644 --- a/.github/workflows/check-and-test.yaml +++ b/.github/workflows/check-and-test.yaml @@ -58,6 +58,8 @@ jobs: contents: read id-token: write steps: + - uses: actions/checkout@v3 + - name: Download closure for ${{ matrix.systems.system }} uses: actions/download-artifact@v3 with: @@ -82,3 +84,7 @@ jobs: with: source-binary: "${{ steps.extract.outputs.mnc-path }}" strict-mode: true + + - name: Run nix to test magic-nix-cache-action + run: | + nix develop --command echo "just testing" From 08033cd09a135621acd1928bf3e9d2ce7dbe7b6b Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Mon, 20 May 2024 08:11:08 -0300 Subject: [PATCH 22/22] Revert "Spawn daemon in separate process (this should fail in CI)" This reverts commit f92c44ab59ef92d6ccb0a740107618abbbb75fcb. --- .github/workflows/build.yaml | 4 ++-- magic-nix-cache/src/main.rs | 26 ++++++++++---------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index b292cc3..32403b5 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -41,8 +41,8 @@ jobs: - name: Build package and create closure for ${{ matrix.systems.system }} run: | - nix build .# -L --fallback - nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.ARCHIVE_NAME }}" + nix build .# -L --fallback && \ + nix-store --export $(nix-store -qR ./result) | xz -9 > "${{ env.ARCHIVE_NAME }}" - name: Upload magic-nix-cache closure for ${{ matrix.systems.system }} uses: actions/upload-artifact@v3.1.2 diff --git a/magic-nix-cache/src/main.rs b/magic-nix-cache/src/main.rs index fb97e3c..e0af249 100644 --- a/magic-nix-cache/src/main.rs +++ b/magic-nix-cache/src/main.rs @@ -26,7 +26,6 @@ use std::io::Write; use std::net::SocketAddr; use std::os::unix::fs::PermissionsExt; use std::path::{Path, PathBuf}; -use std::process::exit; use std::sync::Arc; use ::attic::nix_store::NixStore; @@ -371,21 +370,6 @@ async fn main_cli() -> Result<()> { tracing::info!("Listening on {}", args.listen); - let server = axum::Server::bind(&args.listen) - .serve(app.into_make_service()) - .with_graceful_shutdown(async move { - shutdown_receiver.await.ok(); - tracing::info!("Shutting down"); - }); - - // Spawn here so that post-startup tasks can proceed - tokio::spawn(async move { - if let Err(e) = server.await { - tracing::error!("failed to start up daemon: {e}"); - exit(1); - } - }); - // Notify of startup via HTTP if let Some(startup_notification_url) = args.startup_notification_url { tracing::debug!("Startup notification via HTTP POST to {startup_notification_url}"); @@ -427,11 +411,21 @@ async fn main_cli() -> Result<()> { tracing::debug!("Created startup notification file at {startup_notification_file_path:?}"); } + let ret = axum::Server::bind(&args.listen) + .serve(app.into_make_service()) + .with_graceful_shutdown(async move { + shutdown_receiver.await.ok(); + tracing::info!("Shutting down"); + }) + .await; + // Notify diagnostics endpoint if let Some(diagnostic_endpoint) = diagnostic_endpoint { state.metrics.send(diagnostic_endpoint).await; } + ret?; + Ok(()) }