Skip to content

Commit 8dcacda

Browse files
Add nix derivation (#96)
This adds a nix derivation for stable-mir-json. In addition, the unit and integration tests can be executed via nix by running `nix flake check`. Also a nix formatter was added. It can be installed via `nix profile install nixpkgs#nixfmt` and run via `make format` or `nixfmt **/*.nix`. A test workflow was added that builds and tests the nix derivation for both x86_64-linux and arm64-MacOS. Finally, the derivation and its dependencies are published on the usual k-framework cachix nix binary caches. --------- Co-authored-by: JianHong Zhao <[email protected]>
1 parent 89a011e commit 8dcacda

39 files changed

+29866
-29440
lines changed

.github/workflows/master.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,52 @@ jobs:
3131
-H "X-GitHub-Api-Version: 2022-11-28" \
3232
https://api.github.com/repos/runtimeverification/devops/dispatches \
3333
-d '{"event_type":"on-demand-test","client_payload":{"repo":"runtimeverification/stable-mir-json","version":"'${VERSION}'"}}'
34+
35+
nix-cache:
36+
name: 'Populate Nix Cache'
37+
strategy:
38+
matrix:
39+
runner: [normal, ARM64]
40+
runs-on: ${{ matrix.runner }}
41+
steps:
42+
- name: 'Check out code'
43+
uses: actions/checkout@v4
44+
with:
45+
ref: ${{ github.event.push.head.sha }}
46+
fetch-depth: 0
47+
48+
- name: 'Build and cache stable-mir-json'
49+
uses: workflow/nix-shell-action@v3
50+
env:
51+
GC_DONT_GC: 1
52+
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_PUBLIC_TOKEN }}
53+
with:
54+
packages: jq
55+
script: |
56+
STABLE_MIR_JSON=$(nix build --extra-experimental-features 'nix-command flakes' .#stable-mir-json --json | jq -r '.[].outputs | to_entries[].value')
57+
DRV=$(nix-store --query --deriver ${STABLE_MIR_JSON})
58+
nix-store --query --requisites --include-outputs ${DRV} | cachix push k-framework
59+
60+
nix-binary-cache:
61+
name: 'Populate Nix Binary Cache'
62+
strategy:
63+
matrix:
64+
runner: [normal, ARM64]
65+
runs-on: ${{ matrix.runner }}
66+
steps:
67+
- name: 'Check out code'
68+
uses: actions/checkout@v4
69+
with:
70+
ref: ${{ github.event.push.head.sha }}
71+
fetch-depth: 0
72+
73+
- name: 'Publish stable-mir-json to k-framework-binary cache'
74+
uses: workflow/nix-shell-action@v3
75+
env:
76+
CACHIX_AUTH_TOKEN: '${{ secrets.CACHIX_PRIVATE_KFB_TOKEN }}'
77+
GC_DONT_GC: '1'
78+
with:
79+
packages: jq
80+
script: |
81+
export PATH="$(nix build github:runtimeverification/kup --no-link --json | jq -r '.[].outputs | to_entries[].value')/bin:$PATH"
82+
kup publish k-framework-binary .#stable-mir-json --keep-days 180

.github/workflows/test.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ jobs:
4141
rustup component add rustfmt
4242
cargo fmt --check
4343
44+
- name: 'Install Nix'
45+
uses: cachix/[email protected]
46+
with:
47+
install_url: https://releases.nixos.org/nix/nix-2.30.1/install
48+
extra_nix_config: |
49+
substituters = https://cache.nixos.org
50+
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
51+
52+
- name: "Check `nixfmt`"
53+
run: |
54+
NIX_FILES=$(bash -O globstar -c 'ls **/*.nix')
55+
nix shell nixpkgs#nixfmt-rfc-style --command nixfmt --check ${NIX_FILES}
56+
4457
integration-tests:
4558
needs: code-quality
4659
name: "Integration tests"
@@ -106,3 +119,41 @@ jobs:
106119
- name: 'Run smir integration tests'
107120
run: |
108121
RUST_DIR_ROOT='rust' VERBOSE=1 make test-ui
122+
123+
nix:
124+
needs: code-quality
125+
name: 'Nix Tests'
126+
strategy:
127+
fail-fast: false
128+
matrix:
129+
runner: [normal, MacM1] # MacM1 / normal are self-hosted,
130+
runs-on: ${{ matrix.runner }}
131+
timeout-minutes: 20
132+
steps:
133+
- name: 'Check out code'
134+
uses: actions/checkout@v4
135+
with:
136+
# Check out pull request HEAD instead of merge commit.
137+
ref: ${{ github.event.pull_request.head.sha }}
138+
submodules: recursive
139+
140+
- name: 'Install Nix'
141+
if: ${{ matrix.runner != 'MacM1' }}
142+
uses: cachix/[email protected]
143+
with:
144+
install_url: https://releases.nixos.org/nix/nix-2.30.1/install
145+
extra_nix_config: |
146+
substituters = http://cache.nixos.org https://cache.iog.io
147+
trusted-public-keys = cache.nixos.org
148+
149+
- name: 'Install Cachix'
150+
if: ${{ matrix.runner != 'MacM1' }}
151+
uses: cachix/cachix-action@v16
152+
with:
153+
name: k-framework
154+
155+
- name: 'Build and test'
156+
run: |
157+
set -euxo pipefail
158+
nix --version
159+
nix flake check # build and run integration & unit tests
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
name: 'Update Version'
3+
on:
4+
push:
5+
branches:
6+
- '_update-deps/runtimeverification/rv-nix-tools'
7+
workflow_dispatch:
8+
# Stop in progress workflows on the same branch and same workflow to use latest committed code
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
update-versions:
15+
name: 'Update Dependency Versions'
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: 'Check out code'
19+
uses: actions/checkout@v3
20+
with:
21+
submodules: recursive
22+
token: ${{ secrets.JENKINS_GITHUB_PAT }}
23+
fetch-depth: 0
24+
- name: 'Configure GitHub user'
25+
run: |
26+
git config user.name devops
27+
git config user.email [email protected]
28+
- name: 'Install Nix'
29+
uses: cachix/[email protected]
30+
with:
31+
install_url: https://releases.nixos.org/nix/nix-2.30.1/install
32+
extra_nix_config: |
33+
substituters = http://cache.nixos.org https://cache.iog.io
34+
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=
35+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
36+
- uses: cachix/cachix-action@v16
37+
with:
38+
name: k-framework
39+
authToken: ${{ secrets.CACHIX_PUBLIC_TOKEN }}
40+
- name: 'Update Nix flake inputs'
41+
run: |
42+
RV_NIX_TOOLS_VERSION=$(cat deps/rv-nix-tools)
43+
sed -i 's! rv-nix-tools.url = "github:runtimeverification/rv-nix-tools/[a-z0-9\.]*"! rv-nix-tools.url = "github:runtimeverification/rv-nix-tools/'"${RV_NIX_TOOLS_VERSION}"'"!' flake.nix
44+
nix flake update
45+
git add flake.nix flake.lock && git commit -m 'flake.{nix,lock}: update Nix derivations' || true
46+
- name: 'Push updates'
47+
run: git push

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ golden:
4545

4646
format:
4747
cargo fmt
48+
bash -O globstar -c 'nixfmt **/*.nix'
4849

4950
style-check: format
5051
cargo clippy

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ There are a few environment variables that can be set to control the tools outpu
3838

3939
## Development
4040

41-
To ensure code quality, all code is required to pass `cargo clippy` and `cargo fmt` without warning to pass CI.
41+
To ensure code quality, all code is required to pass `cargo clippy`, `cargo fmt`, and `nixfmt **/*.nix` without warning to pass CI.
42+
43+
You can install `nixfmt` by [installing nix](https://nixos.org/download/) and running `nix profile install nixpkgs#nixfmt-rfc-style`.
4244

4345
## Tests
4446

deps/rv-nix-tools

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
854d4f05ea78547d46e807b414faad64cea10ae4

flake.lock

Lines changed: 105 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
description = "stable-mir-json development environment";
3+
4+
inputs = {
5+
rv-nix-tools.url = "github:runtimeverification/rv-nix-tools/854d4f05ea78547d46e807b414faad64cea10ae4";
6+
nixpkgs.follows = "rv-nix-tools/nixpkgs";
7+
8+
rust-overlay = {
9+
url = "github:oxalica/rust-overlay";
10+
inputs.nixpkgs.follows = "nixpkgs";
11+
};
12+
flake-utils = {
13+
url = "github:numtide/flake-utils";
14+
};
15+
};
16+
17+
outputs =
18+
{
19+
self,
20+
rv-nix-tools,
21+
nixpkgs,
22+
rust-overlay,
23+
flake-utils,
24+
}:
25+
flake-utils.lib.eachDefaultSystem (
26+
system:
27+
let
28+
overlays = [ (import rust-overlay) ];
29+
pkgs = import nixpkgs {
30+
inherit system overlays;
31+
};
32+
33+
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
34+
35+
stable-mir-json = pkgs.callPackage ./nix/stable-mir-json {
36+
inherit rustToolchain;
37+
};
38+
39+
stable-mir-json-integration-tests = pkgs.callPackage ./nix/test/integration.nix {
40+
inherit stable-mir-json;
41+
};
42+
in
43+
{
44+
packages = {
45+
inherit stable-mir-json;
46+
default = stable-mir-json;
47+
inherit rustToolchain;
48+
};
49+
50+
checks = {
51+
inherit stable-mir-json-integration-tests;
52+
stable-mir-json-unit-tests = stable-mir-json.overrideAttrs { doCheck = true; };
53+
};
54+
55+
devShells.default = pkgs.mkShell {
56+
buildInputs = with pkgs; [
57+
rustToolchain
58+
zlib
59+
jq
60+
gnumake
61+
];
62+
63+
env = {
64+
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
65+
};
66+
};
67+
}
68+
);
69+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
lib,
3+
nix-gitignore,
4+
}:
5+
6+
lib.cleanSource (
7+
nix-gitignore.gitignoreSourcePure [
8+
../../.gitignore
9+
".github/"
10+
"result*"
11+
# "/deps/"
12+
# do not include submodule directories that might be initilized empty or non-existent
13+
# -> there are none yet
14+
] ../../.
15+
)

0 commit comments

Comments
 (0)