generated from Patagia/template-nix
chore(nix): Clean up flake.nix
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
This commit is contained in:
parent
4aff939cb1
commit
d8c8b7bb10
1 changed files with 70 additions and 123 deletions
193
flake.nix
193
flake.nix
|
@ -44,158 +44,105 @@
|
|||
|
||||
pkgs = import nixpkgs { inherit overlays system; };
|
||||
craneLib = (crane.mkLib pkgs).overrideToolchain pkgs.rust-toolchain;
|
||||
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv;
|
||||
|
||||
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;
|
||||
src = pkgs.lib.fileset.toSource {
|
||||
root = ./.;
|
||||
fileset = pkgs.lib.fileset.unions [
|
||||
./api.json
|
||||
(craneLib.fileset.commonCargoSources ./.)
|
||||
];
|
||||
};
|
||||
|
||||
commonArgs = {
|
||||
inherit src stdenv nativeBuildInputs;
|
||||
inherit src;
|
||||
|
||||
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv;
|
||||
strictDeps = true;
|
||||
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
|
||||
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
mold-wrapped
|
||||
pkg-config
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
openssl
|
||||
];
|
||||
};
|
||||
|
||||
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)
|
||||
];
|
||||
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 = 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";
|
||||
};
|
||||
|
||||
patagia-agent = buildCrate "patagia-agent" ./agent;
|
||||
patagia-controller = buildCrate "patagia-controller" ./controller;
|
||||
xtask = buildCrate "xtask" ./xtask;
|
||||
in
|
||||
{
|
||||
# `nix build`
|
||||
packages = {
|
||||
inherit patagia-agent patagia-controller xtask;
|
||||
};
|
||||
|
||||
# Tests
|
||||
checks = {
|
||||
inherit patagia-agent patagia-controller xtask;
|
||||
|
||||
clippy = craneLib.cargoClippy (
|
||||
commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||
}
|
||||
);
|
||||
audit = craneLib.cargoAudit (commonArgs // { inherit advisory-db; });
|
||||
|
||||
# fmt = craneLib.cargoFmt (commonArgs // { inherit src; });
|
||||
clippy = craneLib.cargoClippy commonArgs // {
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||
};
|
||||
|
||||
audit = craneLib.cargoAudit (commonArgs // { inherit src advisory-db; });
|
||||
fmt = craneLib.cargoFmt commonArgs;
|
||||
|
||||
nextest = craneLib.cargoNextest (
|
||||
commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
partitions = 1;
|
||||
partitionType = "count";
|
||||
}
|
||||
);
|
||||
nextest = craneLib.cargoNextest commonArgs // {
|
||||
partitions = 1;
|
||||
partitionType = "count";
|
||||
};
|
||||
|
||||
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
|
||||
'';
|
||||
openapi = pkgs.runCommand "openapi" commonArgs ''
|
||||
${self.packages.${system}.xtask}/bin/xtask open-api |
|
||||
${pkgs.diffutils}/bin/diff -u $src/api.json - |
|
||||
tee $out
|
||||
'';
|
||||
};
|
||||
|
||||
# For `nix fmt`
|
||||
formatter = treefmtEval.config.build.wrapper;
|
||||
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;
|
||||
|
||||
# `nix develop`
|
||||
devShells.default = pkgs.mkShell {
|
||||
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
|
||||
];
|
||||
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;
|
||||
RUST_BACKTRACE = 1;
|
||||
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; # Required for rust-analyzer
|
||||
shellHook = ''
|
||||
|
|
Loading…
Reference in a new issue