From 2ed51a3ff0a69a6d2e6359a2bcf5da70f7313789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20=C5=BDlender?= Date: Thu, 9 May 2024 19:11:20 +0200 Subject: [PATCH 1/2] deterministic-uname: Overridable platform Some packages rely on `uname` to configure the host target which breaks cross-compilation. We can have more control over the evaluation of `uname` by placing `deterministic-uname` into the package's `nativeBuildInputs`. However the current `deterministic-uname` is hardcoded to `buildPlatform`. This PR introduces a build argument `forPlatform` to `deterministic-uname` which allows you to override the platform it reports. Example: ```nix deterministic-uname.override { forPlatform = stdenv.hostPlatform; } ``` --- .../deterministic-uname/default.nix | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pkgs/build-support/deterministic-uname/default.nix b/pkgs/build-support/deterministic-uname/default.nix index 6d150557aa9d..9d07a4b6c4e2 100644 --- a/pkgs/build-support/deterministic-uname/default.nix +++ b/pkgs/build-support/deterministic-uname/default.nix @@ -5,6 +5,7 @@ , coreutils , getopt , modDirVersion ? "" +, forPlatform ? stdenv.buildPlatform }: substituteAll { @@ -17,8 +18,8 @@ substituteAll { inherit coreutils getopt; - uSystem = if stdenv.buildPlatform.uname.system != null then stdenv.buildPlatform.uname.system else "unknown"; - inherit (stdenv.buildPlatform.uname) processor; + uSystem = if forPlatform.uname.system != null then forPlatform.uname.system else "unknown"; + inherit (forPlatform.uname) processor; # uname -o # maybe add to lib/systems/default.nix uname attrset @@ -26,9 +27,9 @@ substituteAll { # https://stackoverflow.com/questions/61711186/where-does-host-operating-system-in-uname-c-comes-from # https://github.com/coreutils/gnulib/blob/master/m4/host-os.m4 operatingSystem = - if stdenv.buildPlatform.isLinux + if forPlatform.isLinux then "GNU/Linux" - else if stdenv.buildPlatform.isDarwin + else if forPlatform.isDarwin then "Darwin" # darwin isn't in host-os.m4 so where does this come from? else "unknown"; @@ -42,11 +43,12 @@ substituteAll { mainProgram = "uname"; longDescription = '' This package provides a replacement for `uname` whose output depends only - on `stdenv.buildPlatform`. It is meant to be used from within derivations. - Many packages' build processes run `uname` at compile time and embed its - output into the result of the build. Since `uname` calls into the kernel, - and the Nix sandbox currently does not intercept these calls, builds made - on different kernels will produce different results. + on `stdenv.buildPlatform`, or a configurable `forPlatform`. It is meant + to be used from within derivations. Many packages' build processes run + `uname` at compile time and embed its output into the result of the build. + Since `uname` calls into the kernel, and the Nix sandbox currently does + not intercept these calls, builds made on different kernels will produce + different results. ''; license = [ licenses.mit ]; maintainers = with maintainers; [ artturin ]; From b0e8337c3aed748de1383aba68df971ed3ff0962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20=C5=BDlender?= Date: Sun, 26 May 2024 10:11:39 +0200 Subject: [PATCH 2/2] deterministic-host-uname: init --- pkgs/top-level/all-packages.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 9f74494aff99..88352269603b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -3692,6 +3692,8 @@ with pkgs; deterministic-uname = callPackage ../build-support/deterministic-uname { }; + deterministic-host-uname = deterministic-uname.override { forPlatform = stdenv.hostPlatform; }; + dfmt = callPackage ../tools/text/dfmt { }; diopser = callPackage ../applications/audio/diopser { };