Nixos 23.11, "nix-shell -p gcc" fine but "nix-env --install gcc" fails?

[tru@nixos:~]$ nixos-version 
23.11.1431.a804fc878d7b (Tapir)
[tru@nixos:~]$ nix-env --version
nix-env (Nix) 2.18.1

[tru@nixos:~]$ nix-env -q
curl-8.4.0
git-2.42.0
nano-7.2
openssl-3.1.4

[tru@nixos:~]$ nix-env --install gcc
installing 'gcc-13.2.0'
error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'gcc-13.2.0'
         whose name attribute is located at /nix/store/y907j1lhxsydwjqxh7r9wkjqvz7pn7sc-nixos-23.11/nixos/pkgs/os-specific/linux/minimal-bootstrap/bash/default.nix:51:14

       … while evaluating attribute 'PATH' of derivation 'gcc-13.2.0'

         at /nix/store/y907j1lhxsydwjqxh7r9wkjqvz7pn7sc-nixos-23.11/nixos/pkgs/os-specific/linux/minimal-bootstrap/bash/default.nix:74:7:

           73|       SHELL = "${bash}/bin/bash";
           74|       PATH = lib.makeBinPath ((env.nativeBuildInputs or []) ++ [
             |       ^
           75|         bash

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: Package ‘tinycc-musl-unstable-2023-07-10-compiler’ in «unknown-file» is not available on the requested hostPlatform:
         hostPlatform.config = "x86_64-unknown-linux-gnu"
         package.meta.platforms = [
           "i686-linux"
         ]
         package.meta.badPlatforms = [ ]
       , refusing to evaluate. 

       a) To temporarily allow packages that are unsupported for this system, you can use an environment variable
          for a single invocation of the nix tools.

            $ export NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1

          Note: When using `nix shell`, `nix build`, `nix develop`, etc with a flake,
                then pass `--impure` in order to allow use of environment variables.

       b) For `nixos-rebuild` you can set
         { nixpkgs.config.allowUnsupportedSystem = true; }
       in configuration.nix to override this.

       c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
         { allowUnsupportedSystem = true; }
       to ~/.config/nixpkgs/config.nix.

But I can spawn gcc just fine with:

[nix-shell:~]$ nix-shell --version
nix-shell (Nix) 2.18.1
[tru@nixos:~]$ nix-shell -p gcc

[nix-shell:~]$ gcc -v
Using built-in specs.
COLLECT_GCC=/nix/store/hf2gy3km07d5m0p1lwmja0rg9wlnmyr7-gcc-12.3.0/bin/gcc
COLLECT_LTO_WRAPPER=/nix/store/hf2gy3km07d5m0p1lwmja0rg9wlnmyr7-gcc-12.3.0/libexec/gcc/x86_64-unknown-linux-gnu/12.3.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-12.3.0/configure --prefix=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-12.3.0 --with-gmp-include=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gmp-6.3.0-dev/include --with-gmp-lib=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gmp-6.3.0/lib --with-mpfr-include=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-mpfr-4.2.1-dev/include --with-mpfr-lib=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-mpfr-4.2.1/lib --with-mpc=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-libmpc-1.3.1 --with-native-system-header-dir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-glibc-2.38-27-dev/include --with-build-sysroot=/ --program-prefix= --enable-lto --disable-libstdcxx-pch --without-included-gettext --with-system-zlib --enable-static --enable-languages=c,c++ --disable-multilib --enable-plugin --disable-libcc1 --with-isl=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-isl-0.20 --disable-bootstrap --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=x86_64-unknown-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.3.0 (GCC) 

The correct command would be nix-env -iA nixos.gcc
Either way, you can get a working gcc only using nix-shell. Also https://stop-using-nix-env.privatevoid.net/

oh, my bad, thx for the solution and the hint about nix-env usage.

1 Like