marmolak / gray386linux

Linux distribution for i386 machines only.
BSD 2-Clause "Simplified" License
74 stars 5 forks source link

nix-shell can't find "which" command. #1

Closed BloodBlight closed 2 years ago

BloodBlight commented 2 years ago

I have an Ubuntu VM that I am running this build on, and after this command:

cd src/build-env-with-nix/
nix-shell --pure

I get:

........
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/x1as1wikbr6k7vcl9z9p632c2md8hizl-gcc-wrapper-11.2.0
patching script interpreter paths in /nix/store/x1as1wikbr6k7vcl9z9p632c2md8hizl-gcc-wrapper-11.2.0
checking for references to /build/ in /nix/store/x1as1wikbr6k7vcl9z9p632c2md8hizl-gcc-wrapper-11.2.0...
find: '/nix/store/9qi6bzjg8164nqh8l0ccvmfxjs85msvp-gcc-wrapper-11.2.0-man': No such file or directory
find: '/nix/store/ai8bkjs9w2f1p8n7hd84zs0dgbw04w8a-gcc-wrapper-11.2.0-info': No such file or directory
substituteStream(): WARNING: pattern '
' doesn't match anything in file '/nix/store/x1as1wikbr6k7vcl9z9p632c2md8hizl-gcc-wrapper-11.2.0/nix-support/libc-ldflags'
substituteStream(): WARNING: pattern '
' doesn't match anything in file '/nix/store/x1as1wikbr6k7vcl9z9p632c2md8hizl-gcc-wrapper-11.2.0/nix-support/libcxx-cxxflags'
substituteStream(): WARNING: pattern '
' doesn't match anything in file '/nix/store/x1as1wikbr6k7vcl9z9p632c2md8hizl-gcc-wrapper-11.2.0/nix-support/libcxx-ldflags'
building '/nix/store/l93rwgjj0kr9gawnmx7cabq4vy1y0sz9-stdenv-linux.drv'...
bash: which: command not found
ln: failed to create symbolic link 'musl-strip' -> '': No such file or directory
bash: which: command not found
ln: failed to create symbolic link 'musl-ar' -> '': No such file or directory

The which command is installed and located at /usr/bin/which

I assume that it not being able to find the command is causing the next two lines to bug. Any ideas? I am new to the nix-shell.

BloodBlight commented 2 years ago

Looks like the other files are not there:

$ sudo updatedb
$ locate musl-strip
$ locate musl-ar
$
marmolak commented 2 years ago

Hello. Thank you for your feedback.

Seems like --pure is not that pure on my fedora 35 box with bash as a default shell :/.

Yes, which is needed to create musl-strip and musl-ar symlinks (maybe it's stupid hack, so maybe I should find better way).

Would you please try something? I created fix-which-nix branch so you can try it and it should help. Maybe there will be another stuff missing.

Which distro/os do you use? And what is your default shell?

marmolak commented 2 years ago

Ok. You have Ubuntu (sorry, missed that), but which version? I can try to reproduce it on VM.

BloodBlight commented 2 years ago

Ubuntu 20.04

So, I think I am getting further, but I think some part of the compile is cached somehow, and I am not sure how to clear it:

rm -rf gray386linux
git clone --branch fix-which-nix https://github.com/marmolak/gray386linux.git
cd gray386linux
cd src/build-kernel-env-with-nix/
nix-shell --pure

make headers_install ARCH=i386 INSTALL_HDR_PATH=../gray386/
#... no errors

exit

cd ..
cd ..
cd src/build-env-with-nix/
nix-shell --pure

Nothing happened here... It started compiling at this point last time.... I THOUGHT at least. Is something "cached" somewhere for this compile? I even tried cloning the repo to a different locations to see if it would try compiling here... Nothing.

Also, I am not dropped into a different path that I would have expected:

#[nix-shell:~/Downloads/gray386linux/src]$

And so:

#[nix-shell:~/Downloads/gray386linux/src]$ CFLAGS="$CFLAGS -I$(realpath "${PWD}/../gray386/include")" ./configure --target=i386 --prefix=$(realpath "${PWD}/../gray386/")
realpath: /home/###SOME USERNAME###/Downloads/gray386linux/src/../gray386/include: No such file or directory
bash: ./configure: No such file or directory

So I tried:

cd ~/Downloads/gray386linux/src/build-env-with-nix

And get:

$ CFLAGS="$CFLAGS -I$(realpath "${PWD}/../gray386/include")" ./configure --target=i386 --prefix=$(realpath "${PWD}/../gray386/")
bash: ./configure: No such file or directory
BloodBlight commented 2 years ago

If it helps:

[nix-shell:~/Downloads/Test2/gray386linux]$ find . -name configure
./src/musl-1.2.2/configure
marmolak commented 2 years ago

Ok. There is some misunderstanding in documentation. I just don't want to have paths with versions hardcoded into docs, but some different approach (like LFS) with docs per release/update should be better.

build-kernel-env-with-nix - it's just aimed to compile linux kernel (you need old gcc version to do that) and nothing more. So that's why is directory changed directly to kernel directory (and because I'm lazy :)).

build-env-with-nix - is different beast. It allows to compile whole user land without CET (Control-flow Enforcement Technology) which is already handled by kernel patches, but it can slow down system as a whole during runtime (no measurements of any kind here so I don't have exact numbers).

You need to move to desired directory manually. build-env-with-nix allows you to compile your own apps so more freedom is involved.

  1. Build musl libc: you need change your current directory to musl-1.2.2.

then

CFLAGS="$CFLAGS -I$(realpath "${PWD}/../gray386/include")" ./configure --target=i386 --prefix=$(realpath "${PWD}/../gray386/")

  1. Build busybox - you need change your current directory to busybox-1.34.1.

etc...

Thank you for your testing. I need to think about docs again :).

BloodBlight commented 2 years ago

Ahh, k. I will look over this more closely then, but I think I might be a bit over my head.

Say I wanted to add openssh-server? I am guessing I would have to pull the source for it, and then try and get that to compile in this... work space? Not even sure I would have enough RAM for that but... Adjusting any compile flags of course.

marmolak commented 2 years ago

It's easy. You just need to change directory one by one and put commands from documentation.

Yes, if you want to have openssh server installed, you need to do it by your own or you can try to recompile dropbear (included) with server support.

Oh and about caching: nix does some kind of "caching". It stores derivation (in this case, gcc build) into nix store till update. It saves tons of time, because you don't want to recompile gcc each time when nix-shell is invoked.

marmolak commented 2 years ago

BTW: could I close this issue as a fixed? Looks like you are move to another steps which are not related with original isssue.

BloodBlight commented 2 years ago

Yep, I think so!