Closed Siilwyn closed 3 years ago
The error you see is that it cannot find a C compiler. Our C/C++ compiler infrastructure requires a nix-shell:
with import <nixpkgs> {}:
mkShell {
# this way you could also load rustup with the nix-shell as well... rather
# than installing it globally.
#buildInputs [ rustup ];
}
$ nix-shell
nix-shell> echo $CC
nix-shell> cargo build
Also it feasible to hard code a c compiler into cargo, I rather don't want to do this since it makes it hard to use a different compiler. Also almost any C library would require a nix-shell anyway in order fo the C compiler to be able to pick it up. If you need a better workflow for automatically loading a nix-shell have a look at direnv's nix-shell integration. Our wiki also contains further information on how C/C++ are integrated into nixpkgs.
Ah okay, thought I would be able to define everything globally.
Thanks for the reply!
For those using the experimental nix flakes system and stumbling on this issue, you can get around with:
nix shell nixpkgs#cargo nixpkgs#gcc --command cargo build
(note that here the default/global nixpkgs
always points to the master branch, I'd recommend using another one with nix registry add nixpkgs github:nixos/nixpkgs/nixpkgs-unstable
to follow the branch nixpkgs-unstable
for which most packages are cached by hydra)
nix shell nixpkgs#cargo nixpkgs#gcc --command cargo build
This doesn't work for me for some reason:
root@e0aed42f33d7:/workspaces/sshenanigans# nix shell nixpkgs#cargo nixpkgs#gcc --command cargo build
error: path '«unknown»/nix/store/swqzdxbim9vyc8bbzibvia7gq30ih86j-gcc-wrapper-13.2.0-man' is a symlink
FWIW I'm running on Ubuntu with Nix installed via the Determinate installer, but I'm not sure if that ought to matter here?
Describe the bug Using Rustup to install Rust and then building a project causes an error
linker
ccnot found
.To Reproduce Steps to reproduce the behavior:
rustup
underenvironment.systemPackages
in/etc/nixos/configuration.nix
. 2.Runsudo nixos-rebuild switch
rustup default stable
.cargo build
orrustc
, for example runningrustc test.rs
on a file containing:fn main() {}
.error: aborting due to previous error
{ config, pkgs, ... }:
{ imports = [ # Include the results of the hardware scan. ./hardware-configuration.nix ];
boot.loader.grub.enable = true; boot.loader.grub.version = 2; boot.loader.grub.device = "/dev/sdb";
time.timeZone = "Europe/Amsterdam"; i18n.defaultLocale = "en_US.UTF-8";
Enable the GNOME 3 Desktop Environment.
services.xserver.enable = true; services.xserver.displayManager.gdm.enable = true; services.xserver.desktopManager.gnome3.enable = true;
users.users.siilwyn = { isNormalUser = true; extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user. shell = pkgs.fish; };
programs.fish.enable = true;
environment.systemPackages = with pkgs; [ git neovim firefox chromium
];
Enable CUPS to print documents.
services.printing.enable = true;
Enable sound.
sound.enable = true;
hardware.pulseaudio.enable = true;
The global useDHCP flag is deprecated, therefore explicitly set to false here.
Per-interface useDHCP will be mandatory in the future, so this generated config
replicates the default behaviour.
networking.useDHCP = false; networking.interfaces.enp0s25.useDHCP = true; networking.interfaces.wlp3s0.useDHCP = true;
This value determines the NixOS release from which the default
settings for stateful data, like file locations and database versions
on your system were taken. It‘s perfectly fine and recommended to leave
this value at the release version of the first install of this system.
system.stateVersion = "20.09"; }
λ nix-shell -p nix-info --run "nix-info -m" these paths will be fetched (0.05 MiB download, 0.28 MiB unpacked): /nix/store/rlknkw60sngvky1rkrdws0qik3scjcln-bash-interactive-4.4-p23-dev copying path '/nix/store/rlknkw60sngvky1rkrdws0qik3scjcln-bash-interactive-4.4-p23-dev' from 'https://cache.nixos.org'...
"x86_64-linux"
Linux 5.4.72, NixOS, 20.09.1500.edb26126d98 (Nightingale)
yes
yes
nix-env (Nix) 2.3.7
/nix/var/nix/profiles/per-user/root/channels/nixos
Maintainer information: