Unable to build with `nixpkgs.*.gcc.{arch,tune}` set

Hello everyone and happy new year! :confetti_ball:

I have noticed that my unstable-small system is compiling quite a bit.
If it already is doing that I would like it to produce optimized code.

I have tried adding

 nixpkgs.hostPlatform.gcc = {
    arch = "znver3";
    tune = "znver3";
    system = "x86_64-linux";
  };

to my config, like the wiki suggests. However I get these errors:

# nixos-rebuild test 
error:
       … while evaluating the attribute 'config'
         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:1:12284:
       … while calling the 'seq' builtin
         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:1:12293:
       … while evaluating the module argument `pkgs' in "/nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/services/hardware/bluetooth.nix":

       … while evaluating the option `nixpkgs.buildPlatform':

       … while evaluating the option `nixpkgs.hostPlatform':

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

       error: attribute 'system' missing
       at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/systems/default.nix:1:2711:
building Nix...
error:
       … while evaluating the attribute 'config'
         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:1:12284:
       … while calling the 'seq' builtin
         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:1:12293:
       … while evaluating the module argument `pkgs' in "/nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/services/hardware/bluetooth.nix":

       … while evaluating the option `nixpkgs.buildPlatform':

       … while evaluating the option `nixpkgs.hostPlatform':

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

       error: attribute 'system' missing
       at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/systems/default.nix:1:2711:
building the system configuration...
error:
       … while evaluating the attribute 'config.system.build.toplevel'
         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:1:12284:
       … while calling the 'seq' builtin
         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:1:12293:
       … while evaluating the module argument `pkgs' in "/nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/services/hardware/bluetooth.nix":

       … while evaluating the option `nixpkgs.buildPlatform':

       … while evaluating the option `nixpkgs.hostPlatform':

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

       error: attribute 'system' missing
       at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/systems/default.nix:1:2711:

When I change hostPlatform to localSystem (inspired by this post) I get told that it is a legacy option and I should not use it while the rebuild fails because of conflicting nixpkgs.hostPlatform in hardware-configuration.nix.

Does any of you know how to make this work?

Yo have added the system property in gcc, whilst the wiki is having it in hostPlatform.
That is the observed eval error complaining about.

nixpkgs.hostPlatform = {
    gcc = {
      arch = "znver3";
      tune = "znver3";
    };
    system = "x86_64-linux";
  };

Should be correct

Right, I have overlooked this.

after adding gccarch-znver3 to nix.settings.system-features I managed to start compilation.

This however from what I can see recompiles all the packages.

Is there a possibility to apply those optimizations just for packages that are not available as binaries?

Not really, no, the substitution from a cache is happening at a lower layer, and is not treated specially at the derivation layer. You could create a second nixpkgs instance to cherry-pick specific packages from, but that would increase eval memory usage and slow down eval at the very least.

Then stop using that channel? :slight_smile:
By the time nixos-unstable advances, hydra has cached way more, and more importantly, more packages are tested. *-small variants are really for servers that only use some small subset of packages that are part of the *-small jobset.