Compare commits

..

2 commits

Author SHA1 Message Date
bbc6f283ed Fixed kernel compile sccache caching
a little bit of chatgpt5.4 slop has fixed the kernel caching with sccache. Good stuff.
2026-03-09 02:35:23 +02:00
dd1c091312 fixup 2026-03-09 01:23:50 +02:00
4 changed files with 68 additions and 30 deletions

View file

@ -33,6 +33,7 @@ pkgs.callPackage (
{ buildLinux, ... }@args:
let
llvm = pkgs.llvmPackages_latest;
rust = pkgs.rustc-unwrapped;
# buildLinux uses common-flags.nix which sets CC to the *unwrapped* compiler:
# CC=${lib.getExe stdenv.cc.cc}
@ -43,31 +44,54 @@ pkgs.callPackage (
buildPkgs = args.buildPackages or pkgs.buildPackages;
realHostCC = lib.getExe' buildPkgs.stdenv.cc "${buildPkgs.stdenv.cc.targetPrefix}cc";
realHostCXX = lib.getExe' buildPkgs.stdenv.cc "${buildPkgs.stdenv.cc.targetPrefix}c++";
realRustc = lib.getExe rust;
realHostRustc = realRustc;
clangSccache = pkgs.writeShellScriptBin "clang" ''
set -euo pipefail
: "''${SCCACHE_ENFORCE_MARKER:?SCCACHE_ENFORCE_MARKER is not set}"
: > "''${SCCACHE_ENFORCE_MARKER}"
export SCCACHE_DIR=${lib.escapeShellArg sccacheDir}
if [ -n "''${SCCACHE_ENFORCE_MARKER-}" ]; then
: > "''${SCCACHE_ENFORCE_MARKER}"
fi
exec ${pkgs.sccache}/bin/sccache ${realClang} "$@"
'';
hostccSccache = pkgs.writeShellScriptBin "cc" ''
set -euo pipefail
: "''${SCCACHE_ENFORCE_MARKER:?SCCACHE_ENFORCE_MARKER is not set}"
: > "''${SCCACHE_ENFORCE_MARKER}"
export SCCACHE_DIR=${lib.escapeShellArg sccacheDir}
if [ -n "''${SCCACHE_ENFORCE_MARKER-}" ]; then
: > "''${SCCACHE_ENFORCE_MARKER}"
fi
exec ${pkgs.sccache}/bin/sccache ${realHostCC} "$@"
'';
hostcxxSccache = pkgs.writeShellScriptBin "c++" ''
set -euo pipefail
: "''${SCCACHE_ENFORCE_MARKER:?SCCACHE_ENFORCE_MARKER is not set}"
: > "''${SCCACHE_ENFORCE_MARKER}"
export SCCACHE_DIR=${lib.escapeShellArg sccacheDir}
if [ -n "''${SCCACHE_ENFORCE_MARKER-}" ]; then
: > "''${SCCACHE_ENFORCE_MARKER}"
fi
exec ${pkgs.sccache}/bin/sccache ${realHostCXX} "$@"
'';
rustcSccache = pkgs.writeShellScriptBin "rustc" ''
set -euo pipefail
export SCCACHE_DIR=${lib.escapeShellArg sccacheDir}
if [ -n "''${SCCACHE_ENFORCE_MARKER-}" ]; then
: > "''${SCCACHE_ENFORCE_MARKER}"
fi
exec ${pkgs.sccache}/bin/sccache ${realRustc} "$@"
'';
hostrustcSccache = pkgs.writeShellScriptBin "rustc" ''
set -euo pipefail
export SCCACHE_DIR=${lib.escapeShellArg sccacheDir}
if [ -n "''${SCCACHE_ENFORCE_MARKER-}" ]; then
: > "''${SCCACHE_ENFORCE_MARKER}"
fi
exec ${pkgs.sccache}/bin/sccache ${realHostRustc} "$@"
'';
structuredExtraConfig' =
(with lib.kernel; {
LTO_CLANG_THIN = yes;
@ -97,29 +121,41 @@ pkgs.callPackage (
"CC=${lib.getExe clangSccache}"
"HOSTCC=${lib.getExe hostccSccache}"
"HOSTCXX=${lib.getExe hostcxxSccache}"
"RUSTC=${lib.getExe rustcSccache}"
"HOSTRUSTC=${lib.getExe hostrustcSccache}"
];
# Enforce that the wrappers were actually invoked at least once.
# sccache is a compiler wrapper; this is the contract were enforcing. :contentReference[oaicite:4]{index=4}
# Start with clean stats so the build-phase check reports only this build.
preBuild =
(args.preBuild or "")
+ lib.optionalString enforceSccache ''
export SCCACHE_ENFORCE_MARKER="$NIX_BUILD_TOP/.sccache-used"
rm -f "$SCCACHE_ENFORCE_MARKER"
${pkgs.sccache}/bin/sccache --start-server || true
${pkgs.sccache}/bin/sccache --zero-stats || true
'';
postBuild =
(args.postBuild or "")
+ lib.optionalString enforceSccache ''
if [ ! -e "$SCCACHE_ENFORCE_MARKER" ]; then
echo "FATAL: sccache enforcement failed: compiler wrappers were not invoked."
echo "This means buildLinux did not use your CC/HOSTCC overrides."
exit 1
fi
${pkgs.sccache}/bin/sccache --show-stats --stats-format text || true
'';
buildPhase =
if enforceSccache then
''
runHook preBuild
export SCCACHE_ENFORCE_MARKER="$NIX_BUILD_TOP/.sccache-used"
rm -f "$SCCACHE_ENFORCE_MARKER"
make "''${makeFlags[@]}" "''${buildFlags[@]}"
if [ ! -e "$SCCACHE_ENFORCE_MARKER" ]; then
echo "FATAL: sccache enforcement failed during buildPhase: compiler wrappers were not invoked."
echo "This means the build stage did not use your CC/HOSTCC/HOSTCXX/RUSTC/HOSTRUSTC overrides."
exit 1
fi
${pkgs.sccache}/bin/sccache --show-stats --stats-format text || true
runHook postBuild
''
else
(args.buildPhase or ''
runHook preBuild
make "''${makeFlags[@]}" "''${buildFlags[@]}"
runHook postBuild
'');
postBuild = args.postBuild or "";
structuredExtraConfig = structuredExtraConfig';

View file

@ -55,12 +55,13 @@ final: prev: {
codex = prev.codex.overrideAttrs (
old:
let
version = "0.111.0";
version = "0.112.0";
src = prev.fetchFromGitHub {
owner = "openai";
repo = "codex";
tag = "rust-v${version}";
hash = "sha256-hdR70BhiMg9G/ibLCeHnRSY3PcGZDv0vnqBCbzSRD6I=";
hash = "sha256-tOrqGXh4k5GzcPhCUaiYoUVt4liYfgRd2ejkrdQpqWs=";
# hash = "";
};
in
{
@ -70,7 +71,8 @@ final: prev: {
cargoDeps = prev.rustPlatform.fetchCargoVendor {
inherit src;
sourceRoot = "${src.name}/codex-rs";
hash = "sha256-h+TIwNz+A6aYcMACWl//LiavABITZxwYa4CvawR/0RQ=";
hash = "sha256-2+9cIslfR8BD3oN6Icfpmzz9vDMGr1NcIwiHK3qoukE=";
# hash = prev.lib.fakeHash;
};
buildInputs = (old.buildInputs or [ ]) ++ [ prev.libcap ];

10
flake.lock generated
View file

@ -502,16 +502,16 @@
"kernel-src": {
"flake": false,
"locked": {
"lastModified": 1772925668,
"narHash": "sha256-P+xf11gGIe+VnHVS/vx13ejgevEsTjZ14I6AdMgMzio=",
"ref": "drm-tip",
"rev": "f705e865254996e9a099a22a9320e523e6debdcf",
"lastModified": 1770032463,
"narHash": "sha256-dNxD+k9uxBQdTEnAHN8oZXS4Wl3RhlxG71R5rxxwQAo=",
"ref": "refs/tags/drm-intel-next-fixes-2026-02-05",
"rev": "3e28a67a85f9b569066f6dfcddadb39294c0c9d4",
"shallow": true,
"type": "git",
"url": "https://gitlab.freedesktop.org/drm/tip.git"
},
"original": {
"ref": "drm-tip",
"ref": "refs/tags/drm-intel-next-fixes-2026-02-05",
"shallow": true,
"type": "git",
"url": "https://gitlab.freedesktop.org/drm/tip.git"

View file

@ -23,7 +23,7 @@
nix-flatpak.url = "github:gmodena/nix-flatpak/latest";
kernel-src = {
# url = "git+https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git?ref=master";
url = "git+https://gitlab.freedesktop.org/drm/tip.git?shallow=1&ref=drm-tip";
url = "git+https://gitlab.freedesktop.org/drm/tip.git?ref=refs/tags/drm-intel-next-fixes-2026-02-05&shallow=1";
flake = false;
};
sccache = {
@ -61,7 +61,7 @@
kernel-src = inputs.kernel-src;
};
modules = [
# ./custom/modules
./custom/modules
ragenix.nixosModules.default
niri-flake.nixosModules.niri
nix-index-database.nixosModules.default