From 992e6b945a9bb9fbed94c732a171cdbec0662354 Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Mon, 12 Aug 2024 21:22:05 -0700 Subject: [PATCH] remove usage of IFD in nix packages Lix builders have IFD disabled, and the changes needed to support this are minimal. We do need to do slightly more manual work to keep rust-toolchain.toml in sync with flake.nix, but it's not significant. --- flake.lock | 15 ++++++++++++++- flake.nix | 37 ++++++++++++++++++++++++++---------- nix/pkgs/default/default.nix | 10 ++++------ 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/flake.lock b/flake.lock index f719ccbd..3a58f74d 100644 --- a/flake.lock +++ b/flake.lock @@ -226,7 +226,8 @@ "flake-compat": "flake-compat_2", "flake-utils": "flake-utils_2", "nix-filter": "nix-filter", - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_2", + "rust-manifest": "rust-manifest" } }, "rust-analyzer-src": { @@ -246,6 +247,18 @@ "type": "github" } }, + "rust-manifest": { + "flake": false, + "locked": { + "narHash": "sha256-aZFye4UrtlcvLHrISldx4g9uGt3thDbVlLMK5keBSj0=", + "type": "file", + "url": "https://static.rust-lang.org/dist/channel-rust-1.78.0.toml" + }, + "original": { + "type": "file", + "url": "https://static.rust-lang.org/dist/channel-rust-1.78.0.toml" + } + }, "systems": { "locked": { "lastModified": 1681028828, diff --git a/flake.nix b/flake.nix index 51c50679..3a31a02f 100644 --- a/flake.nix +++ b/flake.nix @@ -8,6 +8,12 @@ flake-utils.url = "github:numtide/flake-utils?ref=main"; nix-filter.url = "github:numtide/nix-filter?ref=main"; nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable"; + + rust-manifest = { + # Keep version in sync with rust-toolchain.toml + url = "https://static.rust-lang.org/dist/channel-rust-1.78.0.toml"; + flake = false; + }; }; outputs = inputs: @@ -29,16 +35,27 @@ shell = self.callPackage ./nix/shell.nix {}; # The Rust toolchain to use - toolchain = inputs - .fenix - .packages - .${pkgs.pkgsBuildHost.system} - .fromToolchainFile { - file = ./rust-toolchain.toml; - - # See also `rust-toolchain.toml` - sha256 = "sha256-opUgs6ckUQCyDxcB9Wy51pqhd0MPGHUVbwRKKPGiwZU="; - }; + # Using fromManifestFile and parsing the toolchain file with importTOML + # instead of fromToolchainFile to avoid IFD + toolchain = let + toolchainFile = pkgs.lib.importTOML ./rust-toolchain.toml; + defaultProfileComponents = [ + "rustc" + "cargo" + "rust-docs" + "rustfmt" + "clippy" + ]; + components = defaultProfileComponents ++ + toolchainFile.toolchain.components; + targets = toolchainFile.toolchain.targets; + fenix = inputs.fenix.packages.${pkgs.pkgsBuildHost.system}; + in + fenix.combine (builtins.map + (target: + (fenix.targets.${target}.fromManifestFile inputs.rust-manifest) + .withComponents components) + targets); }); in inputs.flake-utils.lib.eachDefaultSystem (system: diff --git a/nix/pkgs/default/default.nix b/nix/pkgs/default/default.nix index b03c2c50..fe31cc74 100644 --- a/nix/pkgs/default/default.nix +++ b/nix/pkgs/default/default.nix @@ -71,12 +71,10 @@ let } // buildDepsOnlyEnv; commonAttrs = { - inherit - (craneLib.crateNameFromCargoToml { - cargoToml = "${inputs.self}/Cargo.toml"; - }) - pname - version; + # Reading from cargoManifest directly instead of using + # createNameFromCargoToml to avoid IFD + pname = cargoManifest.package.name; + version = cargoManifest.package.version; src = let filter = inputs.nix-filter.lib; in filter { root = inputs.self;