Skip to content

Commit

Permalink
Merge pull request #63 from mole99/nix
Browse files Browse the repository at this point in the history
WIP: Nix build system
  • Loading branch information
mole99 authored May 16, 2024
2 parents ad7e3d9 + dce2d61 commit a1c1fe5
Show file tree
Hide file tree
Showing 13 changed files with 872 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .github/actions/build_nix/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Build/Cache Nix
description: Builds default devShell for a platform, caching the results (if applicable)
inputs:
cachix_cache:
description: "The name of the Cachix cache to download to and/or upload from"
required: true
default: "openlane"
cachix_token:
description: "An authentication token for Cachix"
required: false
default: ""
shell:
description: "Shell to use"
required: true
default: "bash"
nix_system:
description: "The nix platform string to build for"
required: true
default: "x86_64-linux"
local_cache_key:
description: Key to use for the cache
required: false
default: ""
run_tests:
description: Whether to run unit tests and the smoke test
required: false
default: "false"
runs:
using: "composite"
steps:
- id: cache
name: Cache Derivation
uses: actions/cache@v3
with:
key: ${{ inputs.local_cache_key }}-${{ inputs.nix_system }}
path: /tmp/${{ inputs.local_cache_key }}
- id: Build
name: Build
shell: ${{ inputs.shell }}
run: |
substituters='https://${{ inputs.cachix_cache }}.cachix.org https://cache.nixos.org'
if [ '${{ inputs.local_cache_key }}' = '' ]; then
substituters="file:///tmp/${{ inputs.local_cache_key }} $substituters"
fi
echo "#################################################################"
outPath=$(nix build\
--print-out-paths\
--no-link\
--accept-flake-config\
--option system ${{ inputs.nix_system }}\
--extra-platforms ${{ inputs.nix_system }}\
--option substituters "$substituters"\
.#devShells.${{ inputs.nix_system }}.default)
echo "out-path=$outPath" >> $GITHUB_OUTPUT
sudo du -hs /nix/store/* | sort -h | tail -n 20
- name: Unit/Step Tests
shell: ${{ inputs.shell }}
if: inputs.run_tests == 'true'
run: echo TODO
- name: Smoke Test
shell: ${{ inputs.shell }}
if: inputs.run_tests == 'true'
run: |
echo "#################################################################"
nix run\
--option system ${{ inputs.nix_system }}\
--extra-platforms ${{ inputs.nix_system }}\
--accept-flake-config\
.#packages.${{ inputs.nix_system }}.cace -- --help
- name: Push to local cache
shell: ${{ inputs.shell }}
if: inputs.local_cache_key != '' && steps.cache.outputs.cache-hit != 'true'
run: |
nix copy\
--to 'file:///tmp/${{ inputs.local_cache_key }}?compression=zstd&parallel-compression=true'\
${{ steps.build.outputs.out-path }}
- name: Install + Push to Cachix
shell: ${{ inputs.shell }}
if: ${{ inputs.cachix_token != '' }}
run: |
echo "#################################################################"
nix-env -iA cachix -f https://cachix.org/api/v1/install
cachix authtoken ${{ inputs.cachix_token }}
cachix push ${{ inputs.cachix_cache }} ${{ steps.build.outputs.out-path }}
22 changes: 22 additions & 0 deletions .github/actions/check_space/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Check Space
description: Reusable step that prints disk usage information
runs:
using: "composite"
steps:
- name: Check Space
shell: bash
run: |
if test -d /nix/store; then
sudo du -hs /nix/store/* | sort -h | tail -n 10
fi
echo ===============
df -h
echo ===============
du -hs ~/* | sort -h
echo ===============
du -hs * | sort -h
echo ===============
du -hs /home/runner/runners/* | sort -h
echo ===============
du -hs /home/runner/work/* | sort -h
echo ===============
28 changes: 28 additions & 0 deletions .github/actions/setup_env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Set up environment
description: Sets up a number of environment variables that are useful for publishing
runs:
using: "composite"
steps:
- name: Export Repo URL
shell: bash
run: echo "REPO_URL=https://github.com/${{ github.repository }}.git" >> $GITHUB_ENV

- name: Export Branch Name
shell: bash
run: echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV

- name: Set default for env.NEW_TAG
shell: bash
run: echo "NEW_TAG=NO_NEW_TAG" >> $GITHUB_ENV

- name: Check for new version
if: ${{ github.event_name == 'push' && env.BRANCH_NAME == 'main' }}
shell: bash
run: |
python3 ./.github/scripts/generate_tag.py
- name: Publish
if: ${{ github.event_name == 'push' && env.BRANCH_NAME == 'main' && env.NEW_TAG != 'NO_NEW_TAG' }}
shell: bash
run: |
echo "PUBLISH=1" >> $GITHUB_ENV
Loading

0 comments on commit a1c1fe5

Please sign in to comment.