Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Nix build action #336

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Generic Nix build action #336

wants to merge 6 commits into from

Conversation

ro-tex
Copy link

@ro-tex ro-tex commented Apr 25, 2024

This PR adds a generic GHA that can build a Nix project and cache its artefacts on S3.

TODO: This PR should probably be adapted to augment the setup-nix action, instead of being a separate one.

Example usage:

      - name: Build and cache
        uses: smartcontractkit/.github/actions/nix-build
        with:
          cache-url: s3://${{ secrets.NIX_CACHE_S3_BUCKET }}?region=${{ secrets.AWS_REGION }}
          cache-privkey: ${{ secrets.NIX_BINARY_SIGNING_KEY }}
          aws-region: ${{ secrets.AWS_REGION }}
          role-to-assume: ${{ secrets.AWS_OIDC_IAM_ROLE_PUBLISH_ARN }}
          role-duration-seconds: ${{ secrets. AWS_ROLE_DURATION_SECONDS }}

@ro-tex ro-tex requested a review from a team as a code owner April 25, 2024 10:04
@ro-tex ro-tex requested review from aalu1418 and tt-cll April 25, 2024 10:04
@ro-tex ro-tex marked this pull request as draft April 25, 2024 10:44
Copy link
Contributor

@chainchad chainchad left a comment

Choose a reason for hiding this comment

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

Looks good. Left some general feedback. Might want another reviewer more familiar with nix to review those specific steps though.

actions/nix-build/README.md Outdated Show resolved Hide resolved
actions/nix-build/action.yml Outdated Show resolved Hide resolved
actions/nix-build/package.json Outdated Show resolved Hide resolved
default: ""
cache-privkey:
description: "Nix cache binary private signing key - not used if setup-only=true"
required: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we enforce signing?

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose to enforce we could add a check where if setup-only != true and this is empty, to fail?

Copy link
Author

Choose a reason for hiding this comment

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

In theory you can use this action without any cache setup - it will still build your flake and all derivations. It will just be slower.

actions/nix-build/action.yml Outdated Show resolved Hide resolved
actions/nix-build/action.yml Outdated Show resolved Hide resolved
Comment on lines 71 to 72
aws-access-key-id: ${{ inputs.aws-access-key-id }}
aws-secret-access-key: ${{ inputs.aws-secret-access-key }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
aws-access-key-id: ${{ inputs.aws-access-key-id }}
aws-secret-access-key: ${{ inputs.aws-secret-access-key }}
aws-access-key-id: ${{ inputs.aws-access-key-id }}
aws-secret-access-key: ${{ inputs.aws-secret-access-key }}
mask-aws-account-id: true

Don't think we need access keys (see earlier comment) and we should mask the AWS account ID so it doesn't appear in logs.

Copy link
Author

@ro-tex ro-tex Apr 26, 2024

Choose a reason for hiding this comment

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

Access key and accompanying fields removed.

GitHub already does the masking for us - anything that comes from the secrets appears as *** in the output of the action.

Example:

Run aws-actions/configure-aws-credentials@v4
  with:
    aws-region: ***
    aws-access-key-id: ***
    aws-secret-access-key: ***
    audience: sts.amazonaws.com
  env:
    NIX_PATH: nixpkgs=channel:nixos-unstable
    TMPDIR: /home/runner/work/_temp
Proceeding with IAM user credentials
Run # run check package builds
  # run check package builds
  nix flake check --impure --all-systems
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    NIX_PATH: nixpkgs=channel:nixos-unstable
    TMPDIR: /home/runner/work/_temp
    AWS_DEFAULT_REGION: ***
    AWS_REGION: ***
    AWS_ACCESS_KEY_ID: ***
    AWS_SECRET_ACCESS_KEY: ***

ro-tex and others added 3 commits April 26, 2024 13:57
Co-authored-by: chainchad <96362174+chainchad@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants