chore: add Nix Flake

Adds a `flake.nix` for building and testing the radicle-ci-broker using Nix.

Auditing and license denial configurations are also added as part of the `nix
flake check`s.

Note that one of the tests is ignore as part of the nextest check, since it
relies on using the Git repository itself. This is discouraged, since the check
runs in a sandboxed environment.
This commit is contained in:
Fintan Halpenny
2025-01-24 10:24:17 +00:00
parent 8cbc1fe313
commit ddac7386c9
4 changed files with 461 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
use flake
+1
View File
@@ -1,4 +1,5 @@
*.svg
*.html
/result
/target
doc/messages.md
Generated
+245
View File
@@ -0,0 +1,245 @@
{
"nodes": {
"advisory-db": {
"flake": false,
"locked": {
"lastModified": 1737246984,
"narHash": "sha256-cjWzMwqej9zVoFGV5NkefOspMDJJ+gN3+zkFZcBBAkc=",
"owner": "rustsec",
"repo": "advisory-db",
"rev": "cfd49ce116f12c856a3f3c065d041fd0dd7169dc",
"type": "github"
},
"original": {
"owner": "rustsec",
"repo": "advisory-db",
"type": "github"
}
},
"advisory-db_2": {
"flake": false,
"locked": {
"lastModified": 1722017365,
"narHash": "sha256-9wYR5NZIgI+qzMDlJrUzevR31fvFQRgfjlYp50Xp3Ts=",
"owner": "rustsec",
"repo": "advisory-db",
"rev": "9d024c07ee8c18609b43436bc865abf46636e250",
"type": "github"
},
"original": {
"owner": "rustsec",
"repo": "advisory-db",
"type": "github"
}
},
"crane": {
"locked": {
"lastModified": 1737250794,
"narHash": "sha256-bdIPhvsAKyYQzqAIeay4kOxTHGwLGkhM+IlBIsmMYFI=",
"owner": "ipetkov",
"repo": "crane",
"rev": "c5b7075f4a6d523fe8204618aa9754e56478c0e0",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"crane_2": {
"inputs": {
"nixpkgs": [
"radicle",
"nixpkgs"
]
},
"locked": {
"lastModified": 1722907532,
"narHash": "sha256-i/j/dMZPR7uJoQPFTa6UCahLu8kMtozYuR83lIKMERM=",
"owner": "ipetkov",
"repo": "crane",
"rev": "d0c8f4ed8571c533b31c1d68e4ebc534b790cc5c",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1737364209,
"narHash": "sha256-Vwr+QSD8YbonNMl1Xk4sT6yh+L1G+6kwZLUgrx4ibkc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e67b9736817530ccdd84797d8f3614b7750c74ae",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "release-24.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1722940684,
"narHash": "sha256-X8JnSq0ruRWsU4PdYuxV+8W4W66F1lnCcxIZZMWzo4E=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a3103d68517c6ad262ea27c96fc4a38ad81be7a0",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "release-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"radicle": {
"inputs": {
"advisory-db": "advisory-db_2",
"crane": "crane_2",
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1736859921,
"narHash": "sha256-i1Gn8JHhPKBG5IdP5GDI9NQtSWNWHIhBsOYl8aW+UVs=",
"ref": "refs/heads/master",
"rev": "ee0d19f2eb5744777ed717b8f8ec585e54aed4f0",
"revCount": 2177,
"type": "git",
"url": "https://seed.radicle.xyz/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git?tag=v1.1.0"
},
"original": {
"type": "git",
"url": "https://seed.radicle.xyz/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git?tag=v1.1.0"
}
},
"root": {
"inputs": {
"advisory-db": "advisory-db",
"crane": "crane",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"radicle": "radicle",
"rust-overlay": "rust-overlay_2"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": [
"radicle",
"nixpkgs"
]
},
"locked": {
"lastModified": 1722910815,
"narHash": "sha256-v6Vk/xlABhw2QzOa6xh3Jx/IvmlbKbOazFM+bDFQlWU=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "7df2ac544c203d21b63aac23bfaec7f9b919a733",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"rust-overlay_2": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1737340068,
"narHash": "sha256-5UciRckNV+YOZ6y6ASBIb01cySB12whDxgFUK+EqT8g=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "275c824ed9e90e7fd4f96d187bde3670062e721f",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"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"
}
},
"systems_2": {
"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
}
+214
View File
@@ -0,0 +1,214 @@
{
description = "Radicle CI Broker";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-24.11";
crane = {
url = "github:ipetkov/crane";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
radicle = {
url = "git+https://seed.radicle.xyz/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git?tag=v1.1.0";
};
flake-utils.url = "github:numtide/flake-utils";
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};
nixConfig = {
keepOutputs = true;
};
outputs = {
self,
nixpkgs,
crane,
flake-utils,
advisory-db,
radicle,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pname = "radicle-ci-broker";
lib = nixpkgs.lib;
pkgs = import nixpkgs {
inherit system;
overlays = [(import rust-overlay)];
};
rustToolChain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolChain;
srcFilters = path: type:
builtins.any (suffix: lib.hasSuffix suffix path) [
".subplot" # build and documentation
".md"
".yaml"
".css"
]
||
# Default filter from crane (allow .rs files)
(craneLib.filterCargoSources path type);
src = lib.cleanSourceWith {
src = ./.;
filter = srcFilters;
};
basicArgs = {
inherit src;
inherit pname;
strictDeps = true;
};
# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly basicArgs;
# Common arguments can be set here to avoid repeating them later
commonArgs =
basicArgs
// {
inherit cargoArtifacts;
nativeBuildInputs = with pkgs; [
git
# Add additional build inputs here
];
buildInputs = lib.optionals pkgs.stdenv.buildPlatform.isDarwin (with pkgs; [
darwin.apple_sdk.frameworks.Security
]);
};
radicle-ci-broker = craneLib.buildPackage (commonArgs
// {
inherit (craneLib.crateNameFromCargoToml {cargoToml = ./Cargo.toml;}) pname version;
doCheck = false;
});
bins = let
bin = {
name,
}:
craneLib.buildPackage (commonArgs
// {
inherit (craneLib.crateNameFromCargoToml {cargoToml = ./Cargo.toml;}) pname version;
cargoExtraArgs = "--bin ${name}";
doCheck = false;
});
bins = builtins.listToAttrs (map
({name, ...} @ package: lib.nameValuePair name (bin package))
[
{
name = "cibtool";
}
{
name = "cib";
}
{
name = "synthetic-events";
}
]);
in
bins
// rec {
default = radicle-ci-broker;
ci-broker = pkgs.buildEnv {
name = "ci-broker";
paths = with bins; [
cibtool
cib
synthetic-events
];
};
};
in {
# Formatter
formatter = pkgs.alejandra;
# Set of checks that are run: `nix flake check`
checks = {
# Run clippy (and deny all warnings) on the crate source,
# again, reusing the dependency artifacts from above.
#
# Note that this is done as a separate derivation so that
# we can block the CI if there are issues here, but not
# prevent downstream consumers from building our crate by itself.
clippy = craneLib.cargoClippy (commonArgs
// {
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
doc = craneLib.cargoDoc commonArgs;
fmt = craneLib.cargoFmt basicArgs;
# Run tests with cargo-nextest
nextest = craneLib.cargoNextest (commonArgs
// {
# We skip the test since it uses the underlying .git directory,
# which is not available in the Nix sandbox.
# In any case, this test is slow and we expect it to be tested
# before merges (and it can be tested in the devShell)
cargoNextestExtraArgs = "-- --skip acceptance_criteria_for_upgrades";
partitions = 1;
partitionType = "count";
nativeBuildInputs = [
pkgs.bash
pkgs.git
pkgs.jq
pkgs.sqlite
radicle.packages.${system}.radicle-cli
radicle.packages.${system}.radicle-remote-helper
];
# Ensure dev is used since we rely on env variables being
# set in tests.
env.CARGO_PROFILE = "dev";
});
};
packages.default = radicle-ci-broker;
apps.cibtool = flake-utils.lib.mkApp {
drv = self.bins.${system}.cibtool;
};
apps.cib = flake-utils.lib.mkApp {
drv = self.bins.${system}.cib;
};
apps.synthetic-events = flake-utils.lib.mkApp {
drv = self.bins.${system}.synthetic-events;
};
devShells.default = craneLib.devShell {
# Extra inputs can be added here; cargo and rustc are provided by default.
packages = with pkgs; [
bash
coreutils
cargo-watch
cargo-nextest
git
jq
ripgrep
rust-analyzer
sqlite
];
env.RUST_SRC_PATH = "${rustToolChain}/lib/rustlib/src/rust/library";
};
});
}