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

#! /usr/bin/env bash for all scripts that rely on it #8644

Closed
sonjiku opened this issue Jul 4, 2023 · 3 comments
Closed

#! /usr/bin/env bash for all scripts that rely on it #8644

sonjiku opened this issue Jul 4, 2023 · 3 comments
Labels
feature Feature request or proposal

Comments

@sonjiku
Copy link

sonjiku commented Jul 4, 2023

Hey.

I like to use dash as my posix shell for shell scripts, by simlinking it to /usr/bin/sh. I've heard that nix uses a lot of shell scripts that rely on bash, which could be affected by a change like that. Could you verify if that's true? If it is, could you perhaps correct the shebangs to reflect the reliance on bash instead of just any shell?

@sonjiku sonjiku added the feature Feature request or proposal label Jul 4, 2023
@abathur
Copy link
Member

abathur commented Jul 4, 2023

I've heard that nix uses a lot of shell scripts that rely on bash, which could be affected by a change like that. Could you verify if that's true?

The Nix ecosystem does indeed use a lot of bash.

If it is, could you perhaps correct the shebangs to reflect the reliance on bash instead of just any shell?

Why do you believe there's anything to correct?

(i suspect you have some mistake impression about how nix works. It does not really care about your system executables.)

@sonjiku
Copy link
Author

sonjiku commented Jul 4, 2023

Hey, thanks for the quick reply!

I am not against the use of bash, I don't believe that should change. I am pretty new to nix tbh, I've installed NixOS about a week ago and I'm still learning. I'm really enjoying it up to this point.

My main concern is about me being able to change the sh executable to redirect to dash as it faster. I do not know if shell scripts that nix uses specifically call bash or sh, and while looking at how I use dash, I was told by other nix users that it could affect the way nix works.

Do you know if that is true, or is there no reason to worry about this?
In case it is true, I think it would be better to explicitly call for bash instead of sh.

@abathur
Copy link
Member

abathur commented Jul 4, 2023

Ah. This is a NixOS question.

This repository is for the Nix package manager itself, and (speaking generally) Nix itself doesn't have this problem. The code for NixOS is in https://github.com/nixos/nixpkgs, so that'll be the appropriate place to follow up on this.

I'm not personally familiar with the details here, but it sounds like whatever you've heard is probably inspired by the description of the option for setting it:

https://github.com/NixOS/nixpkgs/blob/0c3a28f08f207a0b074d5ecbbed21b5b045f690f/nixos/modules/config/shells-environment.nix#L129-L143

You also aren't the only one; I already see a similar issue open in nixpkgs:

I do see some public configs where people use this option (ttps://github.com/search?q=language%3Anix+%2Fenvironment.binsh.*pkgs.dash%2F&type=code), so I guess that's a sign that replacing it works well enough for some people.

The "warning" was added along with the option to make this configurable 10 years ago, so it's possible that other people replacing this with dash have contributed fixes to any issues they personally run into. Nixpkgs should be receptive to fixes if you try this and run into any dash syntax error messages (where a fix might either be avoiding the bashism causing trouble, or making sure it specifies bash).

I'm closing this since it's out of scope here, but you can still reply here if you need me to clarify anything above :)

@abathur abathur closed this as completed Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal
Projects
None yet
Development

No branches or pull requests

2 participants