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

ci: use nix devshell #108

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install Nix
uses: cachix/install-nix-action@v27

- name: Install Rust (${{ matrix.toolchain.name }})
uses: actions-rust-lang/[email protected]
with:
toolchain: ${{ matrix.toolchain.version }}

- name: Install just, nextest
uses: taiki-e/[email protected]
with:
tool: just,nextest
- name: Enter Nix devshell
uses: nicknovitski/[email protected]

- name: workaround MSRV issues
if: matrix.toolchain.name == 'msrv'
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ jobs:
with:
components: llvm-tools-preview

- name: Install just & cargo-llvm-cov
- name: Enter Nix devshell
uses: nicknovitski/[email protected]

- name: Install cargo-llvm-cov
uses: taiki-e/[email protected]
with:
tool: just,cargo-llvm-cov
tool: cargo-llvm-cov

- name: Generate code coverage
run: just test-coverage-codecov
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install Nix
uses: cachix/install-nix-action@v27

- name: Install Rust
uses: actions-rust-lang/[email protected]
with:
components: clippy

- name: Install just & cargo-hack
uses: taiki-e/[email protected]
with:
tool: just,cargo-hack
- name: Enter Nix devshell
uses: nicknovitski/[email protected]

- name: Clippy
run: just clippy
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
/target/
Cargo.lock

# x52 toolchain
/.toolchain/

# direnv
/.direnv/

Expand Down
61 changes: 40 additions & 21 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 40 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-parts.url = "github:hercules-ci/flake-parts";
x52 = {
url = "github:x52dev/nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-parts.follows = "flake-parts";
};
};

outputs = inputs@{ flake-parts, ... }:
outputs = inputs @ { flake-parts, x52, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
perSystem = { pkgs, config, inputs', system, lib, ... }: {
formatter = pkgs.nixpkgs-fmt;
perSystem = { pkgs, config, inputs', system, lib, ... }:
let
x52just = inputs'.x52.packages.x52-just;
in
{
formatter = pkgs.nixpkgs-fmt;

devShells.default = pkgs.mkShell {
buildInputs = [ x52just ];

packages = [
# scripting
pkgs.just

# cargo plugins
pkgs.cargo-hack
pkgs.cargo-nextest

# formatters
config.formatter
pkgs.nodePackages.prettier
pkgs.taplo
] ++ lib.optional pkgs.stdenv.isDarwin [
pkgs.pkgsBuildHost.libiconv
pkgs.pkgsBuildHost.darwin.apple_sdk.frameworks.Security
pkgs.pkgsBuildHost.darwin.apple_sdk.frameworks.CoreFoundation
pkgs.pkgsBuildHost.darwin.apple_sdk.frameworks.SystemConfiguration
];

devShells.default = pkgs.mkShell {
packages = [
config.formatter
pkgs.nodePackages.prettier
pkgs.taplo
pkgs.just
] ++ lib.optional pkgs.stdenv.isDarwin [
pkgs.pkgsBuildHost.libiconv
pkgs.pkgsBuildHost.darwin.apple_sdk.frameworks.Security
pkgs.pkgsBuildHost.darwin.apple_sdk.frameworks.CoreFoundation
pkgs.pkgsBuildHost.darwin.apple_sdk.frameworks.SystemConfiguration
];
shellHook = ''
mkdir -p .toolchain
cp ${x52just}/*.just .toolchain/
'';
};
};
};
};
}
29 changes: 13 additions & 16 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import '.toolchain/rust.just'

_list:
@just --list

# Format project
fmt:
just --unstable --fmt
nixpkgs-fmt .
fd --hidden --type=file --extension=md --extension=yml --exec-batch prettier --write
fd --hidden --extension=toml --exec-batch taplo format
cargo +nightly fmt

# Lint workspace with Clippy
clippy:
cargo clippy --workspace --no-default-features
cargo clippy --workspace --no-default-features --all-features
cargo hack --feature-powerset --depth=3 clippy --workspace

msrv := ```
cargo metadata --format-version=1 \
| jq -r 'first(.packages[] | select(.source == null and .rust_version)) | .rust_version' \
| sed -E 's/^1\.([0-9]{2})$/1\.\1\.0/'
```
msrv_rustup := "+" + msrv

# Downgrade dev-dependencies necessary to run MSRV checks/tests.
[private]
downgrade-msrv:
Expand Down Expand Up @@ -58,13 +61,7 @@ doc-watch:
# Check project
check:
just --unstable --fmt --check
prettier --check $(fd --type=file --hidden --extension=md --extension=yml)
taplo lint $(fd --hidden --extension=toml)
fd --hidden --type=file --extension=md --extension=yml --exec-batch prettier --check
fd --hidden --extension=toml --exec-batch taplo format --check
fd --hidden --extension=toml --exec-batch taplo lint
cargo +nightly fmt -- --check

# Format project
fmt:
just --unstable --fmt
prettier --write $(fd --type=file --hidden --extension=md --extension=yml)
taplo format $(fd --hidden --extension=toml)
cargo +nightly fmt