Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix-shell support #111

Open
kolloch opened this issue Feb 19, 2020 · 4 comments
Open

nix-shell support #111

kolloch opened this issue Feb 19, 2020 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@kolloch
Copy link
Collaborator

kolloch commented Feb 19, 2020

Provide a derivation that provides a good basis for a shell.nix and includes the following buildInputs:

  • cargo, rustc, binutils, clippy, rustfmt and others? Maybe rls and rust-analyzer?
  • All buildInputs that are needed for a cargo test run. Accumulating on non-rust buildInputs over all crates in the build file via the defaultCrateOverrides mechanism is a good start.
@kolloch kolloch added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Feb 19, 2020
@nagisa
Copy link
Contributor

nagisa commented Feb 20, 2020

{ lib, mkShell, allCrates, cargo }:

let
  depsCollector = n: a: a.completeBuildDeps ++ a.completeDeps ++ [a];
  allRustDeps = lib.mapAttrsToList depsCollector allCrates;
  uniqueRustDeps = lib.unique (builtins.concatLists allRustDeps);
  inputs = builtins.map (a: a.buildInputs) uniqueRustDeps;
  uniqueInputs = lib.unique (builtins.concatLists inputs);
  nativeInputs = builtins.map (a: a.nativeBuildInputs) uniqueRustDeps;
  uniqueNativeInputs = lib.unique (builtins.concatLists nativeInputs);
  getUniqueValue = list: (assert [(lib.head list)] == lib.unique list; lib.head list);
  envVars = lib.zipAttrs (builtins.map (lib.filterAttrs (n: v: n == lib.toUpper n)) uniqueRustDeps);
  verifiedEnvVars = lib.mapAttrs (n: v: getUniqueValue v) envVars;
  shellAttrs = verifiedEnvVars // {
    name = "rust-build-shell";
    buildInputs = uniqueInputs;
    nativeBuildInputs = uniqueNativeInputs ++ [
      cargo
    ];
  };

in mkShell shellAttrs

is what I came up locally a little while ago.

@nagisa
Copy link
Contributor

nagisa commented Feb 20, 2020

(nb: cargo here is from the mozilla overlay so it does include all the cargo-tools you’d expect)

@rambip
Copy link

rambip commented Jul 24, 2021

@nagisa How do you extract allCrates from the file generated by crate2nix ?
When I try to use cargo and rustup from a nix-shell on a non nix-os system, I get sometimes errors about the glibc version.
I would really appreciate this feature too !

@rambip
Copy link

rambip commented Jul 24, 2021

If someone know what I can do to create a nix expression for an environment where I can build a https://rustwasm.github.io/docs/wasm-pack/ project, it would be really nice !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants