generated from Patagia/template-nix
parent
7b273c7245
commit
af28c60984
14 changed files with 1596 additions and 66 deletions
169
flake.nix
169
flake.nix
|
@ -1,55 +1,174 @@
|
|||
{
|
||||
description = "My Project";
|
||||
|
||||
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.05";
|
||||
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
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
rustVersion = "1.81.0"; # Skipping 1.82 because of https://github.com/rust-lang/rust/issues/132064
|
||||
|
||||
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;
|
||||
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang_18
|
||||
mold
|
||||
];
|
||||
|
||||
sourceAndFixtures = path: type: (craneLib.filterCargoSources path type);
|
||||
src = pkgs.lib.cleanSourceWith {
|
||||
src = ./.;
|
||||
filter = sourceAndFixtures;
|
||||
};
|
||||
|
||||
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";
|
||||
};
|
||||
|
||||
commonArgs = {
|
||||
inherit src stdenv nativeBuildInputs;
|
||||
strictDeps = true;
|
||||
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
|
||||
};
|
||||
|
||||
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 [
|
||||
./Cargo.toml
|
||||
./Cargo.lock
|
||||
(craneLib.fileset.commonCargoSources ./agent)
|
||||
(craneLib.fileset.commonCargoSources ./controller)
|
||||
(craneLib.fileset.commonCargoSources crate)
|
||||
];
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
);
|
||||
|
||||
in
|
||||
{
|
||||
# Formatter for the Nix code
|
||||
formatter = pkgs.nixpkgs-fmt;
|
||||
|
||||
# Checks/tests for the project
|
||||
checks = {
|
||||
# FIXME: Add actual tests
|
||||
simple-test = pkgs.runCommand "simple-test" { } ''
|
||||
${self.packages.${system}.default}/bin/my-program
|
||||
touch $out
|
||||
'';
|
||||
};
|
||||
|
||||
# Packages
|
||||
# `nix build`
|
||||
packages = {
|
||||
my-program = pkgs.writeShellScriptBin "my-program" ''
|
||||
${pkgs.ddate}/bin/ddate +'Hello, world! Today is the %e of %B%, %Y' |
|
||||
${pkgs.cowsay}/bin/cowsay
|
||||
'';
|
||||
|
||||
default = self.packages.${system}.my-program;
|
||||
inherit patagia-agent patagia-controller;
|
||||
};
|
||||
|
||||
# Development shell
|
||||
# Tests
|
||||
checks = {
|
||||
inherit patagia-agent patagia-controller;
|
||||
|
||||
clippy = craneLib.cargoClippy (
|
||||
commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||
}
|
||||
);
|
||||
|
||||
fmt = craneLib.cargoFmt (commonArgs // { inherit src; });
|
||||
|
||||
audit = craneLib.cargoAudit (commonArgs // { inherit src advisory-db; });
|
||||
|
||||
nextest = craneLib.cargoNextest (
|
||||
commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
partitions = 1;
|
||||
partitionType = "count";
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
# For `nix fmt`
|
||||
formatter = treefmtEval.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
|
||||
just
|
||||
rust-dev-toolchain
|
||||
watchexec
|
||||
];
|
||||
shellHook = ''
|
||||
export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc} # Required for rust-analyzer
|
||||
echo
|
||||
echo "✨ Welcome to the My Project development environment! ✨"
|
||||
echo "✨ Welcome to the Patagia development environment! ✨"
|
||||
echo "Run 'just' to see available commands."
|
||||
echo
|
||||
'';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue