Debian Codegraph @

others/mbedtls/tf-psa-crypto/drivers/pqcp/mldsa-native/.github/actions/setup-nix/action.yml

raw symbols SCIP
1 # Copyright (c) The mlkem-native project authors
2 # Copyright (c) The mldsa-native project authors
3 # SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4
5 name: Setup nix
6 description: Setup nix
7
8 inputs:
9 script:
10 description: The script to be run in the nix shell
11 required: false
12 devShell:
13 description: The name of the devShell
14 required: true
15 cache:
16 description: Determine whether to enable nix cache
17 default: 'false'
18 verbose:
19 description: Determine wether to suppress nix log or not
20 default: 'false'
21 cache_prefix:
22 description: Fixed prefix of ID of Github cache entries that should be removed.
23 required: false
24 save_cache:
25 description: Determine whether to save cache with primary key or not
26 required: false
27 default: 'false'
28 gh_token:
29 description: Github access token to use
30 required: true
31 install:
32 required: false
33 description: Determine how to install nix ('installer' | 'apt')
34 default: 'installer'
35
36 runs:
37 using: composite
38 steps:
39 - name: Pre-check nix
40 id: nix-pre-check
41 if: ${{ env.NIX_SHELL == '' }}
42 shell: bash -lo pipefail {0}
43 run: |
44 suppress() {
45 local exit_code="$?"
46 local line_no="$1"
47 echo "Nix check failed at $line_no: $exit_code"
48 echo "installed=false" >> $GITHUB_OUTPUT
49 exit 0
50 }
51
52 trap 'suppress $LINENO' ERR
53
54 if [[ $USER == 'root' ]]; then
55 mkdir -p /root
56 echo "HOME=/root" >> $GITHUB_ENV
57 fi
58
59 nix --version
60 - name: Install nix via apt
61 if: ${{ steps.nix-pre-check.outputs.installed == 'false' && inputs.install == 'apt' }}
62 shell: bash
63 run: |
64 if [[ -f /.dockerenv ]]; then
65 apt install nix -y
66 else
67 sudo apt install nix -y
68 fi
69 mkdir -p ~/.config/nix
70 cat >> ~/.config/nix/nix.conf << EOF
71 experimental-features = nix-command flakes
72 EOF
73
74 if [[ ! -z $GH_TOKEN ]]; then
75 echo "access-tokens = github.com=$GH_TOKEN" >> ~/.config/nix/nix.conf
76 fi
77 - uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30
78 if: ${{ steps.nix-pre-check.outputs.installed == 'false' }}
79 with:
80 github_access_token: ${{ inputs.gh_token }}
81 - name: Post-check nix
82 id: nix-post-check
83 continue-on-error: true
84 shell: bash -lo pipefail {0}
85 run: |
86 echo "::group::nix config"
87 if [[ -z "${{ inputs.cache_prefix }}" ]]; then
88 cache_prefix="${{ runner.os }}-${{ runner.arch }}"
89 else
90 cache_prefix="${{ inputs.cache_prefix }}"
91 fi
92
93 echo "cache_prefix=$cache_prefix" >> $GITHUB_OUTPUT
94
95 if [[ "${{ steps.nix-pre-check.outputs.installed }}" == 'false' ]]; then
96 sudo chown -R $USER:nixbld /nix
97 fi
98
99 nix profile install nixpkgs/nixos-24.11#sqlite
100 nix config show
101 echo "::endgroup::"
102 - uses: nix-community/cache-nix-action@dab0514428ae3988852b7787a6d86a6fc571cc9d #v6.0.0
103 id: cache
104 if: ${{ env.NIX_CACHE_ENABLED != 1 && inputs.cache == 'true' }}
105 continue-on-error: true
106 with:
107 primary-key: ${{ steps.nix-post-check.outputs.cache_prefix }}
108 gc-max-store-size-linux: 3221225472
109 purge: ${{ inputs.save_cache == 'true' }}
110 save: ${{ inputs.save_cache == 'true' }}
111 purge-prefixes: cache-${{ steps.nix-post-check.outputs.cache_prefix }}
112 purge-created: 0
113 purge-primary-key: ${{ inputs.save_cache == 'true' && 'always' || 'never' }}
114 token: ${{ inputs.gh_token }}
115 - name: Set Shell
116 shell: bash -lo pipefail {0}
117 run: |
118 echo "::group::set nix shell"
119 if [[ "${{ steps.cache.outputs.hit-primary-key }}" == "true" ]]; then
120 echo NIX_CACHE_ENABLED=1 >> $GITHUB_ENV
121 fi
122
123 echo NIX_SHELL="${{ inputs.devShell }}" >> $GITHUB_ENV
124 nix_extra_flags="${{ inputs.verbose == 'false' && '--quiet' || '' }}"
125 if [[ ${{ inputs.install }} == 'apt' && ! -f /.dockerenv ]]; then
126 echo SHELL="sudo $(which nix) develop $nix_extra_flags .#${{ inputs.devShell }} -c bash -e {0}" >> $GITHUB_ENV
127 else
128 echo SHELL="$(which nix) develop $nix_extra_flags .#${{ inputs.devShell }} -c bash -e {0}" >> $GITHUB_ENV
129 fi
130 echo "::endgroup::"
131 - name: Prepare nix dev shell
132 shell: ${{ env.SHELL }}
133 run: |
134 - name: Dependency check
135 shell: ${{ env.SHELL }}
136 if: inputs.script != ''
137 run: eval ${{ inputs.script }}