Why can't I install dotnet in my rust build environment shell?

I’m working on a Rust project I’ve set up to use shell.nix for CI. (Thanks to earlier help from y’all :smile:) I am trying to add the latest dotnet sdk to my Rust shell.nix. Pick either example. I start with the short one :smile:

terse example

Building the following with nix-shell dotnet-shell.nix fails:

with import <nixpkgs> {};
mkShell {
  name = "dotnet-env";
  buildInputs = [
    dotnet-sdk_3
  ];
}

It fails with:

error: undefined variable 'dotnet-sdk_3' at my-project/dotnet-shell.nix:5:5
(use '--show-trace' to show detailed location information)

Why is it failing? I see this locally on a macOS and on a GNU/Linux machine.

long winded example

I found the name from PRs like this one and pending documentation.
Trying to build the following with nix-shell fails:

let
  moz_overlay = import (
    builtins.fetchTarball
      "https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz"
  );
  nixpkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
  ruststable = (
    nixpkgs.latest.rustChannels.stable.rust.override {
      extensions = [ "rust-src" "rust-analysis" "rustfmt-preview" ];
    }
  );
in
  with nixpkgs;
  stdenv.mkDerivation {
    name = "rust-stable";
    buildInputs =
      [ stdenv openssl pkgconfig which zip rustup ruststable dotnet-sdk_3 ];
  }

The failure says:

$ nix-shell
error: undefined variable 'dotnet-sdk_3' at my-project/shell.nix:17:62
(use '--show-trace' to show detailed location information)

Is something wrong with my nix environment? I’m testing this on macOS but seeing the same failure in CI.

Am I specifying the package incorrectly? I suspect so but am confused about what type of arguments buildInputs expects.

My guess would be that your channel is not on nixos-unstable/nixpkgs-unstable, when you import <nixpkgs>
What does nix-channel --list (as root and as your current user) say?

macOS:

nix-channel --list
nixpkgs-latest https://github.com/NixOS/nixpkgs/archive/master.tar.gz
stable https://nixos.org/channels/nixpkgs-18.03-darwin
 $ nix-info
system: "x86_64-darwin", multi-user?: no, version: nix-env (Nix) 2.3.1, channels(root): "nixpkgs-18.09pre137305.d91caac6c3e", channels(me): "nixpkgs-latest, stable-18.03pre133405.4d48e8106f9, nixpkgs-staging", nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixpkgs

CI only has nixpkgs https://nixos.org/channels/nixpkgs-unstable. I can run nix-info for CI too once I figure out the nix-shell -p nix-info incantation.

What does echo $NIX_PATH show?
It should contain an entry like the following (and probably other paths as well).

nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos

This is the path that import <nixpkgs> will import. For me that is:

$ ls -l /nix/var/nix/profiles/per-user/root/channels/nixos
lrwxrwxrwx 2 root root 78  1. Jan 1970  /nix/var/nix/profiles/per-user/root/channels/nixos -> /nix/store/zd836lsd9y50yj8axhl3xa16i2vyvrm6-nixos-19.09.2028.46347794a94/nixos

I assume you have a version that does not have dotnoet-skd_3 yet. The 19.09 channel doesn’t have it while unstable has it.

Also you may want to update from 18.03 to a more recent version. 18.03 doesn’t get updates anymore.

2 Likes

macOS: nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixpkgs /nix/var/nix/profiles/per-user/root/channels
GNU/Linux: /home/gitlab-runner/.nix-defexpr/channels

Also you may want to update from 18.03 to a more recent version. 18.03 doesn’t get updates anymore.

Ah, thanks. I have an older install on macOS. I’m thinking I’ll just pin the version of a channel that satisfies the constraints for Rust + dotnetsdk. I need to find the exact sha, but something like:

with import (
  fetchTarball {
    name = "nixos-unstable-2020-02-06";
    url = https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz;
    sha256 = "1z3kxlbz6bqx1dlagcazg04vhk67r8byihzf959c3m0laf2a1w7y";

  }
) {};

mkShell {
  name = "dotnet-env";
  buildInputs = [
    dotnet-sdk_3
  ];
}