generated from Patagia/template-nix
153 lines
4.2 KiB
Nix
153 lines
4.2 KiB
Nix
{
|
|
inputs = {
|
|
advisory-db = {
|
|
url = "github:rustsec/advisory-db";
|
|
flake = false;
|
|
};
|
|
crane.url = "github:ipetkov/crane";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
nix-filter.url = "github:numtide/nix-filter";
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
|
|
rust-overlay.url = "github:oxalica/rust-overlay";
|
|
treefmt-nix.url = "github:numtide/treefmt-nix";
|
|
};
|
|
|
|
outputs =
|
|
{
|
|
self,
|
|
advisory-db,
|
|
crane,
|
|
flake-utils,
|
|
nix-filter,
|
|
nixpkgs,
|
|
rust-overlay,
|
|
treefmt-nix,
|
|
}:
|
|
flake-utils.lib.eachDefaultSystem (
|
|
system:
|
|
let
|
|
rustVersion = "1.83.0";
|
|
|
|
overlays = [
|
|
(import rust-overlay)
|
|
(final: prev: {
|
|
nix-filter = nix-filter.lib;
|
|
rust-toolchain = pkgs.rust-bin.stable.${rustVersion}.default;
|
|
rust-dev-toolchain = pkgs.rust-toolchain.override {
|
|
extensions = [
|
|
"rust-analyzer"
|
|
"rust-src"
|
|
];
|
|
};
|
|
})
|
|
];
|
|
|
|
pkgs = import nixpkgs { inherit overlays system; };
|
|
craneLib = (crane.mkLib pkgs).overrideToolchain pkgs.rust-toolchain;
|
|
|
|
src = pkgs.lib.fileset.toSource {
|
|
root = ./.;
|
|
fileset = pkgs.lib.fileset.unions [
|
|
./api.json
|
|
(craneLib.fileset.commonCargoSources ./.)
|
|
];
|
|
};
|
|
|
|
commonArgs = {
|
|
inherit src;
|
|
|
|
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv;
|
|
strictDeps = true;
|
|
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
|
|
|
nativeBuildInputs = with pkgs; [
|
|
clang
|
|
mold-wrapped
|
|
pkg-config
|
|
];
|
|
|
|
buildInputs = with pkgs; [
|
|
openssl
|
|
];
|
|
};
|
|
|
|
buildCrate =
|
|
name: path:
|
|
craneLib.buildPackage commonArgs
|
|
// {
|
|
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
|
|
doCheck = false; # We use cargo-nextest for all tests
|
|
pname = name;
|
|
cargoExtraArgs = "-p ${name}";
|
|
};
|
|
|
|
patagia-agent = buildCrate "patagia-agent" ./agent;
|
|
patagia-controller = buildCrate "patagia-controller" ./controller;
|
|
xtask = buildCrate "xtask" ./xtask;
|
|
in
|
|
{
|
|
packages = {
|
|
inherit patagia-agent patagia-controller xtask;
|
|
};
|
|
|
|
checks = {
|
|
inherit patagia-agent patagia-controller xtask;
|
|
|
|
audit = craneLib.cargoAudit (commonArgs // { inherit advisory-db; });
|
|
|
|
clippy = craneLib.cargoClippy commonArgs // {
|
|
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
|
};
|
|
|
|
fmt = craneLib.cargoFmt commonArgs;
|
|
|
|
nextest = craneLib.cargoNextest commonArgs // {
|
|
partitions = 1;
|
|
partitionType = "count";
|
|
};
|
|
|
|
openapi = pkgs.runCommand "openapi" commonArgs ''
|
|
${self.packages.${system}.xtask}/bin/xtask open-api |
|
|
${pkgs.diffutils}/bin/diff -u $src/api.json - |
|
|
tee $out
|
|
'';
|
|
};
|
|
|
|
formatter =
|
|
(treefmt-nix.lib.evalModule pkgs {
|
|
projectRootFile = "flake.nix";
|
|
programs = {
|
|
nixfmt.enable = true;
|
|
nixfmt.package = pkgs.nixfmt-rfc-style;
|
|
shfmt.enable = true;
|
|
rustfmt.enable = true;
|
|
};
|
|
settings.formatter.rustfmt.command = pkgs.lib.mkForce "${pkgs.rust-toolchain}/bin/rustfmt";
|
|
}).config.build.wrapper;
|
|
|
|
devShells.default = pkgs.mkShell {
|
|
nativeBuildInputs = commonArgs.nativeBuildInputs;
|
|
buildInputs =
|
|
with pkgs;
|
|
[
|
|
bacon
|
|
cargo-edit
|
|
cargo-features-manager
|
|
cargo-hakari
|
|
cargo-machete
|
|
cargo-nextest
|
|
cargo-watch
|
|
hyperfine
|
|
just
|
|
nixfmt-rfc-style
|
|
rust-dev-toolchain
|
|
watchexec
|
|
]
|
|
++ commonArgs.buildInputs;
|
|
RUST_BACKTRACE = 1;
|
|
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; # Required for rust-analyzer
|
|
};
|
|
|
|
}
|
|
);
|
|
}
|