use crane.dev
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
.direnv
|
.direnv
|
||||||
|
result
|
||||||
|
|||||||
83
flake.lock
generated
83
flake.lock
generated
@@ -1,25 +1,92 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"advisory-db": {
|
||||||
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1766651565,
|
"lastModified": 1767002661,
|
||||||
"narHash": "sha256-QEhk0eXgyIqTpJ/ehZKg9IKS7EtlWxF3N7DXy42zPfU=",
|
"narHash": "sha256-br63iHn1Hk6YHrqpBkIJJg2KRmyr4cpnuN34ECp7Nds=",
|
||||||
"owner": "nixos",
|
"owner": "rustsec",
|
||||||
"repo": "nixpkgs",
|
"repo": "advisory-db",
|
||||||
"rev": "3e2499d5539c16d0d173ba53552a4ff8547f4539",
|
"rev": "0a2867a9751df525d974f195c293c3d19491640e",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "nixos",
|
"owner": "rustsec",
|
||||||
"ref": "nixos-unstable",
|
"repo": "advisory-db",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"crane": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1766774972,
|
||||||
|
"narHash": "sha256-8qxEFpj4dVmIuPn9j9z6NTbU+hrcGjBOvaxTzre5HmM=",
|
||||||
|
"owner": "ipetkov",
|
||||||
|
"repo": "crane",
|
||||||
|
"rev": "01bc1d404a51a0a07e9d8759cd50a7903e218c82",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "ipetkov",
|
||||||
|
"repo": "crane",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"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": 1766870016,
|
||||||
|
"narHash": "sha256-fHmxAesa6XNqnIkcS6+nIHuEmgd/iZSP/VXxweiEuQw=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "5c2bc52fb9f8c264ed6c93bd20afa2ff5e763dce",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
"advisory-db": "advisory-db",
|
||||||
|
"crane": "crane",
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|||||||
159
flake.nix
159
flake.nix
@@ -1,31 +1,152 @@
|
|||||||
{
|
{
|
||||||
|
description = "Build a cargo project";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
|
|
||||||
|
crane.url = "github:ipetkov/crane";
|
||||||
|
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
|
||||||
|
advisory-db = {
|
||||||
|
url = "github:rustsec/advisory-db";
|
||||||
|
flake = false;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
{
|
{
|
||||||
self,
|
self,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
|
crane,
|
||||||
|
flake-utils,
|
||||||
|
advisory-db,
|
||||||
...
|
...
|
||||||
}@inputs:
|
}:
|
||||||
let
|
flake-utils.lib.eachDefaultSystem (
|
||||||
system = "x86_64-linux";
|
system:
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
let
|
||||||
in
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
{
|
|
||||||
devShells.${system}.default =
|
inherit (pkgs) lib;
|
||||||
let
|
|
||||||
pkgs = import nixpkgs { inherit system; };
|
craneLib = crane.mkLib pkgs;
|
||||||
in
|
src = craneLib.cleanCargoSource ./.;
|
||||||
pkgs.mkShell {
|
|
||||||
packages = with pkgs; [
|
# Common arguments can be set here to avoid repeating them later
|
||||||
cargo
|
commonArgs = {
|
||||||
rustc
|
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
|
||||||
];
|
];
|
||||||
shellHook = ''
|
|
||||||
echo "Meow!!"
|
# Additional environment variables can be set directly
|
||||||
'';
|
# MY_CUSTOM_VAR = "some value";
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
# 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.
|
||||||
|
laptop-dashboard = craneLib.buildPackage (
|
||||||
|
commonArgs
|
||||||
|
// {
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
checks = {
|
||||||
|
# Build the crate as part of `nix flake check` for convenience
|
||||||
|
inherit laptop-dashboard;
|
||||||
|
|
||||||
|
# Run clippy (and deny all warnings) on the crate source,
|
||||||
|
# again, reusing the dependency artifacts from above.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
laptop-dashboard-clippy = craneLib.cargoClippy (
|
||||||
|
commonArgs
|
||||||
|
// {
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
laptop-dashboard-doc = craneLib.cargoDoc (
|
||||||
|
commonArgs
|
||||||
|
// {
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
# This can be commented out or tweaked as necessary, e.g. set to
|
||||||
|
# `--deny rustdoc::broken-intra-doc-links` to only enforce that lint
|
||||||
|
env.RUSTDOCFLAGS = "--deny warnings";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
# Check formatting
|
||||||
|
laptop-dashboard-fmt = craneLib.cargoFmt {
|
||||||
|
inherit src;
|
||||||
|
};
|
||||||
|
|
||||||
|
laptop-dashboard-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
|
||||||
|
laptop-dashboard-audit = craneLib.cargoAudit {
|
||||||
|
inherit src advisory-db;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Audit licenses
|
||||||
|
laptop-dashboard-deny = craneLib.cargoDeny {
|
||||||
|
inherit src;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Run tests with cargo-nextest
|
||||||
|
# Consider setting `doCheck = false` on `laptop-dashboard` if you do not want
|
||||||
|
# the tests to run twice
|
||||||
|
laptop-dashboard-nextest = craneLib.cargoNextest (
|
||||||
|
commonArgs
|
||||||
|
// {
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
partitions = 1;
|
||||||
|
partitionType = "count";
|
||||||
|
cargoNextestPartitionsExtraArgs = "--no-tests=pass";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
packages = {
|
||||||
|
default = laptop-dashboard;
|
||||||
|
};
|
||||||
|
|
||||||
|
apps.default = flake-utils.lib.mkApp {
|
||||||
|
drv = laptop-dashboard;
|
||||||
|
};
|
||||||
|
|
||||||
|
devShells.default = craneLib.devShell {
|
||||||
|
# Inherit inputs from checks.
|
||||||
|
checks = self.checks.${system};
|
||||||
|
|
||||||
|
# Additional dev-shell environment variables can be set directly
|
||||||
|
# MY_CUSTOM_DEVELOPMENT_VAR = "something else";
|
||||||
|
|
||||||
|
# Extra inputs can be added here; cargo and rustc are provided by default.
|
||||||
|
packages = [
|
||||||
|
# pkgs.ripgrep
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user