Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions doc/release-notes/rl-2505.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->

- Using `==` or `!=` to compare elaborated platform attrsets, such as `stdenv.hostPlatform` and `stdenv.buildPlatform`, is no longer supported and may produce a warning. In a future version, this warning will be replaced with an error. Instead, you should use the `canExecute`, `equals`, or `notEquals` functions included with platform attrsets or use `lib.systems.equals`.

- E.g. replace `hostPlatform == buildPlatform` with `buildPlatform.canExecute hostPlatform`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why the example replacement is replacing equals with canExecute.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's one possible replacement for some cases, because often enough the == check is just trying to prevent "real cross" scenarios, where you can't execute the binaries on your build system. So for a lot of cases, this could be a better replacement, but it might not always be correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know of many packages where the build system just doesn't understand the distinction between build and host. For such cases an equality check makes sense.


- `apptainer` and `singularity` deprecate the workaround of overriding `vendorHash` and related attributes via `<pkg>.override`,
in favour of the unified overriding of the same group of attributes via `<pkg>.overrideAttrs`.
The compatibility layer will be removed in future releases.
Expand Down
18 changes: 16 additions & 2 deletions lib/systems/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ let

inherit (lib.strings) toJSON;

# define this binding in the top-level let-block so that it only prints once
warnAboutPlatformEquals = lib.warn (lib.concatStringsSep " " [
"It seems that you're comparing platform attrsets using plain == equality,"
"which is not supported, and will result in an error soon."
"Use `--abort-on-warn --show-trace` to find the location of this warning."
"If equality (e.g. host == build) was used, try (build.canExecute host) or (build.equals host) instead."
"If equality was not used, you may avoid this warning by filtering out the `warnAboutPlatformEquals` attribute."
]) null;

doubles = import ./doubles.nix { inherit lib; };
parse = import ./parse.nix { inherit lib; };
inspect = import ./inspect.nix { inherit lib; };
Expand All @@ -43,9 +52,9 @@ let
*/
equals =
let
removeFunctions = a: filterAttrs (_: v: !isFunction v) a;
removeUnwanted = filterAttrs (name: v: !(name == "warnAboutPlatformEquals" || isFunction v));
in
a: b: removeFunctions a == removeFunctions b;
a: b: removeUnwanted a == removeUnwanted b;

