Building OpenWRT as derivation

Hi, I’m trying to build OpenWRT using Nix, but I have a time with a failed check:

OpenWRT> Checking 'true'... failed.
OpenWRT> Checking 'false'... failed.
.
.
.
.
OpenWRT> Build dependency: Please install GNU 'coreutils'

the nix file:

{stdenv, fetchFromGitHub, runCommand, pkgs, openwrt-version, ...}:
let
in stdenv.mkDerivation {

  src = fetchFromGitHub {
    owner = "openwrt";
    repo = "openwrt";
    rev = "openwrt-${openwrt-version}";
    hash = "sha256-Aef4sDgFBIyBPKVVYu4xMTupBr1PKahkxNaalyAK2H8=";
  };

  nativeBuildInputs = with pkgs; [
    git
    perl
    gnumake
    gcc
    unzip
    util-linux
    python3
    rsync
    patch
    wget
    file
    which
    pkg-config
    openssl
    binutils

    ncurses
    zlib

    coreutils-full
  ];

  multiPkgs = null;
  extraOutputsToInstall = [ "dev" ];
  profile = ''
    export hardeningDisable=all
  '';

  # doCheck = false;
  dontConfigure = true;
  # dontBuild = false;
  dontInstall = true;

  patchPhase = ''
    patchShebangs scripts
  '';

  buildPhase = ''
    make defconfig
  '';

  name = "OpenWRT ${openwrt-version}";
}

and the fail itself defined on a Makefile .mk file

$(eval $(call TestHostCommand,true, \
	Please install GNU 'coreutils', \
	$(TRUE)))

$(eval $(call TestHostCommand,false, \
	Please install GNU 'coreutils', \
	$(FALSE); [ $$$$$$$$? = 1 ] && $(TRUE)))

I don’t know why this two test fails, tested that true and false command works, so what you guys can see here?

2 Likes

I have no answer to your question unfortunately, just wanted to link to https://www.liminix.org/ which might be of interest if you hadn’t seen it yet

This is interesting project and for my personal router (TP Link AX1800) i will try it, thanks… But the openwrt need for another project. The real strange thing is that $(TRUE), why not work on Nix build, there is something that i missing.

Without having looked at your specific problem, maybe this Nix
environment

designed for building OpenWRT might help?

Well, this use a buildFHSUserEnv and already checked to “copy” the dependencies. I was thinking that this is for a shell environment, but I need to build the final firmware file. Thanks for the response.

Sorry for the thread necromancing here, but I ran across this very issue just now and it turns out that OpenWRT depends on /usr/bin/env for executing true/false. This fails because Nix doesn’t provide /usr/bin/env in sandboxed builds which in turn causes those specific checks to fail.

I was able to work around this somewhat, but it’s everything but pretty:

preConfigure = ''
  sed -i -E "s#([A-Z]+):=/usr/bin/env #\\1:=#" rules.mk
'';
1 Like