patagia-control/flake.nix

159 lines
4.4 KiB
Nix
Raw Permalink Normal View History

2024-10-20 19:29:28 +02:00
{
inputs = {
2024-11-23 19:57:17 +01:00
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
crane.url = "github:ipetkov/crane";
2024-10-20 19:29:28 +02:00
flake-utils.url = "github:numtide/flake-utils";
2024-11-23 19:57:17 +01:00
nix-filter.url = "github:numtide/nix-filter";
2024-12-15 10:17:38 +01:00
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
2024-11-23 19:57:17 +01:00
rust-overlay.url = "github:oxalica/rust-overlay";
treefmt-nix.url = "github:numtide/treefmt-nix";
2024-10-20 19:29:28 +02:00
};
outputs =
{
self,
2024-11-23 19:57:17 +01:00
advisory-db,
crane,
2024-10-20 19:29:28 +02:00
flake-utils,
2024-11-23 19:57:17 +01:00
nix-filter,
2024-10-20 19:29:28 +02:00
nixpkgs,
2024-11-23 19:57:17 +01:00
rust-overlay,
treefmt-nix,
2024-10-20 19:29:28 +02:00
}:
flake-utils.lib.eachDefaultSystem (
system:
let
2024-12-15 11:53:40 +01:00
rustVersion = "1.83.0";
2024-11-23 19:57:17 +01:00
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;
2024-12-15 22:12:59 +01:00
src = pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [
./api.json
(craneLib.fileset.commonCargoSources ./.)
];
2024-11-23 19:57:17 +01:00
};
commonArgs = {
2024-12-15 22:12:59 +01:00
inherit src;
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv;
2024-11-23 19:57:17 +01:00
strictDeps = true;
2024-12-15 22:12:59 +01:00
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
nativeBuildInputs = with pkgs; [
clang
mold-wrapped
pkg-config
];
2024-12-14 22:47:40 +01:00
buildInputs = with pkgs; [
openssl
];
2024-11-23 19:57:17 +01:00
};
2024-12-15 22:12:59 +01:00
buildCrate =
name: path:
craneLib.buildPackage commonArgs
2024-11-23 19:57:17 +01:00
// {
2024-12-15 22:12:59 +01:00
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
doCheck = false; # We use cargo-nextest for all tests
pname = name;
cargoExtraArgs = "-p ${name}";
2024-12-14 22:47:40 +01:00
};
2024-12-15 22:12:59 +01:00
patagia-agent = buildCrate "patagia-agent" ./agent;
patagia-controller = buildCrate "patagia-controller" ./controller;
xtask = buildCrate "xtask" ./xtask;
2024-10-20 19:29:28 +02:00
in
{
2024-11-23 19:57:17 +01:00
packages = {
2024-12-11 21:12:24 +01:00
inherit patagia-agent patagia-controller xtask;
2024-11-23 19:57:17 +01:00
};
2024-10-20 19:29:28 +02:00
checks = {
2024-12-11 21:12:24 +01:00
inherit patagia-agent patagia-controller xtask;
2024-10-20 19:29:28 +02:00
2024-12-15 22:12:59 +01:00
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
'';
2024-10-20 19:29:28 +02:00
};
2024-12-15 22:12:59 +01:00
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;
2024-11-23 19:57:17 +01:00
2024-10-20 19:29:28 +02:00
devShells.default = pkgs.mkShell {
2024-12-15 22:12:59 +01:00
nativeBuildInputs = commonArgs.nativeBuildInputs;
buildInputs =
with pkgs;
[
bacon
cargo-edit
cargo-features-manager
cargo-hakari
cargo-machete
cargo-nextest
cargo-watch
hyperfine
just
rust-dev-toolchain
watchexec
]
++ commonArgs.buildInputs;
2024-12-14 22:47:40 +01:00
RUST_BACKTRACE = 1;
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; # Required for rust-analyzer
2024-10-20 19:29:28 +02:00
shellHook = ''
echo
2024-12-14 22:47:40 +01:00
echo "🛠 Welcome to the Patagia development environment 🛠"
2024-10-20 19:29:28 +02:00
echo "Run 'just' to see available commands."
echo
'';
};
}
);
}