Skip to content

treewide: replace stdenv.is with stdenv.hostPlatform.is#341407

Merged
emilazy merged 2 commits intoNixOS:masterfrom
Artturin:stdenvshorthandtreewide
Sep 24, 2024
Merged

treewide: replace stdenv.is with stdenv.hostPlatform.is#341407
emilazy merged 2 commits intoNixOS:masterfrom
Artturin:stdenvshorthandtreewide

Conversation

@Artturin
Copy link
Copy Markdown
Member

@Artturin Artturin commented Sep 12, 2024

Approve or thumbs up to show that you approve of the idea, or request changes on the first file to discuss why you don't think it's a good idea.

Join https://matrix.to/#/#stdenv:nixos.org to discuss

I'll reset to master and rerun the commands before merge.
Further replacements can be done in the PR where the warnings are added.
The commits can be added to .git-blame-ignore-revs in a separate PR

treewide: replace stdenv.is with stdenv.hostPlatform.is

In preparation for the deprecation of stdenv.isX.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of stdenv.isDarwin will get in the way

One example of why this is bad and especially affects compiler packages
#343059

There are too many files to go through manually but a treewide should
get users thinking when they see a hostPlatform.isX in a place where it
doesn't make sense.

fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd  "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd  "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd  "originalStdenv.is" "originalStdenv.hostPlatform.is"

The rebuilds are due to src ./. or similar

image

https://gist.github.com/Artturin/4cc1e73fc612cb7a79459a9bb6bc27a3

@github-actions github-actions bot added 6.topic: python Python is a high-level, general-purpose programming language. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: haskell General-purpose, statically typed, purely functional programming language 6.topic: qt/kde Object-oriented framework for GUI creation 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: emacs Text editor 6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. 6.topic: golang Go is a high-level general purpose programming language that is statically typed and compiled. 6.topic: ruby A dynamic, open source programming language with a focus on simplicity and productivity. 6.topic: vim Advanced text editor 6.topic: erlang General-purpose, concurrent, functional high-level programming language 6.topic: ocaml OCaml is a general-purpose, high-level, multi-paradigm programming language. 6.topic: nodejs Node.js is a free, open-source, cross-platform JavaScript runtime environment 6.topic: lua Lua is a powerful, efficient, lightweight, embeddable scripting language. 6.topic: agda A dependently typed programming language / interactive theorem prover 6.topic: nim Nim programing language 6.topic: LXQt The Lightweight Qt Desktop Environment 6.topic: Enlightenment DE The Enlightenment Desktop Environment 6.topic: mate The MATE Desktop Environment 6.topic: vscode A free and versatile code editor that supports almost every major programming language. 6.topic: flakes The experimental Nix feature 6.topic: lib The Nixpkgs function library 6.topic: zig Zig is an imperative, general-purpose, statically typed, compiled system programming language. 6.topic: jupyter Interactive computing tooling: kernels, notebook, jupyterlab 6.topic: julia Julia is a high-level, high-performance dynamic language for technical computing. 6.topic: php PHP is a general-purpose scripting language geared towards web development. 6.topic: k3s Kubernates distribution (https://k3s.io/) 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 6.topic: dotnet Language: .NET 6.topic: flutter Open-source UI software development kit for cross-platform applications labels Sep 12, 2024
@Artturin
Copy link
Copy Markdown
Member Author

Undrafting to get reviews from probably all the codeowners in nixpkgs.

To keep the emails to a minimum either approve or thumbs up the PR if the idea is okay, or if it needs changes then let's discuss in https://matrix.to/#/#stdenv:nixos.org

@K900
Copy link
Copy Markdown
Contributor

K900 commented Sep 19, 2024

Idea is OK, list of merge conflicts is scary. Maybe do this stepwise?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
] ++ lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.inotify-tools;
] ++ lib.optional pkgs.stdenv.buildPlatform.isLinux pkgs.inotify-tools;

This probably applies to most conditionals for any nativeBuildInputs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let’s maybe fix these patterns in another PR, as it doesn’t match the current behaviour and would disrupt the primary metric (almost no rebuilds) we can judge this PR’s safety by? At least now it will be obviously wrong.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good point, but maybe leave the bad ones as is, so they're easy to update in the follow-up PR? Or I guess this PR's diff could be used for that purpose. It's a bit more hidden, but about as good.

SGTM

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it would require a smarter script than a simple text substitution to diagnose and avoid these cases, so I’d personally prefer to avoid holding this up over that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hostPlatform may just as easily be correct for nativeBuildInputs. I'd just mechanistically replace them. Mistakes are mistakes before and after, they are just more obvious after.

I'd guess in most cases it also sort of doesn't matter since the derivations don't cross compile to begin with or (as is the case here) don't really make sense to cross compile.

@philiptaron
Copy link
Copy Markdown
Contributor

@Artturin, I think you have 15 thumbs up on this issue. What's the right way to land this, given the scariness of the set of merge conflicts?

@emilazy
Copy link
Copy Markdown
Member

emilazy commented Sep 24, 2024

Let’s just rebase, wait for the ofborg rebuilds number, and merge. Best to get this in before 24.11 because of backports.

@Ericson2314
Copy link
Copy Markdown
Member

Excited this is finally happening. Thanks @Artturin!

In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
`treewide: replace stdenv.is with stdenv.hostPlatform.is`
@emilazy
Copy link
Copy Markdown
Member

emilazy commented Sep 24, 2024

Reproduced the commits locally, ofborg has reported low build numbers on previous rebases, seems impossible to race ofborg and merge conflicts. Merging now and will take responsibility for the revert if ofborg throws up a scary result.

@nim65s nim65s mentioned this pull request Oct 27, 2024
13 tasks
@pluiedev pluiedev mentioned this pull request Dec 10, 2024
13 tasks
@wolfgangwalther wolfgangwalther mentioned this pull request Dec 22, 2024
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: agda A dependently typed programming language / interactive theorem prover 6.topic: dotnet Language: .NET 6.topic: emacs Text editor 6.topic: Enlightenment DE The Enlightenment Desktop Environment 6.topic: erlang General-purpose, concurrent, functional high-level programming language 6.topic: flakes The experimental Nix feature 6.topic: flutter Open-source UI software development kit for cross-platform applications 6.topic: golang Go is a high-level general purpose programming language that is statically typed and compiled. 6.topic: haskell General-purpose, statically typed, purely functional programming language 6.topic: julia Julia is a high-level, high-performance dynamic language for technical computing. 6.topic: jupyter Interactive computing tooling: kernels, notebook, jupyterlab 6.topic: k3s Kubernates distribution (https://k3s.io/) 6.topic: lib The Nixpkgs function library 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 6.topic: lua Lua is a powerful, efficient, lightweight, embeddable scripting language. 6.topic: LXQt The Lightweight Qt Desktop Environment 6.topic: mate The MATE Desktop Environment 6.topic: nim Nim programing language 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: nodejs Node.js is a free, open-source, cross-platform JavaScript runtime environment 6.topic: ocaml OCaml is a general-purpose, high-level, multi-paradigm programming language. 6.topic: php PHP is a general-purpose scripting language geared towards web development. 6.topic: python Python is a high-level, general-purpose programming language. 6.topic: qt/kde Object-oriented framework for GUI creation 6.topic: ruby A dynamic, open source programming language with a focus on simplicity and productivity. 6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. 6.topic: vim Advanced text editor 6.topic: vscode A free and versatile code editor that supports almost every major programming language. 6.topic: zig Zig is an imperative, general-purpose, statically typed, compiled system programming language. 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants