Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/install-nix/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ inputs:
description: GitHub token to add as access-token in nix.conf
default: ''
required: false
nix-gitlab-token:
description: GitLab token to add as access-token in nix.conf
default: ''
required: false
nix-gitlab-domain:
description: GitLab domain to add as access-token in nix.conf
default: 'gitlab.com'
required: false

runs:
using: 'composite'
Expand All @@ -34,7 +42,15 @@ runs:
mkdir -p $HOME/.config/nix

cat << EOF > "$HOME/.config/nix/nix.conf"
${{ inputs.nix-github-token != '' && format('access-tokens = github.com={0}', inputs.nix-github-token) || '' }}
${{
(inputs.nix-github-token != '' && inputs.nix-gitlab-token != '' && inputs.nix-gitlab-domain != '' &&
format('access-tokens = github.com={0} {1}=PAT:{2}', inputs.nix-github-token, inputs.nix-gitlab-domain, inputs.nix-gitlab-token)) ||
(inputs.nix-github-token != '' &&
format('access-tokens = github.com={0}', inputs.nix-github-token)) ||
(inputs.nix-gitlab-token != '' && inputs.nix-gitlab-domain != '' &&
format('access-tokens = {0}=PAT:{1}', inputs.nix-gitlab-domain, inputs.nix-gitlab-token)) ||
''
}}
Comment on lines -37 to +53
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion

- name: Configure Nix
  shell: bash
  run: |
    mkdir -p "$HOME/.config/nix"

    access_tokens=""
    if [[ -n "${{ inputs.nix-github-token }}" && -n "${{ inputs.nix-gitlab-token }}" && -n "${{ inputs.nix-gitlab-domain }}" ]]; then
      access_tokens="access-tokens = github.com=${{ inputs.nix-github-token }} ${{ inputs.nix-gitlab-domain }}=PAT:${{ inputs.nix-gitlab-token }}"
    elif [[ -n "${{ inputs.nix-github-token }}" ]]; then
      access_tokens="access-tokens = github.com=${{ inputs.nix-github-token }}"
    elif [[ -n "${{ inputs.nix-gitlab-token }}" && -n "${{ inputs.nix-gitlab-domain }}" ]]; then
      access_tokens="access-tokens = ${{ inputs.nix-gitlab-domain }}=PAT:${{ inputs.nix-gitlab-token }}"
    fi

    cat > "$HOME/.config/nix/nix.conf" <<EOF
$access_tokens
allow-import-from-derivation = true
substituters = https://cache.nixos.org ${{ inputs.substituters }}
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ${{ inputs.trusted-public-keys }}
netrc-file = $HOME/.config/nix/netrc
EOF

    cat > "$HOME/.config/nix/netrc" <<EOF
machine ${{ inputs.cachix-cache }}.cachix.org password ${{ inputs.cachix-auth-token }}
EOF

You can update the whole run clause with this above.
This version is easier to read and modify without needing to mentally parse a long ternary chain.

Note: I have not tested it. Be conscious if you decide to use it.

allow-import-from-derivation = true
substituters = https://cache.nixos.org ${{inputs.substituters}}
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ${{inputs.trusted-public-keys}}
Expand Down
10 changes: 10 additions & 0 deletions .github/print-matrix/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ inputs:
description: GitHub token to add as access-token in nix.conf
default: ''
required: false
nix-gitlab-token:
description: GitLab token to add as access-token in nix.conf
default: ''
required: false
nix-gitlab-domain:
description: GitLab domain to add as access-token in nix.conf
default: 'gitlab.com'
required: false

outputs:
matrix:
Expand All @@ -48,6 +56,8 @@ runs:
trusted-public-keys: ${{ inputs.trusted-public-keys }}
substituters: ${{ inputs.substituters }}
nix-github-token: ${{ inputs.nix-github-token }}
nix-gitlab-token: ${{ inputs.nix-gitlab-token }}
nix-gitlab-domain: ${{ inputs.nix-gitlab-domain }}

- name: Print CI Matrix
id: print-matrix
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/reusable-flake-checks-ci-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ on:
NIX_GITHUB_TOKEN:
description: GitHub token to add as access-token in nix.conf
required: false
NIX_GITLAB_TOKEN:
description: GitLab token to add as access-token in nix.conf
required: false

jobs:
post-initial-comment:
Expand All @@ -50,6 +53,8 @@ jobs:
trusted-public-keys: ${{ vars.TRUSTED_PUBLIC_KEYS }}
substituters: ${{ vars.SUBSTITUTERS }}
nix-github-token: ${{ secrets.NIX_GITHUB_TOKEN }}
nix-gitlab-token: ${{ secrets.NIX_GITLAB_TOKEN }}
nix-gitlab-domain: ${{ vars.NIX_GITLAB_DOMAIN }}

- uses: actions/checkout@v4

