From 951a93757dd8e863c75b342e562cefe81a5af895 Mon Sep 17 00:00:00 2001 From: Alexander Sosedkin Date: Sat, 7 Nov 2020 16:13:57 +0100 Subject: [PATCH] modules/workaround-make: add workaround for make See #91 for context. --- modules/module-list.nix | 1 + modules/workaround-make.nix | 70 +++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 modules/workaround-make.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index 781ed11..737cc9b 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -14,5 +14,6 @@ ./time.nix ./user.nix ./version.nix + ./workaround-make.nix ] diff --git a/modules/workaround-make.nix b/modules/workaround-make.nix new file mode 100644 index 0000000..b1ee44b --- /dev/null +++ b/modules/workaround-make.nix @@ -0,0 +1,70 @@ +# Copyright (c) 2019-2020, see AUTHORS. Licensed under MIT License, see LICENSE. + +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.system.workaround.make-posix-spawn; + + gnumake-no-posix-spawn = pkgs.gnumake.overrideAttrs (old: { + configureFlags = old.configureFlags ++ [ "--disable-posix-spawn" ]; + + buildPhase = "${pkgs.gnumake42}/bin/make"; + installPhase = '' + mkdir -p $out + ${pkgs.gnumake42}/bin/make install + ''; + + # make a copy to facilitate repairs when it gets broken + # because of being bind-mounted onto the normal make + postFixup = '' + cp $out/bin/make $out/bin/overlaying-make + touch $out/SEE_system.workaround.make-posix-spawn.enable + ''; + }); +in +{ + + ###### interface + + options = { + + system.workaround.make-posix-spawn.enable = mkOption { + type = types.bool; + default = false; + description = '' + On some devices, GNU make 4.3 fails with 'Function not implemented', + and the workaround is to compile it with '--disable-posix-spawn'. + This option will shadow the original make in a really dirty way, + by overlaying broken gnumake with a fixed version on proot level. + Please only enable this for a limited time: + get stuck with a broken build; stop attempting to build something; + enable the option; nix-on-droid switch, relogin, build, + disable the option; nix-on-droid switch, relogin. + + If you leave it on Nix-store validation will fail, + repairs will break the working make, + updates will do bad things. You have been warned. + + Consider building remotely as an alternative for such devices: + https://github.com/t184256/nix-on-droid/wiki/Remote-building + ''; + }; + + }; + + ###### implementation + + config = { + build.extraProotOptions = + lib.optionals cfg.enable [ + "-b" + ( + "${config.build.installationDir}/" + + "${gnumake-no-posix-spawn}/bin/overlaying-make" + + ":${pkgs.gnumake}/bin/make" + ) + ]; + }; +}