diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4d33b8b1..81246706 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,10 @@ concurrency: group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }} cancel-in-progress: true +defaults: + run: + shell: nix develop --fallback --command bash -e {0} + jobs: build-nix: runs-on: ubuntu-latest @@ -29,20 +33,16 @@ jobs: - '**/*.go' - 'integration_test/' - 'config-example.yaml' - - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34 + - uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main if: steps.changed-files.outputs.files == 'true' - - uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3 + - uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main if: steps.changed-files.outputs.files == 'true' - with: - primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', - '**/flake.lock') }} - restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }} - name: Check vendor hash id: vendorhash if: steps.changed-files.outputs.files == 'true' run: | - nix develop --fallback --command -- go run ./cmd/vendorhash check | tee check-result + go run ./cmd/vendorhash check | tee check-result { grep '^expected_sri=' check-result || true grep '^actual_sri=' check-result || true @@ -81,17 +81,13 @@ jobs: - "GOARCH=amd64 GOOS=darwin" steps: - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34 - - uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3 - with: - primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', - '**/flake.lock') }} - restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }} + - uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main + - uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main - name: Run go cross compile env: CGO_ENABLED: 0 - run: env ${{ matrix.env }} nix develop --fallback --command -- go build -o "headscale" + run: env ${{ matrix.env }} go build -o "headscale" ./cmd/headscale - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 with: diff --git a/.github/workflows/check-generated.yml b/.github/workflows/check-generated.yml index 4b463fcc..fffc3da0 100644 --- a/.github/workflows/check-generated.yml +++ b/.github/workflows/check-generated.yml @@ -12,6 +12,10 @@ concurrency: group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }} cancel-in-progress: true +defaults: + run: + shell: nix develop --fallback --command bash -e {0} + jobs: check-generated: runs-on: ubuntu-latest @@ -29,17 +33,14 @@ jobs: - 'go.*' - '**/*.go' - 'tools/**' - - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34 + - uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main if: steps.changed-files.outputs.files == 'true' - - uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3 + - uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main if: steps.changed-files.outputs.files == 'true' - with: - primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', '**/flake.lock') }} - restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }} - name: Run make generate if: steps.changed-files.outputs.files == 'true' - run: nix develop --fallback --command -- make generate + run: make generate - name: Check for uncommitted changes if: steps.changed-files.outputs.files == 'true' diff --git a/.github/workflows/check-tests.yaml b/.github/workflows/check-tests.yaml index df5b857c..b7301173 100644 --- a/.github/workflows/check-tests.yaml +++ b/.github/workflows/check-tests.yaml @@ -6,6 +6,10 @@ concurrency: group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }} cancel-in-progress: true +defaults: + run: + shell: nix develop --fallback --command bash -e {0} + jobs: check-tests: runs-on: ubuntu-latest @@ -24,19 +28,15 @@ jobs: - '**/*.go' - 'integration_test/' - 'config-example.yaml' - - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34 + - uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main if: steps.changed-files.outputs.files == 'true' - - uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3 + - uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main if: steps.changed-files.outputs.files == 'true' - with: - primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', - '**/flake.lock') }} - restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }} - name: Generate and check integration tests if: steps.changed-files.outputs.files == 'true' run: | - nix develop --fallback --command bash -c "cd .github/workflows && go generate" + (cd .github/workflows && go generate) git diff --exit-code .github/workflows/test-integration.yaml - name: Show missing tests diff --git a/.github/workflows/container-main.yml b/.github/workflows/container-main.yml index 71710e9f..e2ebe6fc 100644 --- a/.github/workflows/container-main.yml +++ b/.github/workflows/container-main.yml @@ -16,6 +16,10 @@ concurrency: group: ${{ github.workflow }}-${{ github.sha }} cancel-in-progress: true +defaults: + run: + shell: nix develop --fallback --command bash -e {0} + jobs: container: if: github.repository == 'juanfont/headscale' @@ -40,12 +44,8 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34 - - uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3 - with: - primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', - '**/flake.lock') }} - restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }} + - uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main + - uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main - name: Set commit timestamp run: echo "SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)" >> $GITHUB_ENV @@ -56,7 +56,7 @@ jobs: KO_DEFAULTBASEIMAGE: gcr.io/distroless/base-debian13 CGO_ENABLED: "0" run: | - nix develop --fallback --command -- ko build \ + ko build \ --bare \ --platform=linux/amd64,linux/arm64 \ --tags=main-${GITHUB_SHA::7},development \ @@ -68,7 +68,7 @@ jobs: KO_DEFAULTBASEIMAGE: gcr.io/distroless/base-debian13 CGO_ENABLED: "0" run: | - nix develop --fallback --command -- ko build \ + ko build \ --bare \ --platform=linux/amd64,linux/arm64 \ --tags=main-${GITHUB_SHA::7},development \ @@ -92,19 +92,15 @@ jobs: - name: Checkout uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34 - - uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3 - with: - primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', - '**/flake.lock') }} - restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }} + - uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main + - uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main - name: Build binary env: CGO_ENABLED: "0" GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} - run: nix develop --fallback --command -- go build -o headscale ./cmd/headscale + run: go build -o headscale ./cmd/headscale - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 with: diff --git a/.github/workflows/gc.yml b/.github/workflows/gc.yml new file mode 100644 index 00000000..9df7a037 --- /dev/null +++ b/.github/workflows/gc.yml @@ -0,0 +1,39 @@ +name: Cache GC + +# Garbage collection for the hestia binary cache. Must run on the default +# branch: a PR job's cache scope is read-only towards the default branch and +# dies with the PR, but the default-branch scope grows forever without GC. + +concurrency: + group: hestia-gc + cancel-in-progress: false + +on: + schedule: + # Daily, off-peak (UTC). + - cron: "23 3 * * *" + workflow_dispatch: + inputs: + dry-run: + description: Plan only; do not repack, touch, or delete anything. + type: boolean + default: false + +permissions: + contents: read + +jobs: + gc: + runs-on: ubuntu-latest + permissions: + # REST cache deletes need actions:write. + actions: write + contents: read + steps: + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + - uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main + - uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main + - name: Run garbage collection + run: '"${HESTIA_BIN}" gc ${{ inputs.dry-run && ''--dry-run'' || '''' }}' + env: + GITHUB_TOKEN: ${{ github.token }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ed809ac5..617355d6 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,6 +6,10 @@ concurrency: group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }} cancel-in-progress: true +defaults: + run: + shell: nix develop --fallback --command bash -e {0} + jobs: golangci-lint: runs-on: ubuntu-latest @@ -24,18 +28,14 @@ jobs: - '**/*.go' - 'integration_test/' - 'config-example.yaml' - - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34 + - uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main if: steps.changed-files.outputs.files == 'true' - - uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3 + - uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main if: steps.changed-files.outputs.files == 'true' - with: - primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', - '**/flake.lock') }} - restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }} - name: golangci-lint if: steps.changed-files.outputs.files == 'true' - run: nix develop --fallback --command -- golangci-lint run + run: golangci-lint run --new-from-rev=${{github.event.pull_request.base.sha}} --output.text.path=stdout --output.text.print-linter-name @@ -64,16 +64,12 @@ jobs: - '**/*.css' - '**/*.scss' - '**/*.html' - - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34 + - uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main if: steps.changed-files.outputs.files == 'true' - - uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3 + - uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main if: steps.changed-files.outputs.files == 'true' - with: - primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', - '**/flake.lock') }} - restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }} - name: Prettify code if: steps.changed-files.outputs.files == 'true' - run: nix develop --fallback --command -- prettier --no-error-on-unmatched-pattern + run: prettier --no-error-on-unmatched-pattern --ignore-unknown --check **/*.{ts,js,md,yaml,yml,sass,css,scss,html} diff --git a/.github/workflows/nix-module-test.yml b/.github/workflows/nix-module-test.yml index 03fe1191..1a7fbcc8 100644 --- a/.github/workflows/nix-module-test.yml +++ b/.github/workflows/nix-module-test.yml @@ -38,15 +38,11 @@ jobs: - 'cmd/**' - 'hscontrol/**' - - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34 + - uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main if: steps.changed-files.outputs.nix == 'true' || steps.changed-files.outputs.go == 'true' - - uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3 + - uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main if: steps.changed-files.outputs.nix == 'true' || steps.changed-files.outputs.go == 'true' - with: - primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', - '**/flake.lock') }} - restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }} - name: Run NixOS module tests if: steps.changed-files.outputs.nix == 'true' || steps.changed-files.outputs.go == 'true' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2d8c172b..349ad53d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,6 +7,10 @@ on: - "*" # triggers only if push new tag version workflow_dispatch: +defaults: + run: + shell: nix develop --fallback --command bash -e {0} + jobs: goreleaser: if: github.repository == 'juanfont/headscale' @@ -30,14 +34,10 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34 - - uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3 - with: - primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', - '**/flake.lock') }} - restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }} + - uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main + - uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main - name: Run goreleaser - run: nix develop --fallback --command -- goreleaser release --clean + run: goreleaser release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test-integration.yaml b/.github/workflows/test-integration.yaml index bfa13e34..bfdb3f57 100644 --- a/.github/workflows/test-integration.yaml +++ b/.github/workflows/test-integration.yaml @@ -6,6 +6,9 @@ on: [pull_request] concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true +defaults: + run: + shell: nix develop --fallback --command bash -e {0} jobs: # build: Builds binaries and Docker images once, uploads as artifacts for reuse. # build-postgres: Pulls postgres image separately to avoid Docker Hub rate limits. @@ -36,23 +39,18 @@ jobs: - '.github/workflows/test-integration.yaml' - '.github/workflows/integration-test-template.yml' - 'Dockerfile.*' - - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34 + - uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main if: steps.changed-files.outputs.files == 'true' - - uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3 + - uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main if: steps.changed-files.outputs.files == 'true' - with: - primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', '**/flake.lock') }} - restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }} - name: Build binaries and warm Go cache if: steps.changed-files.outputs.files == 'true' run: | # Build all Go binaries in one nix shell to maximize cache reuse - nix develop --fallback --command -- bash -c ' - go build -o hi ./cmd/hi - CGO_ENABLED=0 GOOS=linux go build -o headscale ./cmd/headscale - # Build integration test binary to warm the cache with all dependencies - go test -c ./integration -o /dev/null 2>/dev/null || true - ' + go build -o hi ./cmd/hi + CGO_ENABLED=0 GOOS=linux go build -o headscale ./cmd/headscale + # Build integration test binary to warm the cache with all dependencies + go test -c ./integration -o /dev/null 2>/dev/null || true - name: Upload hi binary if: steps.changed-files.outputs.files == 'true' uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 @@ -128,6 +126,7 @@ jobs: if: needs.build.outputs.files-changed == 'true' steps: - name: Force overlay2 storage driver + shell: bash run: | sudo mkdir -p /etc/docker echo '{"storage-driver":"overlay2"}' | sudo tee /etc/docker/daemon.json @@ -143,6 +142,7 @@ jobs: username: ${{ env.DOCKERHUB_USERNAME }} password: ${{ env.DOCKERHUB_TOKEN }} - name: Pull and save postgres image + shell: bash run: | docker pull postgres:latest docker tag postgres:latest postgres:${{ github.sha }} @@ -159,11 +159,8 @@ jobs: if: needs.build.outputs.files-changed == 'true' steps: - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34 - - uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3 - with: - primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', '**/flake.lock') }} - restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }} + - uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main + - uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main - name: Force overlay2 storage driver run: | sudo mkdir -p /etc/docker @@ -182,7 +179,7 @@ jobs: - name: List Tailscale versions to pre-pull id: versions run: | - versions=$(nix develop --fallback --command go run ./cmd/hi list-versions --set=must --exclude=head) + versions=$(go run ./cmd/hi list-versions --set=must --exclude=head) echo "versions=${versions}" >> "$GITHUB_OUTPUT" echo "Pre-pulling: ${versions}" - name: Pull Tailscale images diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 911f0057..dadacddc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,10 @@ concurrency: group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }} cancel-in-progress: true +defaults: + run: + shell: nix develop --fallback --command bash -e {0} + jobs: test: runs-on: ubuntu-latest @@ -27,14 +31,10 @@ jobs: - 'integration_test/' - 'config-example.yaml' - - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34 + - uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main if: steps.changed-files.outputs.files == 'true' - - uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3 + - uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main if: steps.changed-files.outputs.files == 'true' - with: - primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/*.nix', - '**/flake.lock') }} - restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }} - name: Run tests if: steps.changed-files.outputs.files == 'true' @@ -44,4 +44,4 @@ jobs: # some of the database migration tests. LC_ALL: "en_US.UTF-8" LC_CTYPE: "en_US.UTF-8" - run: nix develop --fallback --command -- gotestsum + run: gotestsum