Expand Down Expand Up @@ -78,6 +83,8 @@ jobs:
trusted-public-keys: ${{ vars.TRUSTED_PUBLIC_KEYS }}
substituters: ${{ vars.SUBSTITUTERS }}
nix-github-token: ${{ secrets.NIX_GITHUB_TOKEN }}
nix-gitlab-token: ${{ secrets.NIX_GITLAB_TOKEN }}
nix-gitlab-domain: ${{ vars.NIX_GITLAB_DOMAIN }}

- uses: actions/checkout@v4

Expand Down Expand Up @@ -154,6 +161,8 @@ jobs:
precalc_matrix: ${{ steps.matrix.outputs.fullMatrix }}
pr-comment-github-token: ${{ secrets.GITHUB_TOKEN }}
nix-github-token: ${{ secrets.NIX_GITHUB_TOKEN }}
nix-gitlab-token: ${{ secrets.NIX_GITLAB_TOKEN }}
nix-gitlab-domain: ${{ vars.NIX_GITLAB_DOMAIN }}

build:
needs: slurp-matrix
Expand All @@ -178,6 +187,8 @@ jobs:
trusted-public-keys: ${{ vars.TRUSTED_PUBLIC_KEYS }}
substituters: ${{ vars.SUBSTITUTERS }}
nix-github-token: ${{ secrets.NIX_GITHUB_TOKEN }}
nix-gitlab-token: ${{ secrets.NIX_GITLAB_TOKEN }}
nix-gitlab-domain: ${{ vars.NIX_GITLAB_DOMAIN }}

- name: Build ${{ matrix.name }}
run: |
Expand Down Expand Up @@ -205,6 +216,8 @@ jobs:
precalc_matrix: ${{ needs.slurp-matrix.outputs.fullMatrix }}
pr-comment-github-token: ${{ secrets.GITHUB_TOKEN }}
nix-github-token: ${{ secrets.NIX_GITHUB_TOKEN }}
nix-gitlab-token: ${{ secrets.NIX_GITLAB_TOKEN }}
nix-gitlab-domain: ${{ vars.NIX_GITLAB_DOMAIN }}

- run: exit 1
if: >-
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/reusable-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ on:
CACHIX_AUTH_TOKEN:
description: 'Cachix auth token'
required: true
NIX_GITLAB_TOKEN:
description: GitLab token to add as access-token in nix.conf
required: false

jobs:
lint:
Expand All @@ -28,6 +31,8 @@ jobs:
uses: metacraft-labs/nixos-modules/.github/install-nix@main
with:
nix-github-token: ${{ secrets.NIX_GITHUB_TOKEN }}
nix-gitlab-token: ${{ secrets.NIX_GITLAB_TOKEN }}
nix-gitlab-domain: ${{ vars.NIX_GITLAB_DOMAIN }}
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
cachix-cache: ${{ vars.CACHIX_CACHE }}
trusted-public-keys: ${{ vars.TRUSTED_PUBLIC_KEYS }}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/reusable-update-flake-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ on:
NIX_GITHUB_TOKEN:
description: GitHub token to add as access-token in nix.conf
required: false
NIX_GITLAB_TOKEN:
description: GitLab token to add as access-token in nix.conf
required: false
CACHIX_AUTH_TOKEN:
description: 'Cachix auth token'
required: true
Expand Down Expand Up @@ -51,6 +54,8 @@ jobs:
uses: metacraft-labs/nixos-modules/.github/install-nix@main
with:
nix-github-token: ${{ secrets.NIX_GITHUB_TOKEN }}
nix-gitlab-token: ${{ secrets.NIX_GITLAB_TOKEN }}
nix-gitlab-domain: ${{ vars.NIX_GITLAB_DOMAIN }}
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
cachix-cache: ${{ vars.CACHIX_CACHE }}
trusted-public-keys: ${{ vars.TRUSTED_PUBLIC_KEYS }}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/reusable-update-flake-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ on:
NIX_GITHUB_TOKEN:
description: GitHub token to add as access-token in nix.conf
required: false
NIX_GITLAB_TOKEN:
description: GitLab token to add as access-token in nix.conf
required: false
CACHIX_AUTH_TOKEN:
description: 'Cachix auth token'
required: true
Expand Down Expand Up @@ -42,6 +45,8 @@ jobs:
uses: metacraft-labs/nixos-modules/.github/install-nix@main
with:
nix-github-token: ${{ secrets.NIX_GITHUB_TOKEN }}
nix-gitlab-token: ${{ secrets.NIX_GITLAB_TOKEN }}
nix-gitlab-domain: ${{ vars.NIX_GITLAB_DOMAIN }}
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
cachix-cache: ${{ vars.CACHIX_CACHE }}
trusted-public-keys: ${{ vars.TRUSTED_PUBLIC_KEYS }}
Expand Down
Loading