runnable flake

This commit is contained in:
Anthony Cicchetti 2023-12-01 16:14:36 -05:00
parent bf60586c80
commit 1049feb012

170
flake.nix
View file

@ -23,117 +23,133 @@
}; };
}; };
outputs = { self, nixpkgs, crane, fenix, flake-utils, advisory-db, ... }: outputs = {
flake-utils.lib.eachDefaultSystem (system: self,
let nixpkgs,
pkgs = nixpkgs.legacyPackages.${system}; crane,
fenix,
flake-utils,
advisory-db,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib; inherit (pkgs) lib;
craneLib = crane.lib.${system}; craneLib = crane.lib.${system};
src = craneLib.cleanCargoSource (craneLib.path ./.); src = craneLib.cleanCargoSource (craneLib.path ./.);
# Common arguments can be set here to avoid repeating them later # Common arguments can be set here to avoid repeating them later
commonArgs = { commonArgs = {
inherit src; inherit src;
strictDeps = true; strictDeps = true;
buildInputs = [ buildInputs =
[
# Add additional build inputs here # Add additional build inputs here
] ++ lib.optionals pkgs.stdenv.isDarwin [ ]
++ lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here # Additional darwin specific inputs can be set here
pkgs.libiconv pkgs.libiconv
]; ];
# Additional environment variables can be set directly # Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value"; # MY_CUSTOM_VAR = "some value";
}; };
craneLibLLvmTools = craneLib.overrideToolchain craneLibLLvmTools =
(fenix.packages.${system}.complete.withComponents [ craneLib.overrideToolchain
"cargo" (fenix.packages.${system}.complete.withComponents [
"llvm-tools" "cargo"
"rustc" "llvm-tools"
]); "rustc"
]);
# Build *just* the cargo dependencies, so we can reuse # Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI # all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly commonArgs; cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual crate itself, reusing the dependency # Build the actual crate itself, reusing the dependency
# artifacts from above. # artifacts from above.
my-crate = craneLib.buildPackage (commonArgs // { my-crate = craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts; inherit cargoArtifacts;
cargoExtraArgs = "-p cli";
}); });
in in {
{ checks = {
checks = { # Build the crate as part of `nix flake check` for convenience
# Build the crate as part of `nix flake check` for convenience inherit my-crate;
inherit my-crate;
# Run clippy (and deny all warnings) on the crate source, # Run clippy (and deny all warnings) on the crate source,
# again, resuing the dependency artifacts from above. # again, resuing the dependency artifacts from above.
# #
# Note that this is done as a separate derivation so that # Note that this is done as a separate derivation so that
# we can block the CI if there are issues here, but not # we can block the CI if there are issues here, but not
# prevent downstream consumers from building our crate by itself. # prevent downstream consumers from building our crate by itself.
my-crate-clippy = craneLib.cargoClippy (commonArgs // { my-crate-clippy = craneLib.cargoClippy (commonArgs
// {
inherit cargoArtifacts; inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings"; cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}); });
my-crate-doc = craneLib.cargoDoc (commonArgs // { my-crate-doc = craneLib.cargoDoc (commonArgs
// {
inherit cargoArtifacts; inherit cargoArtifacts;
}); });
# Check formatting # Check formatting
my-crate-fmt = craneLib.cargoFmt { my-crate-fmt = craneLib.cargoFmt {
inherit src; inherit src;
}; };
# Audit dependencies # Audit dependencies
my-crate-audit = craneLib.cargoAudit { my-crate-audit = craneLib.cargoAudit {
inherit src advisory-db; inherit src advisory-db;
}; };
# Audit licenses # Audit licenses
my-crate-deny = craneLib.cargoDeny { my-crate-deny = craneLib.cargoDeny {
inherit src; inherit src;
}; };
# Run tests with cargo-nextest # Run tests with cargo-nextest
# Consider setting `doCheck = false` on `my-crate` if you do not want # Consider setting `doCheck = false` on `my-crate` if you do not want
# the tests to run twice # the tests to run twice
my-crate-nextest = craneLib.cargoNextest (commonArgs // { my-crate-nextest = craneLib.cargoNextest (commonArgs
// {
inherit cargoArtifacts; inherit cargoArtifacts;
partitions = 1; partitions = 1;
partitionType = "count"; partitionType = "count";
}); });
}; };
packages = { packages = {
default = my-crate; default = my-crate;
my-crate-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs // { my-crate-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs
// {
inherit cargoArtifacts; inherit cargoArtifacts;
}); });
}; };
apps.default = flake-utils.lib.mkApp { apps.default = flake-utils.lib.mkApp {
drv = my-crate; drv = my-crate;
}; name = "cli";
};
devShells.default = craneLib.devShell { devShells.default = craneLib.devShell {
# Inherit inputs from checks. # Inherit inputs from checks.
checks = self.checks.${system}; checks = self.checks.${system};
# Additional dev-shell environment variables can be set directly # Additional dev-shell environment variables can be set directly
# MY_CUSTOM_DEVELOPMENT_VAR = "something else"; # MY_CUSTOM_DEVELOPMENT_VAR = "something else";
# Extra inputs can be added here; cargo and rustc are provided by default. # Extra inputs can be added here; cargo and rustc are provided by default.
packages = [ packages = [
pkgs.sd pkgs.sd
# pkgs.ripgrep pkgs.alejandra
]; ];
}; };
}); });
} }