Compare commits

..

No commits in common. "d8c8b7bb10cbbcf5cddad6ae19509eb1ed205fec" and "62377e372f73d2d8c36b6710b247d27a4c3d818d" have entirely different histories.

3 changed files with 123 additions and 79 deletions

View file

@ -1,10 +1,2 @@
[alias]
xtask = "run --package xtask --quiet --"
[profile.dev]
debug = 0
strip = "debuginfo"
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=mold", "-C", "target-cpu=native"]

View file

@ -1,3 +1,2 @@
nix_direnv_manual_reload
use flake
dotenv_if_exists

193
flake.nix
View file

@ -44,105 +44,158 @@
pkgs = import nixpkgs { inherit overlays system; };
craneLib = (crane.mkLib pkgs).overrideToolchain pkgs.rust-toolchain;
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv;
src = pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [
./api.json
(craneLib.fileset.commonCargoSources ./.)
];
nativeBuildInputs = with pkgs; [
clang_18
mold
pkg-config
];
jsonFilter = path: _type: builtins.match ".*json$" path != null;
sourceAndFixtures = path: type:
(jsonFilter path type) || (craneLib.filterCargoSources path type);
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter = sourceAndFixtures;
};
commonArgs = {
inherit src;
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv;
inherit src stdenv nativeBuildInputs;
strictDeps = true;
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
nativeBuildInputs = with pkgs; [
clang
mold-wrapped
pkg-config
];
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
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}";
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
individualCrateArgs = commonArgs // {
inherit cargoArtifacts;
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
doCheck = false; # We use cargo-nextest for all tests
};
fileSetForCrate =
crate:
pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [
./api.json
./Cargo.toml
./Cargo.lock
(craneLib.fileset.commonCargoSources ./agent)
(craneLib.fileset.commonCargoSources ./controller)
(craneLib.fileset.commonCargoSources ./xtask)
(craneLib.fileset.commonCargoSources crate)
];
};
patagia-agent = buildCrate "patagia-agent" ./agent;
patagia-controller = buildCrate "patagia-controller" ./controller;
xtask = buildCrate "xtask" ./xtask;
patagia-agent = craneLib.buildPackage (
individualCrateArgs
// {
pname = "patagia-agent";
cargoExtraArgs = "-p patagia-agent";
src = fileSetForCrate ./agent;
}
);
patagia-controller = craneLib.buildPackage (
individualCrateArgs
// {
pname = "patagia-controller";
cargoExtraArgs = "-p patagia-controller";
src = fileSetForCrate ./controller;
}
);
xtask = craneLib.buildPackage (
individualCrateArgs
// {
pname = "xtask";
cargoExtraArgs = "-p xtask";
src = fileSetForCrate ./xtask;
}
);
treefmtEval = 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";
};
in
{
# `nix build`
packages = {
inherit patagia-agent patagia-controller xtask;
};
# Tests
checks = {
inherit patagia-agent patagia-controller xtask;
audit = craneLib.cargoAudit (commonArgs // { inherit advisory-db; });
clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
clippy = craneLib.cargoClippy commonArgs // {
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
};
# fmt = craneLib.cargoFmt (commonArgs // { inherit src; });
fmt = craneLib.cargoFmt commonArgs;
audit = craneLib.cargoAudit (commonArgs // { inherit src advisory-db; });
nextest = craneLib.cargoNextest commonArgs // {
partitions = 1;
partitionType = "count";
};
nextest = craneLib.cargoNextest (
commonArgs
// {
inherit cargoArtifacts;
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
'';
openapi =
pkgs.runCommand "openapi"
(
commonArgs
// {
inherit cargoArtifacts;
src = fileSetForCrate ./xtask;
}
)
''
${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;
# For `nix fmt`
formatter = treefmtEval.config.build.wrapper;
# `nix develop`
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
rust-dev-toolchain
watchexec
]
++ commonArgs.buildInputs;
inherit nativeBuildInputs;
buildInputs = with pkgs; [
bacon
cargo-edit
cargo-features-manager
cargo-hakari
cargo-machete
cargo-nextest
cargo-watch
hyperfine
openssl
just
rust-dev-toolchain
watchexec
];
RUST_BACKTRACE = 1;
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; # Required for rust-analyzer
shellHook = ''