Skip to content

Nix flake & CI #3

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

Merged
merged 11 commits into from
May 7, 2024
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "CI"
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build:
strategy:
matrix:
min-version: [true, false]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v26
with:
nix_path: nixpkgs=channel:nixos-unstable
- if: ${{ matrix.min-version }}
run: nix develop . -c cargo update -Z direct-minimal-versions
- run: nix flake check --keep-going --print-build-logs
10 changes: 10 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).defaultNix
166 changes: 166 additions & 0 deletions flake.lock

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

86 changes: 86 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
description = "Development environment";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
flakelight.url = "github:nix-community/flakelight";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay.url = "github:oxalica/rust-overlay";
};

outputs = { flakelight, ... } @ inputs: flakelight ./. {
inherit inputs;
withOverlays = [
inputs.rust-overlay.overlays.default
(final: { inputs', lib, rust-bin, ... }:
let
# version:
# "latest" => latest stable
# "nightly" => latest nightly
# "1.61.0" => specific stable version
craneLib = version: inputs'.crane.lib.overrideToolchain (if version == "nightly" then rust-bin.nightly.latest.default else rust-bin.stable.${version}.default);
commonArgs = {
src = ./.;
pname = "antithesis-sdk-rust-workspace";
version = "0.0.0";
};
workspaceDeps = version: (craneLib version).buildDepsOnly commonArgs;
workspace = version: (craneLib version).buildPackage (commonArgs // {
cargoArtifacts = workspaceDeps version;
});
clippy = version: (craneLib version).cargoClippy (commonArgs // {
cargoArtifacts = workspaceDeps version;
cargoClippyExtraArgs = "--all-targets -- -D warnings";
});
test = version: (craneLib version).cargoTest (commonArgs // {
cargoArtifacts = workspaceDeps version;
});
doc = version: (craneLib version).cargoDoc (commonArgs // {
cargoArtifacts = workspaceDeps version;
});
in
{
inherit craneLib workspaceDeps;
antithesis-sdk-rust = {
workspace = workspace "nightly";
workspaceMSRV = workspace (lib.importTOML ./lib/Cargo.toml).package.rust-version;
clippy = clippy "nightly";
test = test "nightly";
doc = doc "nightly";
};
})
];

packages = rec {
default = workspace;
workspace = { antithesis-sdk-rust }: antithesis-sdk-rust.workspace;
doc = { antithesis-sdk-rust }: antithesis-sdk-rust.doc;
};

apps = rec {
default = simple;
simple = pkgs: "${pkgs.antithesis-sdk-rust-workspace}/bin/simple";
};

devShells.default = pkgs: {
inputsFrom = with pkgs; [ antithesis-sdk-rust.workspace ];
packages = with pkgs; [ rust-analyzer cargo-msrv ];
};

# TODO: Check combinations of feature flags & semver check.
checks = { antithesis-sdk-rust, ... }: {
inherit (antithesis-sdk-rust) workspaceMSRV clippy test;
};

formatters = pkgs: {
"*.rs" = "${pkgs.rustfmt}/bin/rustfmt";
"*.nix" = "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt";
};

flakelight.builtinFormatters = false;
};
}
2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
rust-version = "1.62.1"

[dependencies]
serde = { version = "1.0.103", features = ["derive"] }
serde = { version = "1.0.113", features = ["derive"] }
serde_json = "1.0.25"
libloading = "0.8"
libc = "0.2.64"
Expand Down
Loading
Loading