From cae2526833e45739ba4d229e028c18d953ebc795 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Wed, 11 Sep 2024 08:56:22 +0100 Subject: [PATCH] chore: use fenix and flake-parts --- flake.lock | 91 ++++++++++++++++++++++++++++++++++------------- flake.nix | 101 ++++++++++++++++++++++++++++------------------------- 2 files changed, 120 insertions(+), 72 deletions(-) diff --git a/flake.lock b/flake.lock index a63ca0f..d09d2d9 100644 --- a/flake.lock +++ b/flake.lock @@ -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", diff --git a/flake.nix b/flake.nix index 531c30c..ecf691d 100644 --- a/flake.nix +++ b/flake.nix @@ -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,39 +51,36 @@ cargoArtifacts = craneLib.buildDepsOnly commonArgs; bin = craneLib.buildPackage (commonArgs // {inherit cargoArtifacts;}); - in - with pkgs; { - checks = { - inherit bin; - clippy = craneLib.cargoClippy (commonArgs - // { - inherit cargoArtifacts; - cargoClippyExtraArgs = "--all-targets -- --deny warnings"; - }); - coverage = craneLib.cargoTarpaulin (commonArgs // {inherit cargoArtifacts;}); - fmt = craneLib.cargoFmt {inherit src;}; - audit = craneLib.cargoAudit { - inherit src advisory-db; - }; - }; + in { + _module.args.pkgs = inputs'.nixpkgs.legacyPackages.extend inputs.fenix.overlays.default; - packages = { - default = bin; + checks = { + inherit bin; + clippy = craneLib.cargoClippy (commonArgs + // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }); + coverage = craneLib.cargoTarpaulin (commonArgs // {inherit cargoArtifacts;}); + fmt = craneLib.cargoFmt {inherit src;}; + audit = craneLib.cargoAudit { + 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}; - packages = []; - }; - } - ); + devShells.default = craneLib.devShell { + 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="]; }; }