Error compiling Nix packages from source

Issue: I’ve been trying to recompile Nix packages locally from source with various CPU optimizations, but have been running into a variety of errors when doing so.

Goal: All I care about is getting packages compiled from source with my chosen compiler flags. I don’t care about how I do this (or even what compiler I use, though I understand Nix uses GCC). So if I’m going about this all wrong please let me know.

What I have tried: In short, I’ve tried (and failed) to do this via (details later):

  1. setting gcc.arch, gcc.tune, and system in nixpkgs.hostPlatform
  2. Using overlays for specific packages in ~/.config/nixpkgs/overlays/*.nix
  3. Using nixpkgs.overlaysglobally in /etc/nixos/configuration.nix

Details on these methods:

I attempted method 1 as so. I put the following code in my configuration.nix

{ config, lib, pkgs, ... }:
{

  # ...

  nix.settings.system-features = [
    "gccarch-skylake" "benchmark" "big-parallel" "kvm" "nixos-test"
  ];
  nixpkgs.hostPlatform = {
    gcc.arch = "skylake";
    gcc.tune = "skylake";
    system = "x86_64-linux"; # uname --machine to get this
  };

  # ...

}

I then ran sudo nixos-rebuild switch. This fails with the following error:

... (there is a huge chain of these)
error: Cannot build '/nix/store/17afhqczma186iyd66543bqzvb8hma8p-nixos-rebuild-ng-26.05.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/h713m87kribn15anyxxzkfn1zxnwahzb-nixos-rebuild-ng-26.05-dist
         /nix/store/mprzr6wc0917q6q0gqw8zrh3310ll7v8-nixos-rebuild-ng-26.05
Command 'nix-build '<nixpkgs/nixos>' --attr config.system.build.nixos-rebuild --no-out-link' returned non-zero exit status 100.

I attempted number 2 as so – I put the following code in ~/.config/nixpkgs/overlays/wget.nix`:

self: super: {
  optimizeWithFlags = pkg: flags:
    pkg.overrideAttrs (old: {
      NIX_CFLAGS_COMPILE = [ (old.NIX_CFLAGS_COMPILE or "") ] ++ flags;
    });

  optimizeForHost = pkg:
    self.optimizeWithFlags pkg [ "-O3" "-march=skylake" ];

  wget = self.optimizeForHost super.wget;
}

I than ran `nix-build '<nixpkgs>' -A pkgs.wget. This seems to run, and outputs /nix/store/77b7mj6y6l6616w9cfq0z43dnisvlimb-wget-1.25.0. However, I am then unable to run wgetfrom the command line (bash: wget: command not found), and I cannot serve it from a binary cache in my nix/store/. I’m unsure why.

I attempted number 3 as so: I put the following code in my configuration.nix

{ config, lib, pkgs, ... }:
{

  # ...

  environment.systemPackages = with pkgs; [
     # ...
     wget
  ];


  # ...

  nixpkgs.overlays = [
    (final: prev: {
      wget = prev.stdenvAdapters.addAttrsToDerivation {
        NIX_CFLAGS_COMPILE = "";
        NIX_LDFLAGS = "";
      } prev.wget;
    })
  ];

  # ...

}

I then ran sudo nixos-rebuild switch. This results in the following error:

building the system configuration...
error:
       … while calling the 'head' builtin
         at /nix/store/1z10c48rd5gb80yziqlva2hagvwqa6k0-nixos-26.05.12297.cd4ea8d57de1/nixos/lib/attrsets.nix:1717:13:
         1716|           if length values == 1 || pred here (elemAt values 1) (head values) then
         1717|             head values
             |             ^
         1718|           else

       … while evaluating the attribute 'value'
         at /nix/store/1z10c48rd5gb80yziqlva2hagvwqa6k0-nixos-26.05.12297.cd4ea8d57de1/nixos/lib/modules.nix:1167:7:
         1166|     // {
         1167|       value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |       ^
         1168|       inherit (res.defsFinal') highestPrio;

       … while evaluating the option `system.build.toplevel':

       … while evaluating definitions from `/nix/store/1z10c48rd5gb80yziqlva2hagvwqa6k0-nixos-26.05.12297.cd4ea8d57de1/nixos/nixos/modules/system/activation/top-level.nix':

       … while evaluating the option `system.systemBuilderArgs':

       … while evaluating definitions from `/nix/store/1z10c48rd5gb80yziqlva2hagvwqa6k0-nixos-26.05.12297.cd4ea8d57de1/nixos/nixos/modules/system/activation/top-level.nix':

       … while evaluating the option `environment.sessionVariables':

       … while evaluating definitions from `/nix/store/1z10c48rd5gb80yziqlva2hagvwqa6k0-nixos-26.05.12297.cd4ea8d57de1/nixos/nixos/modules/services/display-managers/default.nix':

       … while evaluating the option `environment.systemPackages':

       … while evaluating definitions from `/etc/nixos/configuration.nix':

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

       error: function 'anonymous lambda' called with unexpected argument 'mkDerivationFromStdenv'
       at /nix/store/1z10c48rd5gb80yziqlva2hagvwqa6k0-nixos-26.05.12297.cd4ea8d57de1/nixos/pkgs/by-name/wg/wget/package.nix:1:1:
            1| {
             | ^
            2|   lib,
Command 'nix-build '<nixpkgs/nixos>' --attr config.system.build.toplevel --no-out-link' returned non-zero exit status 1.

These the various references and documentation I’ve been through that motivated the above:

A couple other solutions out there I think are relevant, but do not fully understand how to apply:

Has anyone got this (or something similar) to work? Any help here would be greatly appreciated!

That huge chain would actually be relevant to help you…

After nix-build the output will be in result. So you should be able to run that wget via ./result/bin/wget.

I do not understand what you mean here.

Just to be clear, do you want every package compiled from source with your flags, or just a subset of packages? In the case of the subset, do you also need the libraries they link against compiled with the same flags?

Hello – I apologize for the delay here. It’s been a busy week.

Just a subset – including the libraries they link against. I’m aware that my first method does a full re-compile. I would accept that as a solution if needed, but it is a lot of extra time

Here you go:

error: Cannot build '/nix/store/wzbl6vhnz4q1ccyi7mbvfmazyx83c6m4-bootstrap-stage0-glibc-minimal-bootstrap.drv'.
       Reason: missing system features
       Required features: {gccarch-skylake}
       Available features: {benchmark, big-parallel, kvm, nixos-test}
error: Cannot build '/nix/store/9gzqbs476k76zqz8j26q2y8gzgn645b5-gnu-config-2024-01-01.drv'.
       Reason: missing system features
       Required features: {gccarch-skylake}
       Available features: {benchmark, big-parallel, kvm, nixos-test}
error: Cannot build '/nix/store/dl5axmjkmz0knrl9yzrsyb5nzxy7gzkj-bootstrap-stage-xgcc-gcc-wrapper-15.3.0.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/pj2rcb4wayhbkiqph8g24gicqqgrqm7r-bootstrap-stage-xgcc-gcc-wrapper-15.3.0
error: Cannot build '/nix/store/srjv75wls0ypzdvjnvs2svijvkfaisvn-bootstrap-stage0-glibc-iconv-minimal-bootstrap.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/8wrz1173shjz0dbw2fh6v7s47hl26hf8-bootstrap-stage0-glibc-iconv-minimal-bootstrap
error: Cannot build '/nix/store/r6ifgbanml0vrqkfj7bps2ckfyxmjbcp-bootstrap-stage1-gcc-wrapper-15.3.0.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/29n3sysc4vjvzn387nz4bb7jjnqffrj3-bootstrap-stage1-gcc-wrapper-15.3.0
error: Cannot build '/nix/store/df4cv2gnb900j5b7441ilimc3cw98558-bootstrap-stage2-gcc-wrapper-15.3.0.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/0nd7cbm03yilhdi60xx516chp079g626-bootstrap-stage2-gcc-wrapper-15.3.0
         /nix/store/728jmbi4gr7h15cs0m7yxb201jijzvdl-bootstrap-stage2-gcc-wrapper-15.3.0-info
         /nix/store/976d9igibyiss1nrlgla066g2vlabnix-bootstrap-stage2-gcc-wrapper-15.3.0-man
error: Cannot build '/nix/store/sk9f619vswn22kz7b1cv4j7mvm2fq30y-glibc-2.42-100.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/4za6d79va0b52zj8rzpkgwh92ip3safz-glibc-2.42-100-bin
         /nix/store/bg5f848p7m25xy4qvvqx3yg9sxkkkkrc-glibc-2.42-100-getent
         /nix/store/canpnyagaga1a6fsklwcmlh0sapmlww7-glibc-2.42-100
         /nix/store/cgd3ll3gvvxg34npazjc3zx95ik31mxq-glibc-2.42-100-static
         /nix/store/md0ahi9c096xvbi9h5mhn6f3l77y3cv0-glibc-2.42-100-dev
         /nix/store/pc9ahdhr59f61idvm68q67fxiba475q7-glibc-2.42-100-debug
error: Cannot build '/nix/store/sk9f619vswn22kz7b1cv4j7mvm2fq30y-glibc-2.42-100.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/4za6d79va0b52zj8rzpkgwh92ip3safz-glibc-2.42-100-bin
         /nix/store/bg5f848p7m25xy4qvvqx3yg9sxkkkkrc-glibc-2.42-100-getent
         /nix/store/canpnyagaga1a6fsklwcmlh0sapmlww7-glibc-2.42-100
         /nix/store/cgd3ll3gvvxg34npazjc3zx95ik31mxq-glibc-2.42-100-static
         /nix/store/md0ahi9c096xvbi9h5mhn6f3l77y3cv0-glibc-2.42-100-dev
         /nix/store/pc9ahdhr59f61idvm68q67fxiba475q7-glibc-2.42-100-debug
error: Cannot build '/nix/store/sk9f619vswn22kz7b1cv4j7mvm2fq30y-glibc-2.42-100.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/4za6d79va0b52zj8rzpkgwh92ip3safz-glibc-2.42-100-bin
         /nix/store/bg5f848p7m25xy4qvvqx3yg9sxkkkkrc-glibc-2.42-100-getent
         /nix/store/canpnyagaga1a6fsklwcmlh0sapmlww7-glibc-2.42-100
         /nix/store/cgd3ll3gvvxg34npazjc3zx95ik31mxq-glibc-2.42-100-static
         /nix/store/md0ahi9c096xvbi9h5mhn6f3l77y3cv0-glibc-2.42-100-dev
         /nix/store/pc9ahdhr59f61idvm68q67fxiba475q7-glibc-2.42-100-debug
error: Cannot build '/nix/store/sk9f619vswn22kz7b1cv4j7mvm2fq30y-glibc-2.42-100.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/4za6d79va0b52zj8rzpkgwh92ip3safz-glibc-2.42-100-bin
         /nix/store/bg5f848p7m25xy4qvvqx3yg9sxkkkkrc-glibc-2.42-100-getent
         /nix/store/canpnyagaga1a6fsklwcmlh0sapmlww7-glibc-2.42-100
         /nix/store/cgd3ll3gvvxg34npazjc3zx95ik31mxq-glibc-2.42-100-static
         /nix/store/md0ahi9c096xvbi9h5mhn6f3l77y3cv0-glibc-2.42-100-dev
         /nix/store/pc9ahdhr59f61idvm68q67fxiba475q7-glibc-2.42-100-debug
error: Cannot build '/nix/store/sk9f619vswn22kz7b1cv4j7mvm2fq30y-glibc-2.42-100.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/4za6d79va0b52zj8rzpkgwh92ip3safz-glibc-2.42-100-bin
         /nix/store/bg5f848p7m25xy4qvvqx3yg9sxkkkkrc-glibc-2.42-100-getent
         /nix/store/canpnyagaga1a6fsklwcmlh0sapmlww7-glibc-2.42-100
         /nix/store/cgd3ll3gvvxg34npazjc3zx95ik31mxq-glibc-2.42-100-static
         /nix/store/md0ahi9c096xvbi9h5mhn6f3l77y3cv0-glibc-2.42-100-dev
         /nix/store/pc9ahdhr59f61idvm68q67fxiba475q7-glibc-2.42-100-debug
error: Cannot build '/nix/store/sk9f619vswn22kz7b1cv4j7mvm2fq30y-glibc-2.42-100.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/4za6d79va0b52zj8rzpkgwh92ip3safz-glibc-2.42-100-bin
         /nix/store/bg5f848p7m25xy4qvvqx3yg9sxkkkkrc-glibc-2.42-100-getent
         /nix/store/canpnyagaga1a6fsklwcmlh0sapmlww7-glibc-2.42-100
         /nix/store/cgd3ll3gvvxg34npazjc3zx95ik31mxq-glibc-2.42-100-static
         /nix/store/md0ahi9c096xvbi9h5mhn6f3l77y3cv0-glibc-2.42-100-dev
         /nix/store/pc9ahdhr59f61idvm68q67fxiba475q7-glibc-2.42-100-debug
error: Cannot build '/nix/store/dbrwc8b3cnpyyv9vg8cnf69ii0yq68j6-perl-5.42.3.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/33xvdgx6bql2ndk15r54aaabqwz55cfj-perl-5.42.3-devdoc
         /nix/store/kicabjkcmn9d87nzqlqpsz2lr53fvx73-perl-5.42.3
         /nix/store/yqr8fpr9can3hywyskhay55dglcrlivf-perl-5.42.3-man
error: Cannot build '/nix/store/jxq03c1w13vw3pknwlghd0gljnpyld5s-update-autotools-gnu-config-scripts-hook.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/ahdfsyd7vvr8vfxpx3hp7nxnzy0xdxyc-update-autotools-gnu-config-scripts-hook
error: Cannot build '/nix/store/i2hwapg78ag996cnraavpkdcsln6z9yp-autoconf-2.73.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/0rb7jz7gsmb6ml3nk4dnm87gxy0yfqnh-autoconf-2.73
         /nix/store/yz0z827cn7msxqirni0gblid186v9zfb-autoconf-2.73-doc
error: Cannot build '/nix/store/dh3hh0mfvdq60ps2fs27v0qqfm7bh3js-binutils-wrapper-2.46.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/dnwr9dl43bn505fjnv92c8x92s428kyy-binutils-wrapper-2.46
         /nix/store/q0nyqz06ik6glywp434s61ayknzn9wal-binutils-wrapper-2.46-info
         /nix/store/qq21cma9inl1f5a68w6j6q5fk7jyhv8h-binutils-wrapper-2.46-man
error: Cannot build '/nix/store/qdci2dags9j04qdw27xcdnyf81hhfgl6-bison-3.8.2.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/0ahh4whdh5if0frkzwlqnc312qda6rpw-bison-3.8.2
error: Cannot build '/nix/store/3y2yg6f21vl0bnx41cr9v9c3szcak9zj-bootstrap-stage-xgcc-stdenv-linux.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/8y5dc1nrv64pr3kljjrj7winvyx2ds1y-bootstrap-stage-xgcc-stdenv-linux
error: Cannot build '/nix/store/va3rfip3j3y7076i0sjjdcgll9rfr63s-bootstrap-stage1-stdenv-linux.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/k4x40g68sskl4adqf43267l3h0kwq5gb-bootstrap-stage1-stdenv-linux
error: Cannot build '/nix/store/yn2hgxldh8y3lvi1ylpn4sydlhfh7xac-bootstrap-stage1-stdenv-linux.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/4c0a7jbg3v3zrxln9hx55h2c4pvs49hx-bootstrap-stage1-stdenv-linux
error: Cannot build '/nix/store/3c3g4rj3f22k3yc33ig0qys0b13w8sfs-bootstrap-stage2-stdenv-linux.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/c32rjdp80y858cy15cjm6hjvrpkbp3ib-bootstrap-stage2-stdenv-linux
error: Cannot build '/nix/store/3bay12s3jprnb1mmwj1sp228zmycxm08-bootstrap-stage3-gcc-wrapper-15.3.0.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/afq5j6d2r8xny8js1sgpfcfarqvsc0hn-bootstrap-stage3-gcc-wrapper-15.3.0-info
         /nix/store/kqhzja1p9rm9mlpmi81dymclyjq7492p-bootstrap-stage3-gcc-wrapper-15.3.0
         /nix/store/kvh14ddqbq26988gpn057chwcb1x1dr3-bootstrap-stage3-gcc-wrapper-15.3.0-man
error: Cannot build '/nix/store/jkk1z1kfcc0f0xp21z3vn3cp06256lyh-bootstrap-stage4-gcc-wrapper-15.3.0.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/6715cr2f3sng8bd2fczvc85klfwxdpnz-bootstrap-stage4-gcc-wrapper-15.3.0-info
         /nix/store/6p8mxyqgqrl258n7r6b1rp04i01h3vbc-bootstrap-stage4-gcc-wrapper-15.3.0-man
         /nix/store/wfi75wqbb2ilvaj68y52gz8vzjk7sdi3-bootstrap-stage4-gcc-wrapper-15.3.0
error: Cannot build '/nix/store/rdmc14k0p11ss6i5q8ba9lkxnbirjj6q-cmake-4.1.6.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/3cxiwhir6jh69lrcvkwh3wdv1xbgrfb7-cmake-4.1.6-debug
         /nix/store/7zksmmig0mdh6ilr1135ilghjfh3mvdx-cmake-4.1.6
error: Cannot build '/nix/store/849zmrk92npiqlb6j87y9lmklwlirsf0-cmake-minimal-4.1.6.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/111sqdzjvqz377p0d13wgfplax4prch1-cmake-minimal-4.1.6-debug
         /nix/store/sj03vbpzl6w6qb45l4dp60c90ql6rdva-cmake-minimal-4.1.6
error: Cannot build '/nix/store/r9vpvd3jypb08ls8zh2mc4d05f4l2p7v-coreutils-9.11.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/g9maakqnxmsna2gzy5lzh06c99b8zl0n-coreutils-9.11
         /nix/store/isg5xs937yp1fhdlxihqhz70x6q1kwk2-coreutils-9.11-info
         /nix/store/mx33ldn9vlrz7fx7l3cqqx0r8vxjhir8-coreutils-9.11-debug
error: Cannot build '/nix/store/g4s52h2xdkdfdxs2k4jmzjyhybqdqdap-gcc-15.3.0.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/avl5g3330f84lsl64bl2305zhkngz6bh-gcc-15.3.0
         /nix/store/d4lmxbkn6ankjk57iv4m5lciqpyf65xb-gcc-15.3.0-checksum
         /nix/store/hq60lx418f1wqr5lql7bzi86afd46nz2-gcc-15.3.0-libgcc
         /nix/store/ib1m8rz22rdm6znmks8ykz4i3a187wfz-gcc-15.3.0-man
         /nix/store/pp0mc4kbjmg1vl3nfm6vlcv7ankis1rg-gcc-15.3.0-info
         /nix/store/vfy7k357br850rdgh31gz4y2arv7kzcp-gcc-15.3.0-lib
error: Cannot build '/nix/store/ynj2b8xz3cyk0r8mgjhgcq3a660bdzkh-gcc-wrapper-15.3.0.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/5hbk6kd3bwyz756hyln7snrv37sa27r2-gcc-wrapper-15.3.0-info
         /nix/store/8ni581b04da8baxd374n9v7z2mzp1bsj-gcc-wrapper-15.3.0
         /nix/store/p85kw7f0fixadbgxlzzmcxp7hq71pgcs-gcc-wrapper-15.3.0-man
error: Cannot build '/nix/store/2q62x0zmmrh366m1w8lr5wdab77ghh0w-glibc-iconv-2.42.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/8qwn3fj2rkavivkwg5iw3qhzv1a8pgdw-glibc-iconv-2.42
error: Cannot build '/nix/store/j8ln0lb80x6q9jakaf1qdl5l489w1pak-glibc-locales-2.42-100.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/pl00pcm26l335v8r1mrqvqivshvj9h03-glibc-locales-2.42-100
error: Cannot build '/nix/store/qn9jv58yyz10w1ds9hq8nz6mnh7wxglj-glibc-locales-2.42-100.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/3846zzhcp7wmzl3rgsw3wpy69vbshpcj-glibc-locales-2.42-100
error: Cannot build '/nix/store/8ky50nwcbs3hr4w33mpzn63k9j5qvgzp-libidn2-2.3.8.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/791n887i805vnb190zvyk7mq25k3kgvf-libidn2-2.3.8-bin
         /nix/store/iz63061v2zw52s82g5x5jrv76qq9rcfs-libidn2-2.3.8
         /nix/store/w254agsmhq86mxx2pxw6g8lmxr1l24v9-libidn2-2.3.8-dev
error: Cannot build '/nix/store/ih2ffvmf82n86x87ivbi9rvnmb0ywyfl-perl-5.42.3.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/c8i6sis9wb72y30ihz7nrfqn92d7bwgi-perl-5.42.3-man
         /nix/store/g45pw39fsc795j0w3ng0cpmzwn4d1dxh-perl-5.42.3
         /nix/store/i5mdcsc9wxaqx61sjqg3zppkw1xd040x-perl-5.42.3-devdoc
error: Cannot build '/nix/store/rggamrk4iwwz7h3nqplvw5c88lpp4jls-perl-5.42.3.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/200p26zgwdjhhbnr0jh09ylda9r9p34l-perl-5.42.3
         /nix/store/mj959cmy5yi301in9vfvrsr9awykw91h-perl-5.42.3-devdoc
         /nix/store/ygbhqvpr5h6jcag4nnrrp5rsccml2b2m-perl-5.42.3-man
error: Cannot build '/nix/store/i8qdlwxy6ydlwy7579jvh1zyq5mq52f4-stdenv-linux.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/4kdfx7s92667dl2c4kq5hgbiclvrqas4-stdenv-linux
error: Cannot build '/nix/store/wziplksbcmc1xjk6qyv5w1dlx22aym2w-stdenv-linux.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/9jnpwp9amlvmmigl5kg3k5vw4dg5h1y6-stdenv-linux
error: Cannot build '/nix/store/4jzgpi4g8lq8za1cfqk67pq00yzzvvfv-texinfo-7.2.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/3y09hy8w9m4m27zc97n83xqq1sqqymdv-texinfo-7.2
error: Cannot build '/nix/store/17afhqczma186iyd66543bqzvb8hma8p-nixos-rebuild-ng-26.05.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/h713m87kribn15anyxxzkfn1zxnwahzb-nixos-rebuild-ng-26.05-dist
         /nix/store/mprzr6wc0917q6q0gqw8zrh3310ll7v8-nixos-rebuild-ng-26.05
Command 'nix-build '<nixpkgs/nixos>' --attr config.system.build.nixos-rebuild --no-out-link' returned non-zero exit status 100.

My understanding is that result is a symlink to nix/store/.... What I want is to expose that nix store path to another computer as a binary cache, so that the second computer can install from there. However, after building the package and serving my nix/store as a binary cache, my second computer cannot pull from it. (If I install a package the “normal” way (using standard binaries Nix makes, not compiling from source), however, I can use that package’s representation in nix/storeto serve the binaries to another computer.)

OK, the first problem is that you added the skylake arch/tune in the same update you added gccarch-skylake to system features. your system does not yet have the feature enabled when it tries to do the build that enables the feature.

You need to add "gccarch-skylake" to nix.settings.system-features, then do a nixos-rebuild, and then add gcc.arch, gcc.arch to the host platform settings.

I believe you will probably run into further issues building the entire system closure for skylake (I ran into random build breakages recompiling for zen3), but this should at least get you past the first hurdle.

In this case, rather than creating an overlay, you can create a second instance of nixpkgs with the tuning and just pull a few packages from that. These packages (and their deps) will be built with the tuning you specify. Assuming you’re not using flakes:

{ config, lib, pkgs, ... }:
let
  tunedPkgs = import <nixpkgs> {
    localSystem = {
      gcc.arch = "skylake";
      gcc.tune = "skylake";
      system = "x86_64-linux"; # uname --machine to get this
    };
  };
in {
  environment.systemPackages = with pkgs; [
     # ...
     tunedPkgs.wget
     tunedPkgs.btop
  ];
};

see: Build flags - Official NixOS Wiki

Even if you expose your store as a binary cache, the other computer will not automatically pull the tuned derivations from it. This is because the tuned derivations have a different hash from the non-tuned version, and the other computer will need to have the same configuration.nix to compute the same hash.

What may be easier for you is telling nix to push the built configuration from one computer to another with nixos-rebuild --target-host that will do a cross-machine rebuild and deploy.