From 002648b782f8af41b4916e6cebd6b68d1d076513 Mon Sep 17 00:00:00 2001 From: Weijia Wang <9713184+wegank@users.noreply.github.com> Date: Fri, 1 May 2026 01:55:57 +0200 Subject: [PATCH] nixos: unset vm.mmap_rnd_compat_bits on loongarch64 --- nixos/modules/config/sysctl.nix | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/nixos/modules/config/sysctl.nix b/nixos/modules/config/sysctl.nix index 1d5a1487bb3d..4a2ecd11e103 100644 --- a/nixos/modules/config/sysctl.nix +++ b/nixos/modules/config/sysctl.nix @@ -72,20 +72,25 @@ in { inherit (config.boot.kernelPackages.kernel) configfile; } - '' - mmap_rnd_bits_max=$(grep "^CONFIG_ARCH_MMAP_RND_BITS_MAX=" $configfile | grep --only-matching "[0-9]*$") - if [[ -z "$mmap_rnd_bits_max" ]]; then - echo "Unable to determine mmap_rnd_bits_max. Check your kernel configfile is valid." - exit 1 - fi - mmap_rnd_compat_bits_max=$(grep "^CONFIG_ARCH_MMAP_RND_COMPAT_BITS_MAX=" $configfile | grep --only-matching "[0-9]*$") - if [[ -z "$mmap_rnd_compat_bits_max" ]]; then - echo "Unable to determine mmap_rnd_compat_bits_max. Check your kernel configfile is valid." - exit 1 - fi - echo "vm.mmap_rnd_bits=$mmap_rnd_bits_max" >> $out - echo "vm.mmap_rnd_compat_bits=$mmap_rnd_compat_bits_max" >> $out - ''; + ( + '' + mmap_rnd_bits_max=$(grep "^CONFIG_ARCH_MMAP_RND_BITS_MAX=" $configfile | grep --only-matching "[0-9]*$") + if [[ -z "$mmap_rnd_bits_max" ]]; then + echo "Unable to determine mmap_rnd_bits_max. Check your kernel configfile is valid." + exit 1 + fi + echo "vm.mmap_rnd_bits=$mmap_rnd_bits_max" >> $out + '' + # HAVE_ARCH_MMAP_RND_COMPAT_BITS is not defined for LoongArch64 + + lib.optionalString (!pkgs.stdenv.hostPlatform.isLoongArch64) '' + mmap_rnd_compat_bits_max=$(grep "^CONFIG_ARCH_MMAP_RND_COMPAT_BITS_MAX=" $configfile | grep --only-matching "[0-9]*$") + if [[ -z "$mmap_rnd_compat_bits_max" ]]; then + echo "Unable to determine mmap_rnd_compat_bits_max. Check your kernel configfile is valid." + exit 1 + fi + echo "vm.mmap_rnd_compat_bits=$mmap_rnd_compat_bits_max" >> $out + '' + ); "sysctl.d/60-nixos.conf".text = lib.concatStrings ( lib.mapAttrsToList ( n: v: lib.optionalString (v != null) "${n}=${if v == false then "0" else toString v}\n"