···20 ips = [ "9.9.9.9" "149.112.112.112" ];
21 url = "https://dns.quad9.net/dns-query";
22 };
000000023 };
2425 defaultProvider = "quad9";
2627 providerCfg =
28- let
29- isCustom = cfg.provider.kind == "custom";
30- in
31- lib.concatStringsSep " " [
32 "-b"
33- (concatStringsSep "," (if isCustom then cfg.provider.ips else providers."${cfg.provider.kind}".ips))
34 "-r"
35- (if isCustom then cfg.provider.url else providers."${cfg.provider.kind}".url)
36 ];
3738in
···62 The upstream provider to use or custom in case you do not trust any of
63 the predefined providers or just want to use your own.
6465- The default is ${defaultProvider} and there are privacy and security trade-offs
66- when using any upstream provider. Please consider that before using any
67- of them.
6869- If you pick a custom provider, you will need to provide the bootstrap
70- IP addresses as well as the resolver https URL.
0071 '';
72- type = types.enum ((builtins.attrNames providers) ++ [ "custom" ]);
73 default = defaultProvider;
74 };
75···105 config = lib.mkIf cfg.enable {
106 systemd.services.https-dns-proxy = {
107 description = "DNS to DNS over HTTPS (DoH) proxy";
0108 after = [ "network.target" ];
00109 wantedBy = [ "multi-user.target" ];
110 serviceConfig = rec {
111 Type = "exec";
112 DynamicUser = true;
0113 ExecStart = lib.concatStringsSep " " (
114 [
115- "${pkgs.https-dns-proxy}/bin/https_dns_proxy"
116 "-a ${toString cfg.address}"
117 "-p ${toString cfg.port}"
118 "-l -"
···20 ips = [ "9.9.9.9" "149.112.112.112" ];
21 url = "https://dns.quad9.net/dns-query";
22 };
23+ opendns = {
24+ ips = [ "208.67.222.222" "208.67.220.220" ];
25+ url = "https://doh.opendns.com/dns-query";
26+ };
27+ custom = {
28+ inherit (cfg.provider) ips url;
29+ };
30 };
3132 defaultProvider = "quad9";
3334 providerCfg =
35+ concatStringsSep " " [
00036 "-b"
37+ (concatStringsSep "," providers."${cfg.provider.kind}".ips)
38 "-r"
39+ providers."${cfg.provider.kind}".url
40 ];
4142in
···66 The upstream provider to use or custom in case you do not trust any of
67 the predefined providers or just want to use your own.
6869+ The default is ${defaultProvider} and there are privacy and security
70+ trade-offs when using any upstream provider. Please consider that
71+ before using any of them.
7273+ Supported providers: ${concatStringsSep ", " (builtins.attrNames providers)}
74+75+ If you pick the custom provider, you will need to provide the
76+ bootstrap IP addresses as well as the resolver https URL.
77 '';
78+ type = types.enum (builtins.attrNames providers);
79 default = defaultProvider;
80 };
81···111 config = lib.mkIf cfg.enable {
112 systemd.services.https-dns-proxy = {
113 description = "DNS to DNS over HTTPS (DoH) proxy";
114+ requires = [ "network.target" ];
115 after = [ "network.target" ];
116+ wants = [ "nss-lookup.target" ];
117+ before = [ "nss-lookup.target" ];
118 wantedBy = [ "multi-user.target" ];
119 serviceConfig = rec {
120 Type = "exec";
121 DynamicUser = true;
122+ ProtectHome = "tmpfs";
123 ExecStart = lib.concatStringsSep " " (
124 [
125+ (lib.getExe pkgs.https-dns-proxy)
126 "-a ${toString cfg.address}"
127 "-p ${toString cfg.port}"
128 "-l -"
···1+## How to upgrade llvm_git
2+3+- Run `update-git.py`.
4+ This will set the github revision and sha256 for `llvmPackages_git.llvm` to whatever the latest chromium build is using.
5+ For a more recent, commit run `nix-prefetch-github` and change the rev and sha256 accordingly.
6+7+- That was the easy part.
8+ The hard part is updating the patch files.
9+10+ The general process is:
11+12+ 1. Try to build `llvmPackages_git.llvm` and associated packages such as
13+ `clang` and `compiler-rt`. You can use the `-L` and `--keep-failed` flags to make
14+ debugging patch errors easy, e.g., `nix build .#llvmPackages_git.clang -L --keep-failed`
15+16+ 2. The build will error out with something similar to this:
17+ ```sh
18+ ...
19+ clang-unstable> patching sources
20+ clang-unstable> applying patch /nix/store/nndv6gq6w608n197fndvv5my4a5zg2qi-purity.patch
21+ clang-unstable> patching file lib/Driver/ToolChains/Gnu.cpp
22+ clang-unstable> Hunk #1 FAILED at 487.
23+ clang-unstable> 1 out of 1 hunk FAILED -- saving rejects to file lib/Driver/ToolChains/Gnu.cpp.rej
24+ note: keeping build directory '/tmp/nix-build-clang-unstable-2022-25-07.drv-17'
25+ error: builder for '/nix/store/zwi123kpkyz52fy7p6v23azixd807r8c-clang-unstable-2022-25-07.drv' failed with exit code 1;
26+ last 8 log lines:
27+ > unpacking sources
28+ > unpacking source archive /nix/store/mrxadx11wv1ckjr2208qgxp472pmmg6g-clang-src-unstable-2022-25-07
29+ > source root is clang-src-unstable-2022-25-07/clang
30+ > patching sources
31+ > applying patch /nix/store/nndv6gq6w608n197fndvv5my4a5zg2qi-purity.patch
32+ > patching file lib/Driver/ToolChains/Gnu.cpp
33+ > Hunk #1 FAILED at 487.
34+ > 1 out of 1 hunk FAILED -- saving rejects to file lib/Driver/ToolChains/Gnu.cpp.rej
35+ For full logs, run 'nix log /nix/store/zwi123kpkyz52fy7p6v23azixd807r8c-clang-unstable-2022-25-07.drv'.
36+ note: keeping build directory '/tmp/nix-build-compiler-rt-libc-unstable-2022-25-07.drv-20'
37+ error: 1 dependencies of derivation '/nix/store/ndbbh3wrl0l39b22azf46f1n7zlqwmag-clang-wrapper-unstable-2022-25-07.drv' failed to build
38+ ```
39+40+ Notice the `Hunk #1 Failed at 487` line.
41+ The lines above show us that the `purity.patch` failed on `lib/Driver/ToolChains/Gnu.cpp` when compiling `clang`.
42+43+ 3. The task now is to cross reference the hunks in the purity patch with
44+ `lib/Driver/ToolCahins/Gnu.cpp.orig` to see why the patch failed.
45+ The `.orig` file will be in the build directory referenced in the line `note: keeping build directory ...`;
46+ this message results from the `--keep-failed` flag.
47+48+ 4. Now you should be able to open whichever patch failed, and the `foo.orig` file that it failed on.
49+ Correct the patch by adapting it to the new code and be mindful of whitespace;
50+ which can be an easily missed reason for failures.
51+ For cases where the hunk is no longer needed you can simply remove it from the patch.
52+53+ This is fine for small corrections, but when more serious changes are needed its better to use git.
54+55+ 1. Clone the LLVM monorepo at https://github.com/llvm/llvm-project/
56+57+ 2. Check out the revision we were using before.
58+59+ 3. Use `patch -p1 < path/to-path` in the project subdirectories to apply the patches and commit.
60+61+ 4. Use `git rebase HEAD^ --onto <dest>` to rebase the patches onto the new revision we are trying to build, and fix all conflicts.
62+63+ 5. Use `git diff HEAD^:<project> HEAD:<project>` to get subdir diff to write back to Nixpkgs.
64+65+## Information on our current patch sets
66+67+### "GNU Install Dirs" patches
68+69+Use CMake's [`GNUInstallDirs`](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html) to support multiple outputs.
70+71+Previously, LLVM Just hard-coded `bin`, `include`, and `lib${LLVM_TARGET_PREFIX}`.
72+We are making it use these variables.
73+74+For the older LLVM versions, these patches live in https://github.com/Ericson2314/llvm-project branches `split-prefix`.
75+Instead of applying the patches to the worktree per the above instructions, one can checkout those directly and rebase those instead.
76+77+For newer LLVM versions, enough has has been upstreamed,
78+(see https://reviews.llvm.org/differential/query/5UAfpj_9zHwY/ for my progress upstreaming),
79+that I have just assembled new gnu-install-dirs patches from the remaining unmerged patches instead of rebasing from the prior LLVM's gnu install dirs patch.
···1-diff --git a/CMakeLists.txt b/CMakeLists.txt
2-index c5003b5efa1d..4fffb9721284 100644
3---- a/CMakeLists.txt
4-+++ b/CMakeLists.txt
5-@@ -5,6 +5,8 @@
6-7- cmake_minimum_required(VERSION 3.13.4)
8-9-+include(GNUInstallDirs)
10-+
11- # Check if compiler-rt is built as a standalone project.
12- if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD)
13- project(CompilerRT C CXX ASM)
14diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake
15-index 1ada0ab30ba0..b4be6c4a3c73 100644
16--- a/cmake/base-config-ix.cmake
17+++ b/cmake/base-config-ix.cmake
18-@@ -66,7 +66,7 @@ if (LLVM_TREE_AVAILABLE)
19- else()
20- # Take output dir and install path from the user.
21- set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH
22-- "Path where built compiler-rt libraries should be stored.")
23-+ "Path where built compiler-rt build artifacts should be stored.")
24- set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH
25- "Path where built compiler-rt executables should be stored.")
26- set(COMPILER_RT_INSTALL_PATH "" CACHE PATH
27-@@ -98,23 +98,23 @@ endif()
28 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
29 set(COMPILER_RT_OUTPUT_LIBRARY_DIR
30 ${COMPILER_RT_OUTPUT_DIR}/lib)
···40 set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH
41 "Path where built compiler-rt libraries should be installed.")
42 endif()
43--extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" bin)
44-+extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_BINDIR}")
45- set(COMPILER_RT_INSTALL_BINARY_DIR "${default_install_path}" CACHE PATH
46- "Path where built compiler-rt executables should be installed.")
47--extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" include)
48-+extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_INCLUDEDIR}")
49- set(COMPILER_RT_INSTALL_INCLUDE_DIR "${default_install_path}" CACHE PATH
50- "Path where compiler-rt headers should be installed.")
51--extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" share)
52-+extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_DATADIR}")
53- set(COMPILER_RT_INSTALL_DATA_DIR "${default_install_path}" CACHE PATH
54- "Path where compiler-rt data files should be installed.")
55-
···00000000000001diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake
2+index 8a6219568b3f..30ee68a47ccf 100644
3--- a/cmake/base-config-ix.cmake
4+++ b/cmake/base-config-ix.cmake
5+@@ -100,13 +100,13 @@ endif()
0000000006 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
7 set(COMPILER_RT_OUTPUT_LIBRARY_DIR
8 ${COMPILER_RT_OUTPUT_DIR}/lib)
···18 set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH
19 "Path where built compiler-rt libraries should be installed.")
20 endif()
0000000000000
···1+--- a/CMakeLists.txt
2++++ b/CMakeLists.txt
3+@@ -131,10 +131,21 @@ if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC)
4+ message(FATAL_ERROR "libc++abi must be built as either a shared or static library.")
5+ endif()
6+7+-# TODO: Remove this, which shouldn't be necessary since we know we're being built
8+-# side-by-side with libc++.
9+ set(LIBCXXABI_LIBCXX_INCLUDES "" CACHE PATH
10+ "Specify path to libc++ includes.")
11++if (NOT libcxx IN_LIST LLVM_ENABLE_RUNTIMES)
12++ if (NOT IS_DIRECTORY ${LIBCXXABI_LIBCXX_INCLUDES})
13++ message(FATAL_ERROR
14++ "LIBCXXABI_LIBCXX_INCLUDES=${LIBCXXABI_LIBCXX_INCLUDES} is not a valid directory. "
15++ "Please provide the path to where the libc++ headers have been installed.")
16++ endif()
17++ add_library(cxx-headers INTERFACE)
18++ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
19++ target_compile_options(cxx-headers INTERFACE /I "${LIBCXXABI_LIBCXX_INCLUDES}")
20++ else()
21++ target_compile_options(cxx-headers INTERFACE -I "${LIBCXXABI_LIBCXX_INCLUDES}")
22++ endif()
23++endif()
24+25+ set(LIBCXXABI_HERMETIC_STATIC_LIBRARY_DEFAULT OFF)
26+ if (WIN32)
27+--- a/test/CMakeLists.txt
28++++ b/test/CMakeLists.txt
29+@@ -61,9 +61,13 @@ if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
30+ list(APPEND LIBCXXABI_TEST_DEPS cxx_external_threads)
31+ endif()
32+33+-list(APPEND LIBCXXABI_TEST_DEPS cxx)
34+-if (LIBCXXABI_USE_LLVM_UNWINDER AND TARGET unwind)
35+- list(APPEND LIBCXXABI_TEST_DEPS unwind)
36++if(libcxx IN_LIST LLVM_ENABLE_RUNTIMES)
37++ list(APPEND LIBCXXABI_TEST_DEPS cxx)
38++endif()
39++if(libunwind IN_LIST LLVM_ENABLE_RUNTIMES)
40++ if (LIBCXXABI_USE_LLVM_UNWINDER AND TARGET unwind)
41++ list(APPEND LIBCXXABI_TEST_DEPS unwind)
42++ endif()
43+ endif()
44+45+ set(AUTO_GEN_COMMENT "## Autogenerated by libcxxabi configuration.\n# Do not edit!")
···2526 patches = [
27 ./gnu-install-dirs.patch
28- # On Darwin the llvm-config is perhaps not working fine as the
29- # LLVM_MAIN_SRC_DIR is not getting set correctly, and the build fails as
30- # the include path is not correct.
31- ./fix-root-src-dir.patch
32 ];
3334 nativeBuildInputs = [ cmake ];
35 buildInputs = [ libllvm libxml2 ];
3637- cmakeFlags = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
0038 "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
39 ];
40
···1-diff --git a/CMakeLists.txt b/CMakeLists.txt
2-index 79d451965ed4..78188978d6de 100644
3---- a/CMakeLists.txt
4-+++ b/CMakeLists.txt
5-@@ -12,6 +12,8 @@ set(CMAKE_MODULE_PATH
6- # If we are not building as part of LLVM, build LLDB as a standalone project,
7- # using LLVM as an external library.
8- if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
9-+ include(GNUInstallDirs)
10-+
11- project(lldb)
12- include(LLDBStandalone)
13-14diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake
15index 3291a7c808e1..b27d27ce6a87 100644
16--- a/cmake/modules/AddLLDB.cmake
···1diff --git a/CMakeLists.txt b/CMakeLists.txt
2-index 7f11a05f5622..fb90f8f6a49b 100644
3--- a/CMakeLists.txt
4+++ b/CMakeLists.txt
5-@@ -8,6 +8,8 @@ if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_S
6- set(OPENMP_STANDALONE_BUILD TRUE)
7- project(openmp C CXX)
8-9-+ include(GNUInstallDirs)
10-+
11- # CMAKE_BUILD_TYPE was not set, default to Release.
12- if (NOT CMAKE_BUILD_TYPE)
13- set(CMAKE_BUILD_TYPE Release)
14-@@ -19,7 +21,7 @@ if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_S
15 set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING
16 "Suffix of lib installation directory, e.g. 64 => lib64")
17 # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR.
···2021 # Group test settings.
22 set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
23-@@ -30,7 +32,7 @@ if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_S
24 else()
25 set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
26 # If building in tree, we honor the same install suffix LLVM uses.
···2930 if (NOT MSVC)
31 set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
32-index 0e1ce2afd154..8b3810f83713 100644
33---- a/libomptarget/plugins/amdgpu/CMakeLists.txt
34-+++ b/libomptarget/plugins/amdgpu/CMakeLists.txt
35-@@ -80,7 +80,7 @@ add_library(omptarget.rtl.amdgpu SHARED
36-37- # Install plugin under the lib destination folder.
38- # When we build for debug, OPENMP_LIBDIR_SUFFIX get set to -debug
39--install(TARGETS omptarget.rtl.amdgpu LIBRARY DESTINATION "lib${OPENMP_LIBDIR_SUFFIX}")
40-+install(TARGETS omptarget.rtl.amdgpu LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${OPENMP_LIBDIR_SUFFIX}")
41- set_property(TARGET omptarget.rtl.amdgpu PROPERTY INSTALL_RPATH_USE_LINK_PATH ON)
42-43- if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
44-diff --git a/libomptarget/plugins/ve/CMakeLists.txt b/libomptarget/plugins/ve/CMakeLists.txt
45-index 16ce0891ca23..db30ee9c769f 100644
46---- a/libomptarget/plugins/ve/CMakeLists.txt
47-+++ b/libomptarget/plugins/ve/CMakeLists.txt
48-@@ -32,7 +32,7 @@ if(${LIBOMPTARGET_DEP_VEO_FOUND})
49-50- # Install plugin under the lib destination folder.
51- install(TARGETS "omptarget.rtl.${tmachine_libname}"
52-- LIBRARY DESTINATION lib${OPENMP_LIBDIR_SUFFIX})
53-+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${OPENMP_LIBDIR_SUFFIX})
54-55- target_link_libraries(
56- "omptarget.rtl.${tmachine_libname}"
57-diff --git a/runtime/src/CMakeLists.txt b/runtime/src/CMakeLists.txt
58-index e4f4e6e1e73f..1164b3b22b0e 100644
59---- a/runtime/src/CMakeLists.txt
60-+++ b/runtime/src/CMakeLists.txt
61-@@ -346,13 +346,13 @@ add_dependencies(libomp-micro-tests libomp-test-deps)
62- # We want to install libomp in DESTDIR/CMAKE_INSTALL_PREFIX/lib
63- # We want to install headers in DESTDIR/CMAKE_INSTALL_PREFIX/include
64- if(${OPENMP_STANDALONE_BUILD})
65-- set(LIBOMP_HEADERS_INSTALL_PATH include)
66-+ set(LIBOMP_HEADERS_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}")
67- else()
68- string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION ${PACKAGE_VERSION})
69- set(LIBOMP_HEADERS_INSTALL_PATH "${OPENMP_INSTALL_LIBDIR}/clang/${CLANG_VERSION}/include")
70- endif()
71- if(WIN32)
72-- install(TARGETS omp RUNTIME DESTINATION bin)
73-+ install(TARGETS omp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
74- install(TARGETS ${LIBOMP_IMP_LIB_TARGET} ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")
75- # Create aliases (regular copies) of the library for backwards compatibility
76- set(LIBOMP_ALIASES "libiomp5md")
77-diff --git a/tools/multiplex/CMakeLists.txt b/tools/multiplex/CMakeLists.txt
78-index 64317c112176..4002784da736 100644
79---- a/tools/multiplex/CMakeLists.txt
80-+++ b/tools/multiplex/CMakeLists.txt
81-@@ -4,7 +4,7 @@ if(LIBOMP_OMPT_SUPPORT)
82- add_library(ompt-multiplex INTERFACE)
83- target_include_directories(ompt-multiplex INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
84-85-- install(FILES ompt-multiplex.h DESTINATION include)
86-+ install(FILES ompt-multiplex.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
87-88- add_subdirectory(tests)
89- endif()
···1diff --git a/CMakeLists.txt b/CMakeLists.txt
2+index b6ddbe90516d..311ab1d50e7f 100644
3--- a/CMakeLists.txt
4+++ b/CMakeLists.txt
5+@@ -29,7 +29,7 @@ if (OPENMP_STANDALONE_BUILD)
0000000006 set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING
7 "Suffix of lib installation directory, e.g. 64 => lib64")
8 # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR.
···1112 # Group test settings.
13 set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
14+@@ -40,7 +40,7 @@ if (OPENMP_STANDALONE_BUILD)
15 else()
16 set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
17 # If building in tree, we honor the same install suffix LLVM uses.
···2021 if (NOT MSVC)
22 set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
0000000000000000000000000000000000000000000000000000000000
···59 ++ optional (lib.versionAtLeast version "4.14") libelf
60 ++ optional (lib.versionAtLeast version "5.13") zstd;
6162-63- installkernel = buildPackages.writeShellScript "installkernel" ''
64- set -e
65- mkdir -p $4
66- cp -av $2 $4
67- cp -av $3 $4
68- '';
69-70 drvAttrs = config_: kernelConf: kernelPatches: configfile:
71 let
72 config = let attrName = attr: "CONFIG_" + attr; in {
···114 ++ optional (lib.versionAtLeast version "5.2" && lib.versionOlder version "5.4") ./gen-kheaders-metadata.patch;
115116 prePatch = ''
117- for mf in $(find -name Makefile -o -name Makefile.include -o -name install.sh); do
118- echo "stripping FHS paths in \`$mf'..."
119- sed -i "$mf" -e 's|/usr/bin/||g ; s|/bin/||g ; s|/sbin/||g'
120- done
121 sed -i Makefile -e 's|= depmod|= ${buildPackages.kmod}/bin/depmod|'
122123 # Don't include a (random) NT_GNU_BUILD_ID, to make the build more deterministic.
···146 fi
147148 patchShebangs scripts
00000149 '';
150151 configurePhase = ''
···185 kernelConf.target
186 "vmlinux" # for "perf" and things like that
187 ] ++ optional isModular "modules"
188- ++ optional buildDTBs "dtbs"
189 ++ extraMakeFlags;
190191 installFlags = [
192- "INSTALLKERNEL=${installkernel}"
193 "INSTALL_PATH=$(out)"
194 ] ++ (optional isModular "INSTALL_MOD_PATH=$(out)")
195 ++ optional installsFirmware "INSTALL_FW_PATH=$(out)/lib/firmware"
196 ++ optionals buildDTBs ["dtbs_install" "INSTALL_DTBS_PATH=$(out)/dtbs"];
197198- preInstall = ''
000000000000000000000000000000000000000000000000000199 installFlagsArray+=("-j$NIX_BUILD_CORES")
0200 '';
201202 # Some image types need special install targets (e.g. uImage is installed with make uinstall)
···59 ++ optional (lib.versionAtLeast version "4.14") libelf
60 ++ optional (lib.versionAtLeast version "5.13") zstd;
610000000062 drvAttrs = config_: kernelConf: kernelPatches: configfile:
63 let
64 config = let attrName = attr: "CONFIG_" + attr; in {
···106 ++ optional (lib.versionAtLeast version "5.2" && lib.versionOlder version "5.4") ./gen-kheaders-metadata.patch;
107108 prePatch = ''
0000109 sed -i Makefile -e 's|= depmod|= ${buildPackages.kmod}/bin/depmod|'
110111 # Don't include a (random) NT_GNU_BUILD_ID, to make the build more deterministic.
···134 fi
135136 patchShebangs scripts
137+138+ # also patch arch-specific install scripts
139+ for i in $(find arch -name install.sh); do
140+ patchShebangs "$i"
141+ done
142 '';
143144 configurePhase = ''
···178 kernelConf.target
179 "vmlinux" # for "perf" and things like that
180 ] ++ optional isModular "modules"
181+ ++ optionals buildDTBs ["dtbs" "DTC_FLAGS=-@"]
182 ++ extraMakeFlags;
183184 installFlags = [
0185 "INSTALL_PATH=$(out)"
186 ] ++ (optional isModular "INSTALL_MOD_PATH=$(out)")
187 ++ optional installsFirmware "INSTALL_FW_PATH=$(out)/lib/firmware"
188 ++ optionals buildDTBs ["dtbs_install" "INSTALL_DTBS_PATH=$(out)/dtbs"];
189190+ preInstall = let
191+ # All we really need to do here is copy the final image and System.map to $out,
192+ # and use the kernel's modules_install, firmware_install, dtbs_install, etc. targets
193+ # for the rest. Easy, right?
194+ #
195+ # Unfortunately for us, the obvious way of getting the built image path,
196+ # make -s image_name, does not work correctly, because some architectures
197+ # (*cough* aarch64 *cough*) change KBUILD_IMAGE on the fly in their install targets,
198+ # so we end up attempting to install the thing we didn't actually build.
199+ #
200+ # Thankfully, there's a way out that doesn't involve just hardcoding everything.
201+ #
202+ # The kernel has an install target, which runs a pretty simple shell script
203+ # (located at scripts/install.sh or arch/$arch/boot/install.sh, depending on
204+ # which kernel version you're looking at) that tries to do something sensible.
205+ #
206+ # (it would be great to hijack this script immediately, as it has all the
207+ # information we need passed to it and we don't need it to try and be smart,
208+ # but unfortunately, the exact location of the scripts differs between kernel
209+ # versions, and they're seemingly not considered to be public API at all)
210+ #
211+ # One of the ways it tries to discover what "something sensible" actually is
212+ # is by delegating to what's supposed to be a user-provided install script
213+ # located at ~/bin/installkernel.
214+ #
215+ # (the other options are:
216+ # - a distribution-specific script at /sbin/installkernel,
217+ # which we can't really create in the sandbox easily
218+ # - an architecture-specific script at arch/$arch/boot/install.sh,
219+ # which attempts to guess _something_ and usually guesses very wrong)
220+ #
221+ # More specifically, the install script exec's into ~/bin/installkernel, if one
222+ # exists, with the following arguments:
223+ #
224+ # $1: $KERNELRELEASE - full kernel version string
225+ # $2: $KBUILD_IMAGE - the final image path
226+ # $3: System.map - path to System.map file, seemingly hardcoded everywhere
227+ # $4: $INSTALL_PATH - path to the destination directory as specified in installFlags
228+ #
229+ # $2 is exactly what we want, so hijack the script and use the knowledge given to it
230+ # by the makefile overlords for our own nefarious ends.
231+ #
232+ # Note that the makefiles specifically look in ~/bin/installkernel, and
233+ # writeShellScriptBin writes the script to <store path>/bin/installkernel,
234+ # so HOME needs to be set to just the store path.
235+ #
236+ # FIXME: figure out a less roundabout way of doing this.
237+ installkernel = buildPackages.writeShellScriptBin "installkernel" ''
238+ cp -av $2 $4
239+ cp -av $3 $4
240+ '';
241+ in ''
242 installFlagsArray+=("-j$NIX_BUILD_CORES")
243+ export HOME=${installkernel}
244 '';
245246 # Some image types need special install targets (e.g. uImage is installed with make uinstall)