I recently had some shenanigans happen when I accidentally switched to another system config on an existing system which got me locked out of my machine. After I was able to recover it, I’ve been noticing some things that’ve broken which used to work flawlessly before. One of those is using nix-direnv to enter devShells automatically.
For some reason, nix develop is trying to fetch a version of get-env.sh that doesn’t exist in the store. There is one in the store, but it doesn’t seem to be fetching it.
The last few log lines where it always hangs when running nix develop -vvv is:
setting up chroot environment in "/nix/store/58hc0wwb6ygmvml67pf18hmnlnf44f8b-rust-default-1.97.0.drv.chroot"
executing builder '/nix/store/v8llyqw71lygr2llhmcc8ya5bdlzq45v-bash-5.3p9/bin/bash'
using builder args '-e /nix/store/l622p70vy8k5sh7y5wizi5f2mic6ynpg-source-stdenv.sh /nix/store/shkw4qm9qcw5sc5n1k5jznc83ny02r39-default-builder.sh'
building '/nix/store/58hc0wwb6ygmvml67pf18hmnlnf44f8b-rust-default-1.97.0.drv'...
linking "/nix/store/w3aw61c6mdr710ic63js7imwr7zksiq9-rust-default-1.97.0/nix-support/propagated-host-host-deps" to "/nix/store/.links/1mdcsczjlqg68f7fywi7r2p5mmrp24qrxs1aq677p1if82ckz15j"
setting up chroot environment in "/nix/store/n2frjl6gswafr91v4vx039wm09z0jnw6-nix-shell-env.drv.chroot"
executing builder '/nix/store/v8llyqw71lygr2llhmcc8ya5bdlzq45v-bash-5.3p9/bin/bash'
using builder args '/nix/store/hyhh9rhzxhzmfspllmpf75xzkzns109r-get-env.sh'
error:
… while setting up the build environment
error: getting attributes of path "/nix/store/hyhh9rhzxhzmfspllmpf75xzkzns109r-get-env.sh": No such file or directory
My flake is:
{
description = "of-the-star's custom rust development flake"; # TODO: Change description for project
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
crane = {
url = "github:ipetkov/crane";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
crane,
rust-overlay,
}:
let
systems = [
"x86_64-linux"
];
iterOverSystems = nixpkgs.lib.genAttrs systems;
forSystem =
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
rust-toolchain =
if builtins.pathExists ./rust-toolchain.toml then
pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml
else
pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" ];
};
# Instantiates custom craneLib using toolchain
craneLib = (crane.mkLib pkgs).overrideToolchain rust-toolchain;
src = craneLib.cleanCargoSource ./.;
pname = (craneLib.crateNameFromCargoToml { cargoToml = ./Cargo.toml; }).pname;
# Common arguments shared between buildPackage and buildDepsOnly
commonArgs = {
inherit src;
strictDeps = true;
nativeBuildInputs = with pkgs; [
pkg-config
];
buildInputs = with pkgs; [
openssl
];
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
package = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
}
);
in
{
inherit
package
;
"${pname}" = package;
devShell = pkgs.mkShell {
# Inherits buildInputs from crane-package
inputsFrom = [ package ];
# Additional packages for the dev environment
packages = with pkgs; [
];
shellHook = "";
env = {
# Needed for rust-analyzer
RUST_SRC_PATH = "${rust-toolchain}/lib/rustlib/src/rust/library";
};
};
formatter = pkgs.nixfmt-tree;
};
in
{
devShells = (
iterOverSystems (system: {
default = (forSystem system).devShell;
})
);
formatter = (iterOverSystems (system: (forSystem system).formatter));
packages = (
iterOverSystems (system: {
default = (forSystem system).package;
})
);
};
}