use crane for the flake

This commit is contained in:
Noa Aarts 2024-12-16 15:15:11 +01:00
parent 00ef4ca355
commit 0bda61cbcc
Signed by: noa
GPG key ID: 1850932741EFF672
5 changed files with 327 additions and 160 deletions

View file

@ -2,6 +2,7 @@
name = "flurry" name = "flurry"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
license = "AGPL-3.0"
[dependencies] [dependencies]
async-trait = "0.1.83" async-trait = "0.1.83"

View file

@ -1 +1 @@
-C target-cpu=native target-cpu = "native"

10
deny.toml Normal file
View file

@ -0,0 +1,10 @@
[licenses]
allow = [
"MIT",
"Apache-2.0",
"BSD-2-Clause",
"BSD-3-Clause",
"Unicode-3.0",
"Apache-2.0 WITH LLVM-exception",
"AGPL-3.0",
]

237
flake.lock generated
View file

@ -1,16 +1,80 @@
{ {
"nodes": { "nodes": {
"advisory-db": {
"flake": false,
"locked": {
"lastModified": 1733749954,
"narHash": "sha256-2Ug80Uf/oUujxgh02Iy5vTG0V+Ab9+YUHuRLRY0ayiY=",
"owner": "rustsec",
"repo": "advisory-db",
"rev": "ec9ce28714bb38d77a2223e7266df705500a7f11",
"type": "github"
},
"original": {
"owner": "rustsec",
"repo": "advisory-db",
"type": "github"
}
},
"advisory-db_2": {
"flake": false,
"locked": {
"lastModified": 1733749954,
"narHash": "sha256-2Ug80Uf/oUujxgh02Iy5vTG0V+Ab9+YUHuRLRY0ayiY=",
"owner": "rustsec",
"repo": "advisory-db",
"rev": "ec9ce28714bb38d77a2223e7266df705500a7f11",
"type": "github"
},
"original": {
"owner": "rustsec",
"repo": "advisory-db",
"type": "github"
}
},
"crane": {
"locked": {
"lastModified": 1734324364,
"narHash": "sha256-omYTR59TdH0AumP1cfh49fBnWZ52HjfdNfaLzCMZBx0=",
"owner": "ipetkov",
"repo": "crane",
"rev": "60d7623f1320470bf2fdb92fd2dca1e9a27b98ce",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"crane_2": {
"locked": {
"lastModified": 1734324364,
"narHash": "sha256-omYTR59TdH0AumP1cfh49fBnWZ52HjfdNfaLzCMZBx0=",
"owner": "ipetkov",
"repo": "crane",
"rev": "60d7623f1320470bf2fdb92fd2dca1e9a27b98ce",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"fenix": { "fenix": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs", "nixpkgs": [
"rust-analyzer-src": "rust-analyzer-src" "nixpkgs"
],
"rust-analyzer-src": []
}, },
"locked": { "locked": {
"lastModified": 1734157906, "lastModified": 1734331093,
"narHash": "sha256-4zYEtbxdhYkmmFC5vgv9pmIVHylEuKs+iJb1XsKDN7o=", "narHash": "sha256-9UrKDtqfLdsmDW4kRG/jSUAWot0jfL4WzcKA4nCvJZM=",
"owner": "nix-community", "owner": "nix-community",
"repo": "fenix", "repo": "fenix",
"rev": "06de03ede52ce64db6eb65be878a39b5ec944f50", "rev": "e39e49f3314f7dd09671094dc640b528ba2b1e4b",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -21,15 +85,20 @@
}, },
"fenix_2": { "fenix_2": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs_3", "nixpkgs": [
"rust-analyzer-src": "rust-analyzer-src_2" "tsunami",
"nixpkgs"
],
"rust-analyzer-src": [
"tsunami"
]
}, },
"locked": { "locked": {
"lastModified": 1733812506, "lastModified": 1734331093,
"narHash": "sha256-3fgFIijf23nKfJogpcEaUGky1W2BpOzpr0ljgx+cmOM=", "narHash": "sha256-9UrKDtqfLdsmDW4kRG/jSUAWot0jfL4WzcKA4nCvJZM=",
"owner": "nix-community", "owner": "nix-community",
"repo": "fenix", "repo": "fenix",
"rev": "0d8227f07b35ab04fee007fff4f9bb18c6d66af1", "rev": "e39e49f3314f7dd09671094dc640b528ba2b1e4b",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -38,122 +107,128 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs": { "flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": { "locked": {
"lastModified": 1733940404, "lastModified": 1731533236,
"narHash": "sha256-Pj39hSoUA86ZePPF/UXiYHHM7hMIkios8TYG29kQT4g=", "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "nixos", "owner": "numtide",
"repo": "nixpkgs", "repo": "flake-utils",
"rev": "5d67ea6b4b63378b9c13be21e2ec9d1afc921713", "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nixos", "owner": "numtide",
"ref": "nixos-unstable", "repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1734126203,
"narHash": "sha256-0XovF7BYP50rTD2v4r55tR5MuBLet7q4xIz6Rgh3BBU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "71a6392e367b08525ee710a93af2e80083b5b3e2",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1733940404, "lastModified": 1734126203,
"narHash": "sha256-Pj39hSoUA86ZePPF/UXiYHHM7hMIkios8TYG29kQT4g=", "narHash": "sha256-0XovF7BYP50rTD2v4r55tR5MuBLet7q4xIz6Rgh3BBU=",
"owner": "nixos", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "5d67ea6b4b63378b9c13be21e2ec9d1afc921713", "rev": "71a6392e367b08525ee710a93af2e80083b5b3e2",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nixos", "owner": "NixOS",
"ref": "nixos-unstable", "ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1733581040,
"narHash": "sha256-Qn3nPMSopRQJgmvHzVqPcE3I03zJyl8cSbgnnltfFDY=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "22c3f2cf41a0e70184334a958e6b124fb0ce3e01",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_4": {
"locked": {
"lastModified": 1733759999,
"narHash": "sha256-463SNPWmz46iLzJKRzO3Q2b0Aurff3U1n0nYItxq7jU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "a73246e2eef4c6ed172979932bc80e1404ba2d56",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"advisory-db": "advisory-db",
"crane": "crane",
"fenix": "fenix", "fenix": "fenix",
"nixpkgs": "nixpkgs_2", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"tsunami": "tsunami" "tsunami": "tsunami"
} }
}, },
"rust-analyzer-src": { "systems": {
"flake": false,
"locked": { "locked": {
"lastModified": 1734121833, "lastModified": 1681028828,
"narHash": "sha256-EZtwXmh9P9FnoXKfbjGxyWksjrjPB4HES2HVIV+STNg=", "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "rust-lang", "owner": "nix-systems",
"repo": "rust-analyzer", "repo": "default",
"rev": "fc18d263aa95f7d6de8174bd4c6663dfe865e6d5", "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "rust-lang", "owner": "nix-systems",
"ref": "nightly", "repo": "default",
"repo": "rust-analyzer",
"type": "github" "type": "github"
} }
}, },
"rust-analyzer-src_2": { "systems_2": {
"flake": false,
"locked": { "locked": {
"lastModified": 1733756789, "lastModified": 1681028828,
"narHash": "sha256-cK9hSImKm6FkMeIsdjzuRA1tjOKnXI1VHdmJbmpOYqI=", "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "rust-lang", "owner": "nix-systems",
"repo": "rust-analyzer", "repo": "default",
"rev": "99a6ecd41e5e458b3f4c2142b29a80d77ecda248", "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "rust-lang", "owner": "nix-systems",
"ref": "nightly", "repo": "default",
"repo": "rust-analyzer",
"type": "github" "type": "github"
} }
}, },
"tsunami": { "tsunami": {
"inputs": { "inputs": {
"advisory-db": "advisory-db_2",
"crane": "crane_2",
"fenix": "fenix_2", "fenix": "fenix_2",
"nixpkgs": "nixpkgs_4" "flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1734016882, "lastModified": 1734357001,
"narHash": "sha256-QqnrhOPgvykA+2a9iIzpOW8S3Ef8uA7aAFxcRqS8fB8=", "narHash": "sha256-NN/Eu7ZDJUsii7AKNk6wtRcuHkv5i3jxB0PC3HFqy8E=",
"owner": "itepastra", "owner": "itepastra",
"repo": "tsunami", "repo": "tsunami",
"rev": "872017618ae615152dc97b6379f5e92b175a55e9", "rev": "91e796c9886282f88bfab8df5f077a7df9800759",
"type": "github" "type": "github"
}, },
"original": { "original": {

217
flake.nix
View file

@ -1,99 +1,180 @@
{ {
description = "A pixelflut stress testing tool";
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane";
fenix = { fenix = {
url = "github:nix-community/fenix"; url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-analyzer-src.follows = "";
}; };
tsunami = { tsunami = {
url = "github:itepastra/tsunami"; url = "github:itepastra/tsunami";
}; };
flake-utils.url = "github:numtide/flake-utils";
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
}; };
outputs = outputs =
{ {
self, self,
fenix,
nixpkgs, nixpkgs,
crane,
fenix,
flake-utils,
tsunami, tsunami,
advisory-db,
... ...
}: }:
let flake-utils.lib.eachDefaultSystem (
allSystems = [
"x86_64-linux" # 64-bit Intel/AMD Linux
"aarch64-linux" # 64-bit ARM Linux
"x86_64-darwin" # 64-bit Intel macOS
"aarch64-darwin" # 64-bit ARM macOS
];
forAllSystems =
f:
nixpkgs.lib.genAttrs allSystems (
system: system:
f { let
inherit system; pkgs = nixpkgs.legacyPackages.${system};
inherit tsunami; tsu = tsunami.packages.${system};
pkgs = import nixpkgs { inherit system; };
fpkgs = import fenix { inherit system; }; inherit (pkgs) lib;
craneLib = (crane.mkLib pkgs).overrideToolchain (p: fenix.packages.${system}.complete.toolchain);
src = craneLib.cleanCargoSource ./.;
# Common arguments can be set here to avoid repeating them later
commonArgs = {
inherit src;
strictDeps = true;
buildInputs =
[
# Add additional build inputs here
]
++ lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
# Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value";
};
craneLibLLvmTools = craneLib.overrideToolchain (
fenix.packages.${system}.complete.withComponents [
"cargo"
"llvm-tools"
"rustc"
]
);
# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual crate itself, reusing the dependency
# artifacts from above.
flurry = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
} }
); );
in in
{ {
packages = forAllSystems ( checks = {
{ pkgs, fpkgs, ... }: # Build the crate as part of `nix flake check` for convenience
let inherit flurry;
toolchain = fpkgs.minimal.toolchain;
fs = pkgs.lib.fileset; # Run clippy (and deny all warnings) on the crate source,
in # again, reusing the dependency artifacts from above.
rec { #
# Note that this is done as a separate derivation so that
# we can block the CI if there are issues here, but not
# prevent downstream consumers from building our crate by itself.
flurry-clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
flurry-doc = craneLib.cargoDoc (
commonArgs
// {
inherit cargoArtifacts;
}
);
# Check formatting
flurry-fmt = craneLib.cargoFmt {
inherit src;
};
flurry-toml-fmt = craneLib.taploFmt {
src = pkgs.lib.sources.sourceFilesBySuffices src [ ".toml" ];
# taplo arguments can be further customized below as needed
# taploExtraArgs = "--config ./taplo.toml";
};
# Audit dependencies
flurry-audit = craneLib.cargoAudit {
inherit src advisory-db;
};
# Audit licenses
flurry-deny = craneLib.cargoDeny {
inherit src;
};
# Run tests with cargo-nextest
# Consider setting `doCheck = false` on `flurry` if you do not want
# the tests to run twice
flurry-nextest = craneLib.cargoNextest (
commonArgs
// {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
}
);
};
packages =
{
default = flurry; default = flurry;
flurry = }
(pkgs.makeRustPlatform { // lib.optionalAttrs (!pkgs.stdenv.isDarwin) {
cargo = toolchain; flurry-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (
rustc = toolchain; commonArgs
}).buildRustPackage // {
{ inherit cargoArtifacts;
pname = "flurry";
version = "0.1.0";
cargoLock.lockFile = ./Cargo.lock;
src = fs.toSource {
root = ./.;
fileset = fs.unions [
./Cargo.lock
./Cargo.toml
./src
./assets
];
};
};
} }
); );
devShells = forAllSystems ( };
{
pkgs, apps.default = flake-utils.lib.mkApp {
fpkgs, drv = flurry;
system, };
...
}: devShells.default = craneLib.devShell {
let # Inherit inputs from checks.
ffpkgs = fpkgs.complete; checks = self.checks.${system};
in
{ # Additional dev-shell environment variables can be set directly
default = pkgs.mkShell { # MY_CUSTOM_DEVELOPMENT_VAR = "something else";
buildInputs = [
ffpkgs.cargo # Extra inputs can be added here; cargo and rustc are provided by default.
ffpkgs.clippy packages = [
ffpkgs.rust-src
ffpkgs.rustc
ffpkgs.rustfmt
pkgs.gcc
pkgs.wgo pkgs.wgo
tsunami.packages.${system}.tsunami pkgs.cargo-flamegraph
tsu.default
]; ];
}; };
} }
); );
hydraJobs = {
devShell.x86_64-linux = self.devShells.x86_64-linux.default;
flurry.x86_64-linux = self.packages.x86_64-linux.flurry;
};
};
} }