pololu / nixcrpkgs

Tools for cross-compiling standalone applications using Nix.
Other
202 stars 17 forks source link

native_inputs do not work in make_derivation #10

Closed seanybaggins closed 1 year ago

seanybaggins commented 1 year ago

Here is my build.nix file

src: config_name: env:

let
  payload = env.make_derivation {
    builder =
      {
        builder = "${env.nixpkgs.bash}/bin/bash";
        args = [
          ./some-script
          "some-commnad"
        ];
      };
    inherit src;
    native_inputs = with env.nixpkgs; [
      git
      bear
      coreutils
    ];
    cross_inputs = with env.nixpkgs; [
      env.qt6
      sol2
      curl.dev
      lua
      libusb1
      sqlcipher
      xmlsec
      avahi
      boost171
      libtool
    ];
  };

  license_set = env.libusbp.license_set // env.global_license_set;

  license = env.make_derivation {
    name = "license";
    builder.ruby = ./license_builder.rb;
    inherit src;
    commit = builtins.getEnv "commit";
    nixcrpkgs_commit = builtins.getEnv "nixcrpkgs_commit";
    nixpkgs_commit = builtins.getEnv "nixpkgs_commit";
    license_names = builtins.attrNames license_set;
    licenses = builtins.attrValues license_set;
  };

  installer = env.make_derivation {
    name = "${config_name}-installer";
    builder.ruby =
      if env.os == "windows" then ./windows_installer_builder.rb
      else if env.os == "linux" then ./linux_installer_builder.rb
      else if env.os == "macos" then ./macos_installer_builder.rb
      else throw "?";
    inherit src config_name payload license;
    libusbp = env.libusbp;
  };

in
payload // { inherit env license installer; }

When I try to build, I can see that the script is getting called by git and nproc commands are not found

error: builder for '/nix/store/md7lc4xjlrz63lr2yjv53pf60xkcpgbn-package-i686-w64-mingw32.drv' failed with exit code 5;
       last 5 log lines:
       > /nix/store/pi0fyir1vzdsjha3ddr5sqj47rw7xgs6-builder.sh: line 314: nproc: command not found
       > Building some-package with  processing units
       > Bash Version: 5.2.15(1)-release
       > /nix/store/pi0fyir1vzdsjha3ddr5sqj47rw7xgs6-builder.sh: line 77: git: command not found
       For full logs, run 'nix log /nix/store/md7lc4xjlrz63lr2yjv53pf60xkcpgbn-package-i686-w64-mingw32.drv'.
seanybaggins commented 1 year ago

Actually think I may have solved my problem. Did not have source $setup in my bash scripts.

DavidEGrayson commented 1 year ago

It sounds like some part of your code uses nproc and git. If so, you should probably find the appropriate packages for those from nixpkgs (e.g. nixpkgs.git) and include those as native inputs. Right now I'm not sure what git or nproc you're using, if those errors went away, maybe you're just using whatever happens to be on your PATH. Also, you need to do source $setup or source $stdenv/setup to actually get the native inputs on your PATH.

P.S. Actually, thinking about it further, I don't really know what you're doing, but if it were my project I'd try to avoid using nproc and git. You can use $NIX_BUILD_CORES to get Nix's recommendation for the number of cores to use, and you can pass Git commit info to your script using environment variables.