Skip to content

Instantly share code, notes, and snippets.

@jtojnar
Last active November 28, 2023 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtojnar/354218fa5b7e81897bbcb36a7b0730b7 to your computer and use it in GitHub Desktop.
Save jtojnar/354218fa5b7e81897bbcb36a7b0730b7 to your computer and use it in GitHub Desktop.
Attempt at packagin kani with fenix https://github.com/model-checking/kani
{
"nodes": {
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1701066187,
"narHash": "sha256-WP2sUVcjM4uuCBnw2r++6Rnuqzd4iZ7oh/o7AarPjIM=",
"owner": "nix-community",
"repo": "fenix",
"rev": "bec77b7f219319a49dc1885490236714b023d19c",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1700794826,
"narHash": "sha256-RyJTnTNKhO0yqRpDISk03I/4A67/dp96YRxc86YOPgU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5a09cb4b393d58f9ed0d9ca1555016a8543c2ac8",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"fenix": "fenix",
"nixpkgs": "nixpkgs",
"systems": "systems"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1700997114,
"narHash": "sha256-pOz99NESIGosyt19tqNw7gfS6NQJtFY0kGF3rFV0bZ0=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "237712fa314237e428e7ef2ab83b979f928a43a1",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
systems.url = "github:nix-systems/default";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
nixConfig = {
extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
extra-substituters = "https://devenv.cachix.org";
};
outputs = { self, nixpkgs, systems, fenix } @ inputs:
let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
in
{
packages = forEachSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
fenix.overlays.default
];
};
fenixToolchain = pkgs.fenix.complete;
in
{
kaniFenix = pkgs.callPackage ./kani.nix {
inherit (fenixToolchain) rust-src rustc-dev llvm-tools-preview toolchain;
rustPlatform = pkgs.makeRustPlatform {
cargo = fenixToolchain.toolchain;
rustc = fenixToolchain.toolchain;
};
};
kaniNixpkgs = pkgs.callPackage ./kani.nix {
toolchain = pkgs.rustPlatform.rustLibSrc;
rust-src = pkgs.rustPlatform.rustLibSrc;
rustc-dev = "";
};
kaniFhs = pkgs.callPackage ./kani-fhs.nix { };
});
};
}
{
buildFHSEnv,
rustup,
rustc,
cargo,
gcc,
python3,
}:
buildFHSEnv {
name = "kani-env";
targetPkgs = _pkgs: [
rustup
rustc
cargo
gcc
(python3.withPackages (pp: [
pp.pip
]))
];
multiPkgs = null;
runScript = ''
sh -c '
export HOME=/tmp/kani-home
if [[ ! -d "$HOME" ]]; then
mkdir -p "$HOME"
rustup default stable
cargo install --locked kani-verifier
cargo kani setup
fi
exec ''${SHELL:bash}
'
'';
}
{ lib
, rustPlatform
, fetchFromGitHub
, toolchain
, rust-src
, rustc-dev
}:
rustPlatform.buildRustPackage rec {
pname = "kani";
version = "0.41.0";
src = fetchFromGitHub {
owner = "model-checking";
repo = "kani";
rev = "kani-${version}";
hash = "sha256-egxEh97LXJDI9PtECxls0pok7ElF/bjri+KhCSR9o8c=";
};
cargoHash = "sha256-ow/ioCQ4cGFKEzn3WI8Fi4sBXgGchTXA+/Myv5rnZF0=";
env = lib.traceValSeq {
# kani-compiler expects Nightly compiler installed through rustup.
RUSTUP_HOME = "${toolchain}";
RUSTUP_TOOLCHAIN = "..";
# Allow nightly features on stable compiler.
RUSTC_BOOTSTRAP = 1;
# RUST_SRC_PATH = "${rust-src}/lib/rustlib/src/rust/library";
# RUST_SRC_PATH = "${rustc-dev}/lib/rustlib/rustc-src/rust/compiler";
};
meta = with lib; {
description = "Kani Rust Verifier";
homepage = "https://github.com/model-checking/kani";
changelog = "https://github.com/model-checking/kani/blob/${src.rev}/CHANGELOG.md";
license = with licenses; [ asl20 mit ];
maintainers = with maintainers; [ jtojnar ];
mainProgram = "kani";
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment