chore: use fenix and flake-parts

This commit is contained in:
Callum Leslie 2024-09-11 08:56:22 +01:00
parent fb22da828f
commit cae2526833
Signed by: cleslie
GPG key ID: D382C4AFEECEAA90
2 changed files with 120 additions and 72 deletions

91
flake.lock generated
View file

@ -31,21 +31,45 @@
"type": "github"
}
},
"flake-utils": {
"fenix": {
"inputs": {
"systems": "systems"
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"lastModified": 1725437390,
"narHash": "sha256-W2ZnHE+FkPVap5Em6na4KP8XkhU8kpY07iX0d4+y4uM=",
"owner": "nix-community",
"repo": "fenix",
"rev": "29ad6b2023ccec4d4679244c233f0ea875cdf000",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"owner": "nix-community",
"ref": "pull/163/head",
"repo": "fenix",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1725234343,
"narHash": "sha256-+ebgonl3NbiKD2UD0x4BszCZQ6sTfL4xioaM49o5B3Y=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "567b938d64d4b4112ee253b9274472dc3a346eb6",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
@ -69,28 +93,27 @@
"inputs": {
"advisory-db": "advisory-db",
"crane": "crane",
"flake-utils": "flake-utils",
"fenix": "fenix",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
"systems": "systems",
"treefmt-nix": "treefmt-nix"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1725935143,
"narHash": "sha256-mVtTVQMlXkydSXVwFClE0ckxHrOQ9nb2DrCjNwW5pUE=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "c3c175c74cd0e8c2c40a0e22bc6e3005c4d28d64",
"lastModified": 1725890120,
"narHash": "sha256-7bsWAKG/otbHj7wmCBrJ9P6ve2MFcoOlIh6wcx6ffKg=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "e35227d186acd47d8e5f78cbd792d57ddf47d74b",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
@ -108,6 +131,26 @@
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1725271838,
"narHash": "sha256-VcqxWT0O/gMaeWTTjf1r4MOyG49NaNxW4GHTO3xuThE=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "9fb342d14b69aefdf46187f6bb80a4a0d97007cd",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",

View file

@ -1,11 +1,12 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
fenix.inputs.nixpkgs.follows = "nixpkgs";
fenix.url = "github:nix-community/fenix/pull/163/head";
crane.url = "github:ipetkov/crane";
@ -13,26 +14,33 @@
url = "github:rustsec/advisory-db";
flake = false;
};
systems.url = "github:nix-systems/default";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = {
self,
nixpkgs,
flake-utils,
rust-overlay,
crane,
advisory-db,
}:
flake-utils.lib.eachDefaultSystem
(
system: let
overlays = [(import rust-overlay)];
pkgs = import nixpkgs {
inherit system overlays;
};
flake-parts,
...
} @ inputs:
flake-parts.lib.mkFlake {inherit self inputs;} {
systems = import inputs.systems;
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
src = craneLib.cleanCargoSource ./.;
perSystem = {
pkgs,
inputs',
self',
...
}: let
rustToolchain = inputs'.fenix.packages.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-VZZnlyP69+Y3crrLHQyJirqlHrTtGTsyiSnZB8jEvVo=";
};
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain;
src = craneLib.cleanCargoSource (craneLib.path ./.);
nativeBuildInputs = with pkgs; [rustToolchain pkg-config];
buildInputs = with pkgs; [udev];
@ -43,8 +51,9 @@
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
bin = craneLib.buildPackage (commonArgs // {inherit cargoArtifacts;});
in
with pkgs; {
in {
_module.args.pkgs = inputs'.nixpkgs.legacyPackages.extend inputs.fenix.overlays.default;
checks = {
inherit bin;
clippy = craneLib.cargoClippy (commonArgs
@ -55,27 +64,23 @@
coverage = craneLib.cargoTarpaulin (commonArgs // {inherit cargoArtifacts;});
fmt = craneLib.cargoFmt {inherit src;};
audit = craneLib.cargoAudit {
inherit src advisory-db;
inherit src;
inherit (inputs) advisory-db;
};
};
packages = {
default = bin;
};
apps = rec {
default = flake-utils.lib.mkApp {drv = bin;};
};
devShells.default = craneLib.devShell {
checks = self.checks.${system};
inherit (self') checks;
packages = [];
};
}
);
};
};
nixConfig = {
extra-substituters = ["callumio-public.cachix.org"];
extra-substituters = ["https://callumio-public.cachix.org"];
extra-trusted-public-keys = ["callumio-public.cachix.org-1:VucOSl7vh44GdqcILwMIeHlI0ufuAnHAl8cO1U/7yhg="];
};
}