Untitled conversation
- User
{ pkgs ? import {} }:
let libPath = with pkgs; lib.makeLibraryPath [ libGL libxkbcommon wayland ]; in { devShell = with pkgs; mkShell { buildInputs = [ cargo rustc rust-analyzer ];RUST_LOG = "debug"; RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; LD_LIBRARY_PATH = libPath; };} fails with error: cannot coerce a set to a string: { }
- Assistant
The problem is that
{ pkgs ? import {} }:is trying to do
import {} # <-- “{}” is an attr‐set, not a path or URLso Nix complains
error: cannot coerce a set to a string: { }You have two easy ways to fix it:
—–
OPTION 1: Classic (non‐flake) Nix{ pkgs ? import <nixpkgs> {} }: # <<<<— import from your configured nixpkgs let # it’s often better to pick mesa.libGL explicitly: myGL = pkgs.mesa.libGL; myXkb = pkgs.libxkbcommon; myWayland= pkgs.wayland; libPath = pkgs.lib.makeLibraryPath [ myGL myXkb myWayland ]; in { devShell = pkgs.mkShell { buildInputs = [ pkgs.cargo pkgs.rustc pkgs.rust-analyzer ]; # if you want to see debug trace from log statements RUST_LOG = "debug"; # tell rust-analyzer/rustc where your stdlib is RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; LD_LIBRARY_PATH= libPath; }; }Save that as, say,
shell.nixand then:$ nix-shell—–
OPTION 2: FlakesIf you’re on Nix ≥ 2.4 with flakes enabled, you can turn it into a
flake.nix:{ description = "Rust DevShell"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url= "github:numtide/flake-utils"; }; outputs = { self, nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; myGL = pkgs.mesa.libGL; myXkb = pkgs.libxkbcommon; myWayland= pkgs.wayland; libPath = pkgs.lib.makeLibraryPath [ myGL myXkb myWayland ]; in { devShells.default = pkgs.mkShell { buildInputs = [ pkgs.cargo pkgs.rustc pkgs.rust-analyzer ]; RUST_LOG = "debug"; RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; LD_LIBRARY_PATH = libPath; }; } ); }Then:
# from the same dir as your flake.nix: $ nix develop—–
Key point:•
import {}is illegal—Nix expects a path‐string or another flake reference
• useimport <nixpkgs> {}(classic) or a proper flake input (flakes)That will remove the “cannot coerce a set to a string” error.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.