nixpkgs-architecture / simple-package-paths

Nix RFC draft for auto-calling packages in nixpkgs
18 stars 1 forks source link

Regarding breaking of `builtins.unsafeGetAttrPos "<name>" pkgs` #25

Closed infinisil closed 1 year ago

infinisil commented 1 year ago

https://github.com/nixpkgs-architecture/simple-package-paths/blob/5ed6a81349479bb4718d71e95c00b4b28a745dc8/README.md?plain=1#L101-L103

Code comment by @andir:

@andir: How is this unsafe other than that the name implies? It returns nullif no information can be found. This isn't like it could crash Nix. It is probably unsafe because it could lead to impurities. Should therefore be called impure.

Removing this feature will also remove the ability to link to the source in the search.nixos.org page as that information (in mkDerivation) relies on unsafeGetAttrPos.

infinisil commented 1 year ago

@andir search.nixos.org and nix edit use pkgs.<name>.meta.position, which uses builtins.unsafeGetAttrPos to get the location of the meta.description attribute. So it won't break those two use cases. We should add search.nixos.org to the "Interactions" section

There might be other use cases that do rely on builtins.unsafeGetAttrPos "<name>" pkgs not being null, but I expect those to be very brittle because they're probably tied to all-packages.nix. Those use cases are probably better implemented using the unit directories anyways though.

I do agree that "impure" is the better word here. While "unsafe" in Nix often does mean impure, it's a bit misleading here

infinisil commented 1 year ago

Rewording to:

This functionality is impure and therefore the result can't be assumed to stay the same over time

nixos-discourse commented 1 year ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2022-01-09-nixpkgs-architecture-team-meeting-24/24556/1