`stdenv.isDarwin && stdenv.isAarch64` vs `== "aarch64-darwin"`

Just curious, but why is using stdenv.isDarwin && stdenv.isAarch64 so much more popular than e.g. stdenv.hostPlatform.system == "aarch64-darwin"?

$ rg -F 'stdenv.isDarwin && stdenv.isAarch64' | wc -l
$ rg -F '== "aarch64-darwin"' | wc -l

Relevant: Reduce redundant ways to inspect the platforms · Issue #27069 · NixOS/nixpkgs · GitHub

I would guess it’s because it’s code, not string. Whereas it’s easy to mistype a string and not get a compilation error, mistyping code will result in a compilation error, maybe.

I haven’t tried yet and I’m not knowledgeable enough to answer definitively.

1 Like

In my mind, the purpose of the stdenv.<platform>.is* selectors is to select multiple platforms that match some combination of properties.

I usually prefer the latter because of that; if some property really only concerns one specific platform, it should explicitly state that fact.

I don’t like the fact that it’s an unchecked string though as @1d2af541d0f9 points out. I’d much prefer a variable or some kind of checking. Perhaps there could be a stdenv.isPlatform "aarch64-darwin" which would internally try to parse the platform string which would in turn throw if it’s unknown.

I also don’t like that it’s a string literal. I only care that it’s “the platform colloquially known as aarch64-darwin”, not actually that it’s defined as that exact string of characters. We might also want to change our method of declaring platforms at some point and changing all of those strings would be tedious and error-prone. This is a lot harder to fix though.