Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glibc: Fix _CS_PATH to include default profile #94937

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

McDutchie
Copy link

@McDutchie McDutchie commented Aug 8, 2020

Motivation for this change

The string returned by confstr(_CS_PATH), which is also the output of the command getconf PATH, contains a default path that is guaranteed to find (at least) all POSIX standard utilities. The current value is:

/run/current-system/sw/bin:/bin:/usr/bin

There are two problems with this.

  1. /bin and /usr/bin should be removed, as NixOS package management never puts anything there. Anything dropped in /bin or /usr/bin under the name of a standard utility would likely be bogus.

  2. The default profile binaries directory is not in it. This is a problem because the default NixOS installation lacks several mandatory standard POSIX utilities. The command recommended by the system's error message for a missing command to install a missing package foo is nix-env -iA nixos.foo. When this is done as root, the corresponding binaries are installed for all users in /nix/var/nix/profiles/default/bin.

Things done

pkgs/development/libraries/glibc/fix_path_attribute_in_getconf.patch:

  • CS_PATH: Replace /bin:/usr/bin fallback by default profile path /nix/var/nix/profiles/default/bin.

Fixes: #65512

The string returned by confstr(_CS_PATH)[*1], which is also the
output of the command 'getconf PATH'[*2], contains a default path
that is guaranteed to find (at least) all POSIX standard utilities.
The current value is:

    /run/current-system/sw/bin:/bin:/usr/bin

There are two problems with this.

1. /bin and /usr/bin should be removed, as NixOS package management
   never puts anything there. Anything dropped in /bin or /usr/bin
   under the name of a standard utility would likely be bogus.

2. The default profile binaries directory is not in it. This is a
   problem because the default NixOS installation lacks several
   mandatory standard POSIX utilities. The command recommended by
   the system's error message for a missing command to install a
   missing package foo is 'nix-env -iA nixos.foo'. When this is
   done as root, the corresponding binaries are installed for all
   users in /nix/var/nix/profiles/default/bin.

This commit fixes these problems as follows:

pkgs/development/libraries/glibc/fix_path_attribute_in_getconf.patch:
- CS_PATH: Replace '/bin:/usr/bin' fallback by default profile path
  '/nix/var/nix/profiles/default/bin'.

[*1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/confstr.html
[*2] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/getconf.html

Fixes: NixOS#65512
@McDutchie
Copy link
Author

Could someone rerun the ofborg check? Not sure what it does, but the results indicate it timed out before running anything, so that's not a problem with the PR.

@McDutchie
Copy link
Author

Ping @peti (who committed the original value).

@SuperSandro2000
Copy link
Member

@ofborg eval

@stale
Copy link

stale bot commented Jun 28, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 28, 2021
@McDutchie
Copy link
Author

Again, still not stale. See #65512

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 29, 2021
@lheckemann
Copy link
Member

I'm not sure if /bin and /usr/bin should be removed, due to /bin/sh and /usr/bin/env?

@McDutchie
Copy link
Author

I'm not sure if /bin and /usr/bin should be removed, due to /bin/sh and /usr/bin/env?

/bin and /usr/bin are unused in NixOS. Those compatibility symlinks are for invoking /bin/sh and /usr/bin/env directly, without searching $PATH, so they're not relevant for a default $PATH search. Their real binaries are in /run/current-system/sw/bin.

@stale
Copy link

stale bot commented Jan 3, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 3, 2022
@McDutchie
Copy link
Author

McDutchie commented Jan 3, 2022

Yet again, not stale.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 3, 2022
@SuperSandro2000
Copy link
Member

/bin and /usr/bin are unused in NixOS.

but not when nixpkgs is used in another Distro. I think it is save to add the new entry but not to remove the default entries.

Yet again, not stale.

It didn't get any attention in the last 6 months which is stale. That does not mean it is irrelevant.

@McDutchie
Copy link
Author

/bin and /usr/bin are unused in NixOS.

but not when nixpkgs is used in another Distro. I think it is save to add the new entry but not to remove the default entries.

Surely another distro that uses nixpkgs would use their own libc and not NixOS's version of glibc.

Besides, you cannot know for sure what the correct default directories on any other OS are.

@SuperSandro2000
Copy link
Member

Surely another distro that uses nixpkgs would use their own libc and not NixOS's version of glibc.

Nope, everything is linked against the libc in nixpkgs.

Besides, you cannot know for sure what the correct default directories on any other OS are.

But /bin:/usr/bin is a pretty good guess which works 99% of the time and removing it from the defaults is bound to break things for people that use nixpkgs on none nixos like me.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 31, 2022
@Et7f3
Copy link
Contributor

Et7f3 commented Jan 24, 2023

Non nix-managed tools would most likely be linked agains an external libc.

Do we have a way to query os ? I see stdenv.isCygwin, stdenv.isMips, stdenv.isSunOS but no stdenv.isNixOS.

Maybe add this variable in another PR and use it so on non nixos ok we keep impure path but on nixos we can safely remove them.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 24, 2023
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

glibc: _CS_PATH aka $(getconf PATH) should end in default profile directory
6 participants