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" "type": "github"
} }
}, },
"flake-utils": { "fenix": {
"inputs": { "inputs": {
"systems": "systems" "nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
}, },
"locked": { "locked": {
"lastModified": 1710146030, "lastModified": 1725437390,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "narHash": "sha256-W2ZnHE+FkPVap5Em6na4KP8XkhU8kpY07iX0d4+y4uM=",
"owner": "numtide", "owner": "nix-community",
"repo": "flake-utils", "repo": "fenix",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "rev": "29ad6b2023ccec4d4679244c233f0ea875cdf000",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "numtide", "owner": "nix-community",
"repo": "flake-utils", "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" "type": "github"
} }
}, },
@ -69,28 +93,27 @@
"inputs": { "inputs": {
"advisory-db": "advisory-db", "advisory-db": "advisory-db",
"crane": "crane", "crane": "crane",
"flake-utils": "flake-utils", "fenix": "fenix",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay" "systems": "systems",
"treefmt-nix": "treefmt-nix"
} }
}, },
"rust-overlay": { "rust-analyzer-src": {
"inputs": { "flake": false,
"nixpkgs": [
"nixpkgs"
]
},
"locked": { "locked": {
"lastModified": 1725935143, "lastModified": 1725890120,
"narHash": "sha256-mVtTVQMlXkydSXVwFClE0ckxHrOQ9nb2DrCjNwW5pUE=", "narHash": "sha256-7bsWAKG/otbHj7wmCBrJ9P6ve2MFcoOlIh6wcx6ffKg=",
"owner": "oxalica", "owner": "rust-lang",
"repo": "rust-overlay", "repo": "rust-analyzer",
"rev": "c3c175c74cd0e8c2c40a0e22bc6e3005c4d28d64", "rev": "e35227d186acd47d8e5f78cbd792d57ddf47d74b",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "oxalica", "owner": "rust-lang",
"repo": "rust-overlay", "ref": "nightly",
"repo": "rust-analyzer",
"type": "github" "type": "github"
} }
}, },
@ -108,6 +131,26 @@
"repo": "default", "repo": "default",
"type": "github" "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", "root": "root",

View file

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