Skip to content

Commit

Permalink
build: use nightly toolchain
Browse files Browse the repository at this point in the history
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]: rust-lang/rust#84908
[^2]: https://doc.rust-lang.org/std/process/struct.ExitStatusError.html
  • Loading branch information
andrew-scott-fischer committed May 14, 2024
1 parent 5914f95 commit c4ec1e4
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 11 deletions.
39 changes: 39 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down
16 changes: 15 additions & 1 deletion nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
};
Expand Down Expand Up @@ -51,5 +64,6 @@ in {
myCrate
myCrateClippy
myCrateCoverage
fenix-toolchain
;
}
39 changes: 39 additions & 0 deletions nix/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions nix/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -15,6 +19,7 @@
self,
nixpkgs,
crane,
fenix,
pre-commit-hooks,
}: let
forEachSystem = nixpkgs.lib.genAttrs [
Expand All @@ -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 = {
Expand All @@ -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;

Expand Down

0 comments on commit c4ec1e4

Please sign in to comment.