From c4ec1e45bc362a78cd492d60c2f8c3be04fe97dc Mon Sep 17 00:00:00 2001 From: Andrew Fischer Date: Wed, 8 May 2024 12:03:32 -0700 Subject: [PATCH] build: use nightly toolchain This change adds `fenix` to the nix flake to enable the use of nightly toolchains. Using nightly rust toolchains enables the use of the features behind the `exit_status_error`[^1] feature flag, which allows the use of `ExitStatusError`[^2]. [^1]: https://github.com/rust-lang/rust/issues/84908 [^2]: https://doc.rust-lang.org/std/process/struct.ExitStatusError.html --- flake.lock | 39 +++++++++++++++++++++++++++++++++++++++ flake.nix | 7 ++++++- nix/default.nix | 16 +++++++++++++++- nix/flake.lock | 39 +++++++++++++++++++++++++++++++++++++++ nix/flake.nix | 20 +++++++++++--------- 5 files changed, 110 insertions(+), 11 deletions(-) diff --git a/flake.lock b/flake.lock index 0d343ce..f57ae42 100644 --- a/flake.lock +++ b/flake.lock @@ -20,6 +20,27 @@ "type": "github" } }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1715063087, + "narHash": "sha256-cktPkcCmJ2sR0V/FaWEuCWmKuGPbwoMltih/EfF0mXg=", + "owner": "nix-community", + "repo": "fenix", + "rev": "f8f16c1f2c83bea4e51e6522d988ec8bfcc8420e", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1715106818, @@ -38,8 +59,26 @@ "root": { "inputs": { "crane": "crane", + "fenix": "fenix", "nixpkgs": "nixpkgs" } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1714936835, + "narHash": "sha256-M+PpgfRMBfHo8Jb2ou/s3maAZbps0XnuHXQU9Hv9vL0=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "c4618fe14d39992fbbb85c2d6cad028a232c13d2", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index c362d9e..3e7c5c3 100644 --- a/flake.nix +++ b/flake.nix @@ -5,12 +5,17 @@ url = "github:ipetkov/crane"; inputs.nixpkgs.follows = "nixpkgs"; }; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = { self, nixpkgs, crane, + fenix, }: let forEachSystem = nixpkgs.lib.genAttrs [ "aarch64-darwin" @@ -21,7 +26,7 @@ in { packages = forEachSystem (system: let craneDerivations = nixpkgs.legacyPackages.${system}.callPackage ./nix/default.nix { - inherit crane; + inherit crane fenix; }; in { default = craneDerivations.myCrate; diff --git a/nix/default.nix b/nix/default.nix index d54652f..d1fc410 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -2,14 +2,27 @@ pkgs, system, crane, + fenix, }: let - craneLib = crane.lib.${system}; + fenix-channel = fenix.packages.${system}.latest; + fenix-toolchain = fenix-channel.withComponents [ + "cargo" + "clippy" + "rust-analyzer" + "rust-src" + "rustc" + "rustfmt" + ]; + + craneLib = crane.lib.${system}.overrideToolchain fenix-toolchain; # Common derivation arguments used for all builds commonArgs = { src = craneLib.cleanCargoSource ../.; nativeBuildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [ + pkgs.darwin.apple_sdk.frameworks.Security + pkgs.darwin.apple_sdk.frameworks.SystemConfiguration pkgs.libiconv ]; }; @@ -51,5 +64,6 @@ in { myCrate myCrateClippy myCrateCoverage + fenix-toolchain ; } diff --git a/nix/flake.lock b/nix/flake.lock index 4733cb5..23da993 100644 --- a/nix/flake.lock +++ b/nix/flake.lock @@ -20,6 +20,27 @@ "type": "github" } }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1715063087, + "narHash": "sha256-cktPkcCmJ2sR0V/FaWEuCWmKuGPbwoMltih/EfF0mXg=", + "owner": "nix-community", + "repo": "fenix", + "rev": "f8f16c1f2c83bea4e51e6522d988ec8bfcc8420e", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -133,10 +154,28 @@ "root": { "inputs": { "crane": "crane", + "fenix": "fenix", "nixpkgs": "nixpkgs", "pre-commit-hooks": "pre-commit-hooks" } }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1714936835, + "narHash": "sha256-M+PpgfRMBfHo8Jb2ou/s3maAZbps0XnuHXQU9Hv9vL0=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "c4618fe14d39992fbbb85c2d6cad028a232c13d2", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, "systems": { "locked": { "lastModified": 1681028828, diff --git a/nix/flake.nix b/nix/flake.nix index a3bd9db..2095a20 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -5,6 +5,10 @@ url = "github:ipetkov/crane"; inputs.nixpkgs.follows = "nixpkgs"; }; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; pre-commit-hooks = { url = "github:cachix/pre-commit-hooks.nix"; inputs.nixpkgs.follows = "nixpkgs"; @@ -15,6 +19,7 @@ self, nixpkgs, crane, + fenix, pre-commit-hooks, }: let forEachSystem = nixpkgs.lib.genAttrs [ @@ -25,7 +30,8 @@ ]; in { checks = forEachSystem (system: let - craneDerivations = nixpkgs.legacyPackages.${system}.callPackage ./default.nix {inherit crane;}; + pkgs = import nixpkgs {inherit system;}; + craneDerivations = pkgs.callPackage ./default.nix {inherit crane fenix;}; pre-commit-check = pre-commit-hooks.lib.${system}.run { src = ../.; hooks = { @@ -46,17 +52,13 @@ }); devShells = forEachSystem (system: let - pkgs = nixpkgs.legacyPackages.${system}; - craneDerivations = pkgs.callPackage ./default.nix {inherit crane;}; + pkgs = import nixpkgs {inherit system;}; + craneDerivations = pkgs.callPackage ./default.nix {inherit crane fenix;}; in { default = pkgs.mkShell { - nativeBuildInputs = with pkgs; + packages = with pkgs; [ - cargo - clippy - rust-analyzer - rustc - rustfmt + craneDerivations.fenix-toolchain ] ++ craneDerivations.commonArgs.nativeBuildInputs;