/**
List of all Nix system doubles the nixpkgs flake will expose the package set
Expand Down Expand Up @@ -531,6 +540,11 @@ let
"-uefi"
];
};
}
// {
inherit warnAboutPlatformEquals;
equals = equals final;
notEquals = platform: !final.equals platform;
};
in
assert final.useAndroidPrebuilt -> final.isAndroid;
Expand Down
27 changes: 15 additions & 12 deletions lib/tests/systems.nix
Original file line number Diff line number Diff line change
Expand Up @@ -267,21 +267,24 @@ lib.runTests (
in
{
expr = lib.systems.equals (lib.systems.elaborate "x86_64-linux") modified;
expected =
{
# Changes in these attrs are not detectable because they're function.
# The functions should be derived from the data, so this is not a problem.
canExecute = null;
emulator = null;
emulatorAvailable = null;
staticEmulatorAvailable = null;
isCompatible = null;
} ? ${platformAttrName};
expected = false;
};

})
# x86_64-linux is an arbitrary choice, just to get all the elaborated attrNames
(
lib.systems.elaborate "x86_64-linux" # arbitrary choice, just to get all the elaborated attrNames
builtins.removeAttrs (lib.systems.elaborate "x86_64-linux") [
# Avoid the warning
"warnAboutPlatformEquals"
# Changes in these attrs are not detectable because they're function.
# The functions should be derived from the data, so this is not a problem.
"canExecute"
"emulator"
"emulatorAvailable"
"equals"
"isCompatible"
"notEquals"
"staticEmulatorAvailable"
]
)

)
2 changes: 1 addition & 1 deletion nixos/modules/config/nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ let
${cfg.extraOptions}
'';
checkPhase = lib.optionalString cfg.checkConfig (
if pkgs.stdenv.hostPlatform != pkgs.stdenv.buildPlatform then
if pkgs.stdenv.hostPlatform.notEquals pkgs.stdenv.buildPlatform then
''
echo "Ignoring validation for cross-compilation"
''
Expand Down
12 changes: 10 additions & 2 deletions nixos/modules/misc/nixpkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ let
defaultPkgs =
if opt.hostPlatform.isDefined then
let
isCross = cfg.buildPlatform != cfg.hostPlatform;
isCross = cfg.buildPlatform.notEquals cfg.hostPlatform;
systemArgs =
if isCross then
{
Expand Down Expand Up @@ -226,7 +226,15 @@ in
elaborated = lib.systems.elaborate inputBuildPlatform;
in
if lib.systems.equals elaborated cfg.hostPlatform then
cfg.hostPlatform # make identical, so that `==` equality works; see https://github.com/NixOS/nixpkgs/issues/278001
# Make equivalent platforms actually identical, so that `==` equality works.
# See https://github.com/NixOS/nixpkgs/issues/278001
# NOTE: `==` between platforms was deprecated 2025-02-08.
# Users should instead use the `canExecute`, `equals`, or `notEquals`
# functions included with platform attrsets or use `lib.systems.equals`.
# See https://github.com/NixOS/nixpkgs/pull/380005
# TODO: Once users have had chance to migrate, this `apply` function
# can be simplified to `lib.systems.elaborate`.
cfg.hostPlatform
else
elaborated;
defaultText = lib.literalExpression ''config.nixpkgs.hostPlatform'';
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/databases/postgresql.nix
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ in
];

system.checks = lib.optional (
cfg.checkConfig && pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform
cfg.checkConfig && pkgs.stdenv.hostPlatform.equals pkgs.stdenv.buildPlatform
) configFileCheck;

systemd.services.postgresql = {
Expand Down
4 changes: 2 additions & 2 deletions nixos/modules/services/monitoring/nagios.nix
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ in

validateConfig = lib.mkOption {
type = lib.types.bool;
default = pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform;
defaultText = lib.literalExpression "pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform";
default = pkgs.stdenv.hostPlatform.equals pkgs.stdenv.buildPlatform;
defaultText = lib.literalExpression "pkgs.stdenv.hostPlatform.equals pkgs.stdenv.buildPlatform";
description = "if true, the syntax of the nagios configuration file is checked at build time";
};

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/networking/ssh/sshd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let
# This middle-ground solution ensures *an* sshd can do their basic validation
# on the configuration.
validationPackage =
if pkgs.stdenv.buildPlatform == pkgs.stdenv.hostPlatform then
if pkgs.stdenv.buildPlatform.equals pkgs.stdenv.hostPlatform then
cfg.package
else
pkgs.buildPackages.openssh;
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/web-servers/caddy/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let
'';
in
"${
if pkgs.stdenv.buildPlatform == pkgs.stdenv.hostPlatform then Caddyfile-formatted else Caddyfile
if pkgs.stdenv.buildPlatform.equals pkgs.stdenv.hostPlatform then Caddyfile-formatted else Caddyfile
}/Caddyfile";

etcConfigFile = "caddy/caddy_config";
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/system/activation/switchable-system.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ in
;

chmod +x $out/bin/switch-to-configuration
${lib.optionalString (pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) ''
${lib.optionalString (pkgs.stdenv.hostPlatform.equals pkgs.stdenv.buildPlatform) ''
if ! output=$(${perlWrapped}/bin/perl -c $out/bin/switch-to-configuration 2>&1); then
echo "switch-to-configuration syntax is not valid:"
echo "$output"
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/system/boot/stage-1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ let
patchelf --set-rpath $out/lib $i
done

if [ -z "${toString (pkgs.stdenv.hostPlatform != pkgs.stdenv.buildPlatform)}" ]; then
if [ -z "${toString (pkgs.stdenv.hostPlatform.notEquals pkgs.stdenv.buildPlatform)}" ]; then
# Make sure that the patchelf'ed binaries still work.
echo "testing patched programs..."
$out/bin/ash -c 'echo hello world' | grep "hello world"
Expand Down
4 changes: 1 addition & 3 deletions pkgs/applications/audio/csound/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ stdenv.mkDerivation {
[ "-DBUILD_CSOUND_AC=0" ] # fails to find Score.hpp
++ lib.optional stdenv.hostPlatform.isDarwin "-DCS_FRAMEWORK_DEST=${placeholder "out"}/lib"
# Ignore gettext in CMAKE_PREFIX_PATH on cross to prevent find_program picking up the wrong gettext
++ lib.optional (
stdenv.hostPlatform != stdenv.buildPlatform
) "-DCMAKE_IGNORE_PATH=${lib.getBin gettext}/bin";
++ lib.optional (stdenv.hostPlatform.notEquals stdenv.buildPlatform) "-DCMAKE_IGNORE_PATH=${lib.getBin gettext}/bin";

nativeBuildInputs = [
cmake
Expand Down
6 changes: 2 additions & 4 deletions pkgs/applications/audio/faust/faust2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,9 @@ let
cd ..
shopt -s globstar
for f in **/Makefile **/Makefile.library **/CMakeLists.txt build/Make.llvm.static embedded/faustjava/faust2engine architecture/autodiff/autodiff.sh source/tools/faust2appls/* **/llvm.cmake tools/benchmark/faust2object; do
echo $f "llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}"
echo $f "llvm-config${lib.optionalString (stdenv.hostPlatform.notEquals stdenv.buildPlatform) "-native"}"
substituteInPlace $f \
--replace-quiet "llvm-config" "llvm-config${
lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"
}"
--replace-quiet "llvm-config" "llvm-config${lib.optionalString (stdenv.hostPlatform.notEquals stdenv.buildPlatform) "-native"}"
done
shopt -u globstar
cd build
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/editors/vim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ stdenv.mkDerivation {
"--enable-multibyte"
"--enable-nls"
]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) (
++ lib.optionals (stdenv.hostPlatform.notEquals stdenv.buildPlatform) (
[
"vim_cv_toupper_broken=no"
"--with-tlib=ncurses"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/editors/vim/full.nix
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ stdenv.mkDerivation {
"--disable-carbon_check"
"--disable-gtktest"
]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
++ lib.optionals (stdenv.hostPlatform.notEquals stdenv.buildPlatform) [
"vim_cv_toupper_broken=no"
"--with-tlib=ncurses"
"vim_cv_terminfo=yes"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/graphics/sane/backends/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ stdenv.mkDerivation rec {

# autoconf check for HAVE_MMAP is never set on cross compilation.
# The pieusb backend fails compilation if HAVE_MMAP is not set.
buildFlags = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
buildFlags = lib.optionals (stdenv.hostPlatform.notEquals stdenv.buildPlatform) [
"CFLAGS=-DHAVE_MMAP=${if stdenv.hostPlatform.isLinux then "1" else "0"}"
];

Expand Down
5 changes: 3 additions & 2 deletions pkgs/applications/networking/browsers/chromium/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,8 @@ let

''
+
lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform && stdenv.hostPlatform.isAarch64)
lib.optionalString
(stdenv.hostPlatform.equals stdenv.buildPlatform && stdenv.hostPlatform.isAarch64)
''
substituteInPlace build/toolchain/linux/BUILD.gn \
--replace 'toolprefix = "aarch64-linux-gnu-"' 'toolprefix = ""'
Expand Down Expand Up @@ -739,7 +740,7 @@ let
# We only build those specific toolchains when we cross-compile, as native non-cross-compilations would otherwise
# end up building much more things than they need to (roughly double the build steps and time/compute):
}
// lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) {
// lib.optionalAttrs (stdenv.buildPlatform.notEquals stdenv.hostPlatform) {
host_toolchain = "//build/toolchain/linux/unbundle:host";
v8_snapshot_toolchain = "//build/toolchain/linux/unbundle:host";
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/networking/browsers/elinks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
guile ? null,
enablePython ? false,
python ? null,
enablePerl ? (!stdenv.hostPlatform.isDarwin) && (stdenv.hostPlatform == stdenv.buildPlatform),
enablePerl ? (!stdenv.hostPlatform.isDarwin) && (stdenv.hostPlatform.equals stdenv.buildPlatform),
perl ? null,
# re-add javascript support when upstream supports modern spidermonkey
}:
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/networking/browsers/firefox/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ in
),
overrideCC,
buildPackages,
pgoSupport ? (stdenv.hostPlatform.isLinux && stdenv.hostPlatform == stdenv.buildPlatform),
pgoSupport ? (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.equals stdenv.buildPlatform),
xvfb-run,
elfhackSupport ?
isElfhackPlatform stdenv && !(stdenv.hostPlatform.isMusl && stdenv.hostPlatform.isAarch64),
Expand Down
4 changes: 2 additions & 2 deletions pkgs/applications/networking/sniffers/wireshark/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ stdenv.mkDerivation rec {
./patches/lookup-dumpcap-in-path.patch
];

depsBuildBuild = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
depsBuildBuild = lib.optionals (stdenv.buildPlatform.notEquals stdenv.hostPlatform) [
buildPackages.stdenv.cc
];

Expand Down Expand Up @@ -163,7 +163,7 @@ stdenv.mkDerivation rec {
"-DENABLE_APPLICATION_BUNDLE=${if isAppBundle then "ON" else "OFF"}"
"-DLEMON_C_COMPILER=cc"
]
++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
++ lib.optionals (stdenv.buildPlatform.notEquals stdenv.hostPlatform) [
"-DHAVE_C99_VSNPRINTF_EXITCODE__TRYRUN_OUTPUT="
"-DHAVE_C99_VSNPRINTF_EXITCODE=0"
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
mkOpenModelicaDerivation,
}:
let
isCross = stdenv.buildPlatform != stdenv.hostPlatform;
isCross = stdenv.buildPlatform.notEquals stdenv.hostPlatform;
nativeOMCompiler = buildPackages.openmodelica.omcompiler;
in
mkOpenModelicaDerivation (
Expand Down
8 changes: 4 additions & 4 deletions pkgs/applications/version-management/git/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
subversionClient,
perlLibs,
smtpPerlLibs,
perlSupport ? stdenv.buildPlatform == stdenv.hostPlatform,
perlSupport ? stdenv.buildPlatform.equals stdenv.hostPlatform,
nlsSupport ? true,
osxkeychainSupport ? stdenv.hostPlatform.isDarwin,
guiSupport ? false,
Expand Down Expand Up @@ -178,7 +178,7 @@ stdenv.mkDerivation (finalAttrs: {
[
"ac_cv_prog_CURL_CONFIG=${lib.getDev curl}/bin/curl-config"
]
++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
++ lib.optionals (stdenv.buildPlatform.notEquals stdenv.hostPlatform) [
"ac_cv_fread_reads_directories=yes"
"ac_cv_snprintf_returns_bogus=no"
"ac_cv_iconv_omits_bom=no"
Expand All @@ -195,7 +195,7 @@ stdenv.mkDerivation (finalAttrs: {
]
# Git does not allow setting a shell separately for building and run-time.
# Therefore lets leave it at the default /bin/sh when cross-compiling
++ lib.optional (stdenv.buildPlatform == stdenv.hostPlatform) "SHELL_PATH=${stdenv.shell}"
++ lib.optional (stdenv.buildPlatform.equals stdenv.hostPlatform) "SHELL_PATH=${stdenv.shell}"
++ (if perlSupport then [ "PERL_PATH=${perlPackages.perl}/bin/perl" ] else [ "NO_PERL=1" ])
++ (if pythonSupport then [ "PYTHON_PATH=${python3}/bin/python" ] else [ "NO_PYTHON=1" ])
++ lib.optionals stdenv.hostPlatform.isSunOS [
Expand All @@ -219,7 +219,7 @@ stdenv.mkDerivation (finalAttrs: {
# See https://github.com/Homebrew/homebrew-core/commit/dfa3ccf1e7d3901e371b5140b935839ba9d8b706
++ lib.optional stdenv.hostPlatform.isDarwin "TKFRAMEWORK=/nonexistent";

disallowedReferences = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
disallowedReferences = lib.optionals (stdenv.buildPlatform.notEquals stdenv.hostPlatform) [
stdenv.shellPackage
];

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/version-management/mercurial/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ let
requiredSystemFeatures = [ "big-parallel" ];

# Don't run tests if not-Linux or if cross-compiling.
meta.broken = !stdenv.hostPlatform.isLinux || stdenv.buildPlatform != stdenv.hostPlatform;
meta.broken = !stdenv.hostPlatform.isLinux || stdenv.buildPlatform.notEquals stdenv.hostPlatform;
}
''
addToSearchPathWithCustomDelimiter : PYTHONPATH "${mercurial}/${python.sitePackages}"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/video/kodi/unwrapped.nix
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ stdenv.mkDerivation (finalAttrs: {
''
cmakeFlagsArray+=("-DCORE_PLATFORM_NAME=${lib.concatStringsSep " " kodi_platforms}")
''
+ lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
+ lib.optionalString (stdenv.hostPlatform.notEquals stdenv.buildPlatform) ''
# Need these tools on the build system when cross compiling,
# hacky, but have found no other way.
CXX=$CXX_FOR_BUILD LD=ld make -C tools/depends/native/JsonSchemaBuilder
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/video/mplayer/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ let
else
null;

crossBuild = stdenv.hostPlatform != stdenv.buildPlatform;
crossBuild = stdenv.hostPlatform.notEquals stdenv.buildPlatform;

in

Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/bintools-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ let
#
# TODO(@Ericson2314) Make unconditional, or optional but always true by
# default.
targetPrefix = optionalString (targetPlatform != hostPlatform) (targetPlatform.config + "-");
targetPrefix = optionalString (targetPlatform.notEquals hostPlatform) (targetPlatform.config + "-");

bintoolsVersion = getVersion bintools;
bintoolsName = removePrefix targetPrefix (getName bintools);
Expand Down
Loading