Skip to content

Commit

Permalink
nix: Clean up Rust toolchain expressions
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Nov 11, 2024
1 parent 49d2d3c commit f2f1394
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
8 changes: 8 additions & 0 deletions hacking/nix/scope/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ superCallPackage ../rust-utils {} self //
in
toolchain.withComponents filteredComponents;

parseStructuredChannel = unstructuredChannel:
let
parts = builtins.match ''(nightly)-(.*)'' unstructuredChannel;
in
if parts == null
then { channel = unstructuredChannel; date = null; }
else { channel = lib.elemAt parts 0; date = lib.elemAt parts 1; };

defaultRustEnvironment =
let
inherit (scopeConfig.rustEnvironmentSelector) tracks upstream;
Expand Down
17 changes: 7 additions & 10 deletions hacking/nix/scope/kani/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
, crateUtils
, vendorLockfile
, sources
, fenix
, assembleRustToolchain
, parseStructuredChannel
, elaborateRustEnvironment
, mkDefaultElaborateRustEnvironmentArgs
, mkMkCustomTargetPathForEnvironment
Expand All @@ -27,20 +28,16 @@ let

rustToolchainAttrs = builtins.fromTOML (builtins.readFile (src + "/rust-toolchain.toml"));

rustToolchain = fenix.fromToolchainFile {
file = crateUtils.toTOMLFile "rust-toolchain.toml" (crateUtils.clobber [
rustToolchainAttrs
{
toolchain.components = rustToolchainAttrs.toolchain.components ++ [ "rust-src" ];
}
]);
inherit (rustToolchainAttrs.toolchain) channel;

rustToolchain = assembleRustToolchain (parseStructuredChannel channel // {
sha256 = "sha256-opDDHyN+Xa9kcjdHwGl3IpBsUw7ikGU+Ng00JeCdkMA=";
};
});

rustEnvironment = lib.fix (self: elaborateRustEnvironment (mkDefaultElaborateRustEnvironmentArgs {
inherit rustToolchain;
} // {
inherit (rustToolchainAttrs.toolchain) channel;
inherit channel;
mkCustomTargetPath = mkMkCustomTargetPathForEnvironment {
rustEnvironment = self;
};
Expand Down
6 changes: 4 additions & 2 deletions hacking/nix/scope/verus/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ let

rustToolchainAttrs = builtins.fromTOML (builtins.readFile (src + "/rust-toolchain.toml"));

inherit (rustToolchainAttrs.toolchain) channel;

rustToolchain = assembleRustToolchain {
channel = "1.76.0";
inherit channel;
sha256 = "sha256-e4mlaJehWBymYxJGgnbuCObVlqMlQSilZ8FljG9zPHY=";
};

rustEnvironment = lib.fix (self: elaborateRustEnvironment (mkDefaultElaborateRustEnvironmentArgs {
inherit rustToolchain;
} // {
inherit (rustToolchainAttrs.toolchain) channel;
inherit channel;
backwardsCompatibilityHacks = {
outDirInsteadOfArtifactDir = true;
noLibraryWorkspace = true;
Expand Down

0 comments on commit f2f1394

Please sign in to comment.