Skip to content

Instantly share code, notes, and snippets.

@rrbutani
Created March 30, 2022 05:56
Show Gist options
  • Save rrbutani/3721f17caa74e9d2851c4e698c9df449 to your computer and use it in GitHub Desktop.
Save rrbutani/3721f17caa74e9d2851c4e698c9df449 to your computer and use it in GitHub Desktop.
{
description = "A very basic flake";
inputs.nixpkgs.url = github:nixos/nixpkgs/21.11;
inputs.flake-utils.url = github:numtide/flake-utils;
inputs.llvm-repo = {
flake = false;
# url = github:llvm/llvm-project?ref=a6d081b2cbc3348ed7261254ae7a563146b76d23;
url = github:llvm/llvm-project?ref=d7b669b3a30345cfcdb2fde2af6f48aa4b94845d; # 13.0.0
};
# LLVM 12; this needs to be in sync with our LLVM submodule.
# inputs.nixpkgsForLlvmBuildDefs.url = github:nixos/nixpkgs?ref=a7f062d8980f525ca484585015fc0deccc419728; # https://github.com/NixOS/nixpkgs/commit/a7f062d8980f525ca484585015fc0deccc419728
# inputs.nixpkgsForLlvmBuildDefs.url = github:nixos/nixpkgs?ref=83bf34642a6069fba3ca8ae32db3528ba6b202f5; # https://github.com/NixOS/nixpkgs/commit/83bf34642a6069fba3ca8ae32db3528ba6b202f5
# LLVM 13: right before the jump to 13.0.1:
inputs.nixpkgsForLlvmBuildDefs.url = github:nixos/nixpkgs?ref=e238f456b8d643d5afe5370e942e82204907d0ef; # https://github.com/NixOS/nixpkgs/commit/e238f456b8d643d5afe5370e942e82204907d0ef; before: https://github.com/NixOS/nixpkgs/commit/1a8754caf8eb8831b904daaf34b2ee737053b383
# Actually, right around our LLVM commit:
# inputs.nixpkgsForLlvmBuildDefs.url = github:nixos/nixpkgs?ref=b0f27ee74d36075656b6a9ff238254216d6c2687; # https://github.com/NixOS/nixpkgs/commit/b0f27ee74d36075656b6a9ff238254216d6c2687
outputs = { self, nixpkgs, flake-utils, llvm-repo, nixpkgsForLlvmBuildDefs }: with flake-utils.lib; eachDefaultSystem (system: let
# dbg = x: builtins.trace x x;
dbg = x: x;
# !!! This is faster for testing since we get to
# skip building with `?submodules=1` and copying in the whole submodule to
# the nix store on every change to this file.
llvmSourceRoot = llvm-repo;
# llvmSourceRoot = ./llvm;
# the stdenv builder copies `src` into a folder matching the derivation's name; older versions of
# the git LLVM nixpkg assume that this derivation is called `source` (as is the default for
# fetchFromGitHub and other fetchers)
#
# so, we wrap our llvm repo in a derivation named "source" to match:
wrappedLlvmSourceRoot = with nixpkgs.legacyPackages.${system}; runCommand "source" {} ''
# ln -s ${llvmSourceRoot} $out; chmod -R u+w $out;
cp -R ${llvmSourceRoot} $out; # Wasteful but, alas. Got to be able to change permissions.
'';
# llvmPackages is a bit weird; it's two disjoint overridable sets that
# reference each other through `buildLlvmTools` and `targetLlvmLibraries`.
#
# properly overriding packages in these requires a little bit of ceremony:
modifyLlvmPackages = base:
{ toolsFunc ? final: prev: {}
, libsFunc ? final: prev: {}
}:
let
tools = base.tools.extend toolsFunc;
libraries = base.libraries.extend libsFunc;
in
{
inherit (base) release_version;
inherit tools libraries;
} // tools // libraries;
llvmPackageList = let
# real cmake builds under `llvmPackages.libraries`:
# https://github.com/NixOS/nixpkgs/blob/904ed45698338365f086c22ab5af167adf8bee9a/pkgs/development/compilers/llvm/13/default.nix#L216
actualLibraries = [
"compiler-rt-libc"
"compiler-rt-no-libc"
# "compiler-rt" # Just an alias
# "stdenv" # Just a wrapper
# "libcxxStdenv" # Just a wrapper
"libcxx"
"libcxxabi"
"libunwind"
"openmp"
];
# real cmake builds under `llvmPackages.tools`:
# https://github.com/NixOS/nixpkgs/blob/904ed45698338365f086c22ab5af167adf8bee9a/pkgs/development/compilers/llvm/13/default.nix#L41-L42
actualTools = [
"libllvm"
# "llvm" # Just an alias to `libllvm`
"libclang"
# "clang-unwrapped" # Just an alias to `libclang`
"llvm-manpages" # An override of `libllvm`
"clang-manpages" # An override of `libclang`
# "clang" # Just an alias of `libstdcxxClang` or `libcxxClang`
# "libstdcxxClang" # Just a cc wrapper
# "libcxxClang" # Just a cc wrapper
"lld"
"lldb"
# "bintools-unwrapped" # Just makes some symlinks to things in `llvm`
# "bintoolsNoLibc" # Just a bintools wrapper
# "bintools" # Just a bintools wrapper
# "clangUseLLVM" # Just a cc wrapper
# "clangNoLibcxx" # Just a cc wrapper
# "clangNoLibc" # Just a cc wrapper
# "clangNoCompilerRt" # Just a cc wrapper
# "clangNoCompilerRtWithLibc" # Just a cc wrapper
];
in {
inherit actualLibraries actualTools;
} // { allActuals = actualLibraries ++ actualTools; };
llvmOverlay = final': prev': let
llvmPackagesCustomUnpatched = nixpkgs.lib.recurseIntoAttrs (prev'.callPackage "${nixpkgsForLlvmBuildDefs}/pkgs/development/compilers/llvm/13" {
inherit (prev'.stdenvAdapters) overrideCC;
buildLlvmTools = final'.llvmPackagesCustom.tools;
targetLlvmLibraries = final'.llvmPackagesCustom.libraries;
fetchFromGitHub = with prev'.lib; args@{ owner, repo, ... }:
let
isLlvmFetch = owner == "llvm" && repo == "llvm-project";
in
if isLlvmFetch
then
"${wrappedLlvmSourceRoot}"
else
prev'.fetchFromGitHub args;
});
addCmakeFlagsToPackage = pkg: flags:
pkg.overrideAttrs (old: { cmakeFlags = old.cmakeFlags ++ flags; });
MUSL = "-DLIBCXX_HAS_MUSL_LIBC=1";
ASSERTIONS = "-DLLVM_ENABLE_ASSERTIONS=1";
addWithAssertions = base: names:
builtins.listToAttrs (builtins.map (n:
{
name = n;
value = addCmakeFlagsToPackage (base.${n}) [ASSERTIONS];
}
) names);
# Enable assertions, add musl support, and fix `libcxxabi` linking:
llvmPackagesCustom = modifyLlvmPackages llvmPackagesCustomUnpatched {
toolsFunc = final: prev: (addWithAssertions prev llvmPackageList.actualTools) // {
# We need to add `-lc++abi` as a linkopt.
#
# See: https://github.com/NixOS/nixpkgs/issues/166205
#
# We're essentially adding this: https://github.com/NixOS/nixpkgs/blob/3491c5ea290bca5437845b6348919fcb23950af9/pkgs/build-support/cc-wrapper/default.nix#L382
libcxxClang = prev.libcxxClang.overrideAttrs (old: {
postFixup = old.postFixup + (if prev'.stdenv.isDarwin then ''
echo "-lc++abi" >> $out/nix-support/libcxx-ldflags
'' else "");
});
};
libsFunc = final: prev: (addWithAssertions prev llvmPackageList.actualLibraries) // rec {
# We want to add `-DLIBCXX_HAS_MUSL_LIBC=ON` to the cmake flags
# for `libcxx`.
#
# This is a `libcxx` option however the `libcxx` package gets
# instantiated twice: once for `libraries.libcxx` and another
# time in it's header-only configuration as an arg to the
# `libcxxabi` package.
#
# It's unclear if this is necessary, but we override both of
# these:
libcxx = (addCmakeFlagsToPackage prev.libcxx [MUSL ASSERTIONS]).overrideAttrs (old: {
# See: https://github.com/NixOS/nixpkgs/blob/290c4eaf6c69aa34e81e81b4f9ffcacf8e908fce/pkgs/development/compilers/llvm/13/libcxx/default.nix#L24-L26
patches = old.patches ++ ["${nixpkgsForLlvmBuildDefs}/pkgs/development/compilers/llvm/libcxx-0001-musl-hacks.patch"];
# See: https://github.com/NixOS/nixpkgs/blob/290c4eaf6c69aa34e81e81b4f9ffcacf8e908fce/pkgs/development/compilers/llvm/13/libcxx/default.nix#L28-L30
preConfigure = old.preConfigure + ''
patchShebangs utils/cat_files.py
'' +
# This is bad and doesn't make sense; the `xlocale.h` stubs in
# libc++ for use when linking against `musl` conflict with the
# signatures defined in `glibc` for these functions.
#
# It's not clear to me why this is a problem on Nix but not
# elsewhere; other `glibc`s also declare these symlinks `extern`
# (which conflicts with `static`) and the intent is definitely to
# include these system headers (`#include_next<>`).
#
# Perhaps something about the nix cc setup is setting `__USE_GNU`? I
# don't think so, though.
''
sed -i 's/static inline/inline/g' include/__support/musl/xlocale.h
'';
# __contentAddressed = true; # unfortunately this breaks the clang stdenv
});
libcxxabi = addCmakeFlagsToPackage (prev.libcxxabi.override {
# Can't recover the `cxx-headers` originally passed to `libcxxabi`
# so we reconstruct it (just `libcxx` w/`headersOnly = true`).
cxx-headers = addCmakeFlagsToPackage
(libcxx.override { headersOnly = true; })
[MUSL ASSERTIONS];
}) [ASSERTIONS];
};
};
in {
inherit llvmPackagesCustom;
};
# llvmOverlay = final: prev: let
# llvmPackagesCustom = nixpkgs.lib.recurseIntoAttrs (prev.callPackage "${nixpkgs}/pkgs/development/compilers/llvm/12" ({
# # llvmPackagesCustom = nixpkgs.lib.recurseIntoAttrs (prev.callPackage "${nixpkgs}/pkgs/development/compilers/llvm/13" ({
# inherit (prev.stdenvAdapters) overrideCC;
# # targetLlvmLibraries = final.targetPackages.llvmPackages_12.libraries or final.llvmPackages_12.libraries;
# # buildLlvmTools = final.llvmPackagesCustom.tools;
# # buildLlvmTools = final.buildPackages.llvmPackages_12.tools;
# buildLlvmTools = final.llvmPackagesCustom.tools;
# targetLlvmLibraries = final.llvmPackagesCustom.libraries;
# # targetLlvmLibraries = llvmPackagesCustom.libraries; # !!! not sure why ^ doesn't work...
# fetchurl = with prev.lib; args@{ url, ... }:
# # "https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/${name}-${release_version}${candidate}.src.tar.xz";
# let
# urlPrefix = "https://github.com/llvm/llvm-project/releases/download/llvmorg-";
# isLlvmFetch = hasPrefix urlPrefix url;
# # baseReleaseVersion = "12.0.1";
# in
# if isLlvmFetch
# then let
# component = (builtins.elemAt (splitString "/" (builtins.head (splitString "-${baseReleaseVersion}" (removePrefix urlPrefix url)))) 1);
# compressed = with nixpkgs.legacyPackages.${system}; runCommand "source-${component}" {} ''
# mkdir -p $out
# set -x
# tar cf $out/archive.tar -C ${llvmSourceRoot} ${component} --mode='u+rwX' --transform "s,^${component},${component}-${baseReleaseVersion},"
# '';
# in
# # "${llvmSourceRoot}/${component}"
# "${compressed}/archive.tar"
# else
# prev.fetchurl args;
# }
# # // lib.optionalAttrs (stdenv.hostPlatform.isi686 && buildPackages.stdenv.cc.isGNU) {
# # stdenv = gcc7Stdenv;
# # }
# ));
# llvmPackagesCustom = nixpkgs.lib.recurseIntoAttrs (prev.callPackage "${nixpkgsForLlvmBuildDefs}/pkgs/development/compilers/llvm/git" ({
# inherit (prev.stdenvAdapters) overrideCC;
# buildLlvmTools = final.buildPackages.llvmPackages_12.tools;
# targetLlvmLibraries = final.targetPackages.llvmPackages.libraries or final.llvmPackages.libraries;
# fetchFromGitHub = with prev.lib; args@{ owner, repo, ... }:
# let
# isLlvmFetch = owner == "llvm" && repo == "llvm-project";
# in
# if isLlvmFetch
# then
# "${dbg wrappedLlvmSourceRoot}"
# else
# prev.fetchFromGitHub args;
# }
# // lib.optionalAttrs (stdenv.hostPlatform.isi686 && buildPackages.stdenv.cc.isGNU) {
# stdenv = gcc7Stdenv;
# }
# ));
# in {
# # llvmPackages = llvmPackagesCustom;
# inherit llvmPackagesCustom;
# };
# See: https://github.com/leanprover/lean4/blob/b40cf1d1712ae7b1585ecd75a533a5fb3030bded/nix/packages.nix#L18-L31
# (!!!: if you change this you invalidate ccache's cache!)
ccacheExtraConfig = cc: ''
export CCACHE_DIR=/nix/var/cache/ccache
[ -d $CCACHE_DIR ] || { exec ${cc}/bin/$(basename "$0") "$@"; }
# export CCACHE_UMASK=007
# export CCACHE_COMPRESS=1
export CCACHE_BASE_DIR=$NIX_BUILD_TOP
# See: https://github.com/NixOS/nixpkgs/issues/109033
args=("$@")
for ((i=0; i<"''${#args[@]}"; i++)); do
case ''${args[i]} in
-frandom-seed=*) unset args[i]; break;;
esac
done
set -- "''${args[@]}"
# echo "''${args[@]}" >> $CCACHE_DIR/log
'';
cachedStdenv = { nixpkgs, stdenv ? nixpkgs.stdenv }:
let
ccacheWrapper = nixpkgs.makeOverridable ({ extraConfig, cc }:
cc.override {
cc = nixpkgs.buildPackages.ccache.links {
inherit extraConfig;
unwrappedCC = cc.cc;
};
}) {
extraConfig = ccacheExtraConfig stdenv.cc.cc;
inherit (stdenv) cc;
};
ccacheWrapperNoResponseFiles = ccacheWrapper
.overrideAttrs (old: {
# https://github.com/NixOS/nixpkgs/issues/119779
installPhase = builtins.replaceStrings ["use_response_file_by_default=1"] ["use_response_file_by_default=0"] old.installPhase;
});
ccacheStdenv = nixpkgs.lowPrio (nixpkgs.makeOverridable ({ stdenv, ... } @ extraArgs:
nixpkgs.overrideCC stdenv (ccacheWrapperNoResponseFiles.override ({
inherit (stdenv) cc;
} // nixpkgs.lib.optionalAttrs (builtins.hasAttr "extraConfig" extraArgs) {
extraConfig = extraArgs.extraConfig;
}))) {
inherit stdenv;
});
in
ccacheStdenv;
# llvmPackagesToCache = [
# # "bintools"
# "bintools-unwrapped"
# # "bintoolsNoLibc"
# # "clang" # just libstdcxxclang or libcxxclang
# # "clang-manpages"
# # missing !!! # "clang-polly-unwrapped"
# # "clang-unwrapped" # just `libclang`
# # "clangNoCompilerRt"
# # "clangNoLibcxx"
# # "clangUseLLVM"
# "compiler-rt"
# # "compiler-rt-libc"
# # "compiler-rt-no-libc"
# "libclang"
# "libcxx"
# # libcxxClang
# # libcxxStdenv
# "libcxxabi"
# "libllvm"
# # missing !!! # "libllvm-polly"
# # libraries
# # libstdcxxClang
# "libunwind"
# "lld"
# "lldb"
# # "llvm" # just `libllvm`
# # llvm-manpages
# # missing !!! # "llvm-polly"
# "openmp"
# # override
# # overrideDerivation
# # recurseForDerivations
# # release_version
# # stdenv
# # tools
# ];
# llvmPackagesToCache = [
# "bintools-unwrapped"
# "compiler-rt"
# "libclang"
# "libcxx"
# "libcxxabi"
# "libllvm"
# "libunwind"
# "lld"
# "lldb"
# "openmp"
# ];
llvmPackagesToCache = llvmPackageList.allActuals;
# cacheLlvmPackages = base: stdenv: nixpkgs:
# let
# cachedStdenv' = cachedStdenv { inherit nixpkgs stdenv; };
# in
# (builtins.removeAttrs base llvmPackagesToCache) //
# (
# builtins.listToAttrs (builtins.map (n:
# {
# name = builtins.trace (builtins.trace n base.${n}.override) n;
# value = base.${n}.override {
# stdenv = cachedStdenv';
# };
# }
# ) llvmPackagesToCache)
# );
# cacheLlvmPackages = base: stdenv: nixpkgs:
# let
# cachedStdenv' = cachedStdenv { inherit nixpkgs stdenv; };
# in
# base.extend (final: prev:
# (
# builtins.listToAttrs (builtins.map (n:
# {
# # name = builtins.trace (builtins.trace n prev.${n}.override) n;
# name = n;
# # this should work but I think the co-recursion breaks it?
# # not sure tbh (TODO)
# #
# # edit: nvm it was the trace above
# value = prev.${n}.override {
# stdenv = cachedStdenv';
# };
# # value = null;
# # base.${n}.override {
# # stdenv = cachedStdenv';
# # };
# }
# ) llvmPackagesToCache)
# ));
cacheLlvmPackages = base: stdenv: nixpkgs:
let
cachedStdenv' = cachedStdenv { inherit nixpkgs stdenv; };
overrideWithCachedStdenv = (final: prev:
builtins.listToAttrs (builtins.map
(n: {
name = n;
value = prev.${n}.override {
stdenv = cachedStdenv';
};
})
(builtins.filter (n: builtins.hasAttr n prev) llvmPackagesToCache)
)
);
in
modifyLlvmPackages base {
toolsFunc = overrideWithCachedStdenv;
libsFunc = overrideWithCachedStdenv;
};
# tools = base.tools.extend overrideWithCachedStdenv;
# libraries = base.libraries.extend overrideWithCachedStdenv;
# in
# { inherit (base) release_version; inherit tools libraries; } // tools // libraries;
llvmCacheCustomOverlay = final: prev: {
# Because we're unilaterally overriding the `stdenv` here and not respecting
# the stdenv manipulation individual packages do, we need to be careful.
#
# For LLVM specifically, libc++ is very particular about its compiler version;
# the current Linux default of GCC9 is actually not new enough for LLVM13's libc++:
# https://bugs.llvm.org/show_bug.cgi?id=51359
# https://github.com/NixOS/nixpkgs/blob/904ed45698338365f086c22ab5af167adf8bee9a/pkgs/development/compilers/llvm/13/default.nix#L248-L251
#
# So, to be safe, we just use gcc-10 across the board, if we're using gcc, instead
# of the default stdenv.
llvmPackagesCustom = let
stdenv = prev.stdenv;
# dbg = x: builtins.trace x x;
# baseStdenv = if stdenv.cc.isGNU && prev.lib.versionOlder stdenv.cc.version "10"
baseStdenv = if stdenv.isLinux
# On aarch64, we get errors about symbols like `__aarch64_ldadd4_relax` that are
# outlined.
#
# See: https://bugzilla.redhat.com/show_bug.cgi?id=1830472
# See: https://github.com/rust-lang/git2-rs/issues/706#issuecomment-836198499
#
# So, we just use `clang-12` instead.
then # prev.gcc10Stdenv
prev.llvmPackages_12.stdenv
# I am not sure why, but when we build `lc++` with musl support with the nix cc-wrapper,
# the glibc version (wchar.h) of the symbols in `xlocale.h` interfere with the libc++ shims.
#
# To get around this here we just don't use `glibc`.
#
# This is not a good solution and I am very confused as to how the glibc
# then prev.pkgsMusl.gcc10Stdenv # TODO: undo the manual application of the `musl` patches? they don't actually do anything on macOS...
# then prev.llvmPackages_12.stdenv
else stdenv;
in
cacheLlvmPackages prev.llvmPackagesCustom baseStdenv prev;
# llvmPackagesCustom = null;
};
# The fact that we apply `override`s after the `overrideAttr`s is okay. Consider:
#
# ```nix
# n = import <nixpkgs> {}
# func = { abc }: n.stdenv.mkDerivation { name = "test"; inherit abc; }
# base = n.callPackage func { abc = 3; }
#
# p = x: if x ? bcd then x.bcd else x.abc
#
# p base ## outputs 3 as expected
# p (base.override { abc = 4; }) ## outputs 4 as expected
# p (base.overrideAttrs (old: { abc = old.abc + 2; })) ## outputs 5 as expected
#
# p ((base.override { abc = 4; }).overrideAttrs (old: { abc = old.abc + 2; }))
# ## ^ outputs 6 as expected
#
# p (base.overrideAttrs (old: { bcd = 7; })) ## outputs 7
# p ((base.overrideAttrs (old: { bcd = 7; })).override { abc = 4; }) ## outputs 7, still!
#
# t = ((base.overrideAttrs (old: { bcd = 7; abc = old.abc + 9; })).override { abc = 4; })
# t.abc
# t.bcd
#
# d = builtins.trace
# t = ((base.overrideAttrs (old: { bcd = 7; abc = d "a" (old.abc + 9); })).override { abc = d "b" 4; }).overrideAttrs (old: { abc = d "c" (old.abc * 4); })
# # trace: c
# # trace: a
# # trace: b
# t.abc # 52
# t.bcd
# ```
#
# I am not sure how this happens; does `overrideAttrs` update the override function?
# I think it's actually because we keep the functions around and apply them. But it's
# not as simple as applying them recursively in reverse order since the
# `override | overrideAttrs` case still works.
nixpkgs' = import nixpkgs {
overlays = [
llvmOverlay
llvmCacheCustomOverlay
];
inherit system;
# config.replaceStdenv = p: p.ccacheStdenv.override { extraConfig = ccacheExtraConfig; };
};
clang11 = nixpkgs'.llvmPackages.clang;
clang11U = nixpkgs'.llvmPackages.clang-unwrapped;
llvm = nixpkgs'.llvmPackages.libllvm;
clangCustom = nixpkgs'.llvmPackagesCustom.clang;
clangCustomU = nixpkgs'.llvmPackagesCustom.clang-unwrapped;
llvmCustom = nixpkgs'.llvmPackagesCustom.libllvm;
stdenvCustom = nixpkgs'.llvmPackagesCustom.libraries.libcxxStdenv;
# stdenvCustom = nixpkgs'.llvmPackagesCustom.stdenv;
# nixpkgs'' = import nixpkgs { inherit system; config.replaceStdenv = p: nixpkgs'.llvmPackagesCustom.libcxxStdenv; };
# `clang-13` added support for `--print-multiarch`; this confuses the Python configure script
#
# See: https://bugs.python.org/issue45405
#
# This is fixed in 3.9.8 and 3.10.1 but nixpkgs 21.11 is stuck on 3.9.6.
#
# So, we apply this patch: https://github.com/python/cpython/commit/9901d153c201d852d27dc9d3074e283c26468f6d
python39Clang13FixOverlay = final: prev: {
python39 = prev.python39.overrideAttrs (old: {
patches = old.patches ++ [
(nixpkgs'.fetchpatch {
url = "https://github.com/python/cpython/commit/9901d153c201d852d27dc9d3074e283c26468f6d.patch";
sha256 = "sha256-Dt/qjTGjSKlYoBauK8GywkvKeMT0iAR7/RT7D9IiGuY=";
})
];
# An additional build error: https://github.com/NixOS/nixpkgs/issues/158091
# See: https://github.com/NixOS/nixpkgs/issues/154120
# And: https://github.com/NixOS/nixpkgs/commit/49a0059a59a950c9261325fad14a2f905f53036d
prePatch = builtins.replaceStrings
["substituteInPlace configure --replace '-Wl,-stack_size,1000000' ' '"]
[""]
old.prePatch;
preConfigure = builtins.replaceStrings
[
''export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -msse2"''
''export MACOSX_DEPLOYMENT_TARGET=10.6''
]
["" ""]
old.preConfigure;
});
};
nixpkgs'' = import nixpkgs {
inherit system;
# config.replaceStdenv = p: p.ccacheStdenv.override {
# extraConfig = ccacheExtraConfig;
# stdenv = stdenvCustom;
# };
config.replaceStdenv = p: stdenvCustom;
# This helps a little when iterating on the compiler/changing the stdenv and
# when building packages from "scratch" with `nixpkgs''`: packages that don't
# directly depend on the compiler will not need to be rebuilt assuming the
# compiler change is a no-op and libraries produced are unchanged.
config.contentAddressedByDefault = true;
overlays = [
python39Clang13FixOverlay
];
};
# nixpkgs'' = import nixpkgs { inherit system; config.replaceStdenv = p: nixpkgs'.llvmPackages.stdenv; };
# test = nixpkgs'.neofetch.override { inherit stdenv; }; # Can handle only rebuilding the things that need to be rebuilt yourself
pkgName = "neofetch";
test = nixpkgs''.${pkgName}; # Or you can use the big hammer
in {
packages.clang = clang11;
packages.clangCustom = clangCustom;
packages.llvm = llvm;
packages.llvmCustom = llvmCustom;
packages.test = test;
defaultPackage = clangCustom;
# TODO: broken
lib.stdenv = stdenvCustom;
lib.nixpkgs = nixpkgs';
lib.nixpkgsCustom = nixpkgs'';
defaultApp = { type = "app"; program = "${clangCustom}/bin/clang"; };
apps.clang = { type = "app"; program = "${clang11}/bin/clang"; };
apps.clangU = { type = "app"; program = "${clang11U}/bin/clang"; };
apps.clangCustom = { type = "app"; program = "${clangCustom}/bin/clang"; };
apps.clangCustomU = { type = "app"; program = "${clangCustomU}/bin/clang"; };
apps.test = { type = "app"; program = "${test}/bin/${pkgName}"; };
devShells = {
normal = nixpkgs'.mkShell {};
# normal = (nixpkgs'.mkShell.override { stdenv = nixpkgs'.llvmPackages_12.stdenv; }) {};
customFull = nixpkgs''.mkShell { };
# TODO: broken, doesn't actually use the stdenv
# customStdenv = nixpkgs'.mkShell { stdenv = stdenvCustom; };
# This seems to work though:
# customStdenv = nixpkgs'.stdenvCustom.mkShell { };
# customStdenv = nixpkgs'.stdenvCustom.mkShell { };
customStdenv = (nixpkgs'.mkShell.override { stdenv = stdenvCustom; }) { };
};
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment