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

EXPERIMENTAL: replace bash with oil #105233

Closed
wants to merge 8 commits into from

Conversation

zimbatm
Copy link
Member

@zimbatm zimbatm commented Nov 28, 2020

http://www.oilshell.org/ is supposed to be compatible with Bash. Let's
find out if it's true!

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

http://www.oilshell.org/ is supposed to be compatible with Bash. Let's
find out if it's true!
@zimbatm
Copy link
Member Author

zimbatm commented Nov 28, 2020

@zimbatm
Copy link
Member Author

zimbatm commented Nov 28, 2020

nix-build -A bash works.

$ nix path-info -Sshr .#bash
/nix/store/1b3308hdqqxzpjmn0d21d43ixwqv1iry-bash-oil           	760.0 	 39.2M
/nix/store/3g1qm2xf7ysfdnka7hb1mwgx8i4fgxl0-glibc-2.32         	 29.7M	 31.4M
/nix/store/a076ip3brcj4x5a1rnj2j5qisfqh9xgk-oil-0.8.4          	  4.1M	 39.2M
/nix/store/g4gk96z9i98hyyf2j4mzn8vvws6gb7i3-libidn2-2.3.0      	217.5K	  1.8M
/nix/store/ma8xwfjik16p74wxdj640d7mk8wj58z9-libunistring-0.9.10	  1.6M	  1.6M
/nix/store/ydziqgw4hb71mzwgigm641m1wm1isfa5-readline-6.3p08    	382.7K	 35.2M
/nix/store/zg0npll5jbm6fbq6pahva3bhj1krmds3-ncurses-6.2        	  3.4M	 34.8M

@zimbatm
Copy link
Member Author

zimbatm commented Nov 28, 2020

It looks like oil doesn't support all of the bash startup flags. --norc, --noprofile and --rcfile seem to be quite important for interactive shells.

@zimbatm
Copy link
Member Author

zimbatm commented Nov 28, 2020

$ nix-build -A perl
warning: unknown setting 'extra-sandbox-paths'
these 2 derivations will be built:
  /nix/store/li1mf14aqavy7i3v93v3768ahqkxk1qh-stdenv-linux.drv
  /nix/store/9rw4di8zixd6cmvy8mzmsq12alwnvv18-perl-5.32.0.drv
warning: unknown setting 'extra-sandbox-paths'
building '/nix/store/li1mf14aqavy7i3v93v3768ahqkxk1qh-stdenv-linux.drv'...
oil: Invalid applet name 'bash'.
error: --- Error --- nix-daemon
builder for '/nix/store/li1mf14aqavy7i3v93v3768ahqkxk1qh-stdenv-linux.drv' failed with exit code 2; last 1 log lines:
  oil: Invalid applet name 'bash'.
error: --- Error ------------------------------------------------------------------------------------------------------------------------------------------------------------------ nix-build
1 dependencies of derivation '/nix/store/9rw4di8zixd6cmvy8mzmsq12alwnvv18-perl-5.32.0.drv' failed to build

@zimbatm
Copy link
Member Author

zimbatm commented Nov 28, 2020

$ nix-build -A perl
these 2 derivations will be built:
  /nix/store/wmfabvifpi3ckzm0r125c1j22wpdd1dk-stdenv-linux.drv
  /nix/store/s6s8rz8fwbxjnpgnwjxchg8s112rs0pk-perl-5.32.0.drv
warning: unknown setting 'extra-sandbox-paths'
building '/nix/store/wmfabvifpi3ckzm0r125c1j22wpdd1dk-stdenv-linux.drv'...
error: --- Error --- nix-daemon
output '/nix/store/mn1zxrxvk2m2fmpq5sq0snpizjqsjlr8-stdenv-linux' is not allowed to refer to the following paths:
  /nix/store/6a1vdcysqv997m920i793iigwnrpmhrn-oil-0.8.4
  /nix/store/8dpaz0i0cz6p4cnjfmvdvh959zqrc0jq-readline-6.3p08
  /nix/store/ddak93ycd54x6m5d6mp5sl6m4x0rgc39-ncurses-6.2
error: --- Error ------------------------------------------------------------------- nix-build
1 dependencies of derivation '/nix/store/s6s8rz8fwbxjnpgnwjxchg8s112rs0pk-perl-5.32.0.drv' failed to build

@zimbatm
Copy link
Member Author

zimbatm commented Nov 28, 2020

$ nix-build -A perl
this derivation will be built:
  /nix/store/02rda66hvdjar8x6rkqhf3g3sy789v00-perl-5.32.0.drv
warning: unknown setting 'extra-sandbox-paths'
building '/nix/store/02rda66hvdjar8x6rkqhf3g3sy789v00-perl-5.32.0.drv'...
type: 'preHook' not found
type: 'addInputsHook' not found
      local -ri hostOffset="$2"
            ^~~
/nix/store/pbx08z51536fi4fp09k8rbqqj9j2d1zr-stdenv-linux/setup:356: 'local' doesn't accept flag -i
      local -ri hostOffset="$2"
      ^~~~~
/nix/store/pbx08z51536fi4fp09k8rbqqj9j2d1zr-stdenv-linux/setup:356: fatal: Exiting with status 2 (command in PID 1)
  source $stdenv/setup
  ^~~~~~
/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh:1: fatal: Exiting with status 2 (command in PID 1)
type: 'failureHook' not found
error: --- Error ------------------------------------------------------------------- nix-build
builder for '/nix/store/02rda66hvdjar8x6rkqhf3g3sy789v00-perl-5.32.0.drv' failed with exit code 2; last 10 log lines:
        local -ri hostOffset="$2"
              ^~~
  /nix/store/pbx08z51536fi4fp09k8rbqqj9j2d1zr-stdenv-linux/setup:356: 'local' doesn't accept flag -i
        local -ri hostOffset="$2"
        ^~~~~
  /nix/store/pbx08z51536fi4fp09k8rbqqj9j2d1zr-stdenv-linux/setup:356: fatal: Exiting with status 2 (command in PID 1)
    source $stdenv/setup
    ^~~~~~
  /nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh:1: fatal: Exiting with status 2 (command in PID 1)
  type: 'failureHook' not found

@ofborg ofborg bot added the 6.topic: stdenv Standard environment label Nov 28, 2020
@zimbatm
Copy link
Member Author

zimbatm commented Nov 28, 2020

currently stuck on the local -i compatibility: oilshell/oil#864

@grahamc
Copy link
Member

grahamc commented Nov 29, 2020

I think osh isn't intended to be interactive, so I guess that is a thing.

@happysalada
Copy link
Contributor

Interested in this!
From what I gather from the issue, I guess that won't be possible though right?
It would require removing all the -i flags.

@zimbatm
Copy link
Member Author

zimbatm commented May 6, 2021

Go for it. -i is relatively rare so if you manage to get past the stdenv, a large part of the tree should build just fine.

It might be worth submitting the -i removal to the stdenv as the -i semantic is weird (see oilshell/oil#864). declare -i foo=foo doesn't even throw an error, it just converts the value to zero.

@happysalada
Copy link
Contributor

Ok, I was a little too optimistic. There is quite some work to do the beam at the moment. I have to put this in the back burner for now.

@zimbatm
Copy link
Member Author

zimbatm commented May 14, 2021

Did you gather some additional notes in the process?

Maybe that's something that can be tackled collectively if we all add a little stone to the road.

@happysalada
Copy link
Contributor

unfortunately not, I went down a rabbit hole of researching oil, the new language andrew wants to make.
I thought instead of osh, why not go the full way into oil.
My take on it is that it's a little early to start thinking about switching out of bash.

@happysalada
Copy link
Contributor

I'm giving this another go.
Here are things that could be interesting.

  • I'm using shellcheck to fix some lints https://www.shellcheck.net/
  • You definitely want to turn on debugging statements for the shell. There is a special NIX_DEBUG var, but I haven't found how to use it. a simple env NIX_DEBUG=10 nix-build -A perl does not work. What I do instead is use this as the line of osh execution exec ${oil}/bin/osh -x -O strict:all "\$@". -x to turn on debugging. I'm trying strict:all to see if more "bugs" wouldn't appear.
  • My rationale so far.
    • Split this into 2 parts, the first part will just a bunch of fixes to .sh files. Those fixes would consist of a mix of shellcheck lints and some things that are necessary to run osh. If we include shellcheck lints, perhaps people would be less reticent in including some of the things that are only needed to make osh run. For example removing the -i flag on defining a variable. It definitely makes the intent less clear, so I'm thinking people might object to this.

nix-build -A bash does indeed work with no problems.
nix-build -A perl fails on stage 3. I am trying something else before I post the error. Every build takes about 2 hours on machine.
The next failure is related to a problematic reference on burning oil. The stdenv stages allowedRequisites attribute need to be modified I think.
I'm going to open a separate PR, I hope it will be clearer.

@happysalada
Copy link
Contributor

just opened a PR here #127736
I will post the errors as I go along.

@stale
Copy link

stale bot commented Jan 8, 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 8, 2022
@happysalada
Copy link
Contributor

Still working on that, albeit, slowly.

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

Is this still being worked on? Is it replaced by #131676 ?

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 17, 2023
@happysalada
Copy link
Contributor

@adamcstephens thanks for coming around!
I've tried to replace bash with oil, I've even made an RFC about it. However the community didn't really want to go that route. They mostly felt that nix was complicated enough as it was and were scared that oil is small and could possibly stop being maintained.
While oil is getting better and better, I still don't think that the nixos community would be ready to accept it unfortunately (only my opinion though).

@adamcstephens
Copy link
Contributor

@happysalada makes sense. Should we close this and the other attempts at that switch then?

@happysalada
Copy link
Contributor

Depends on what the intent is, if the intent is to try to reduce the number of PRs open, then sure.
The only reason I left mine open was to leave some potential clues for people who ever work on bash. Also as a potential reference if this changes in the future (if oil gets some cool new feature).
Personally, I'm happy to close my PR.

@infinisil infinisil added the significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc. label Apr 19, 2023
@zimbatm
Copy link
Member Author

zimbatm commented May 6, 2023

closing as I'm not going to keep working on this, it was a fun experiment

@zimbatm zimbatm closed this May 6, 2023
@zimbatm zimbatm deleted the burning-oil branch May 6, 2023 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict 6.topic: stdenv Standard environment significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants