How to open a nix-shell session

I think this might not be 100% clear, but once you have Nix installed there everything should be done using the normal user and no sudo. If you’re doing anything not as the normal user, do mention it, and there should be a reason.

So you should download the repo and run nix-shell both as the normal user etc.

1 Like

The same user I installed nix on

I’m doing everything on the user I created. The commands you told me about from which you concluded nix is installed correctly, installing nix, cloning the repo, and getting “command not found” from the same user

Because for “cd” it says “command not found”

nix-shell: command not found… It’s always command not found or permission denied for nix

Only using cd provided by the Ubuntu system in the VPS you have: As a normal user (not root), is there any path you can cd into normally ?

Like:
cd /tmp
cd /etc
cd /var/log

It is important you do not use sudo -s cd but simply cd

1 Like

Yes these work.
By the way I have in my shell [drtwentyone is my user]:
“drtwentyone@vps:/root$”
I am not in root, so when I type whoami I get “drtwentyone”. But the folder name is root it seems… Though I can change it to tmp or etc or var/log then I get as an example:
“drtwentyone@vps:/var/log$”

This is just my two cents, but maybe nix-shell is giving you permission issues, because it’s by default looking for a file called shell.nix or default.nix, and it cannot read the /root directory. Try doing as the user drtwentyone cd /tmp then nix-shell -p hello.

Also, perhaps you cannot ‘cd’ into the cloned directory because you did git clone as root? You can do chown -R drtwentyone <directory> to recursively change owner, or even chown -R drtwentyone:<group> <directory> where <group> is the group your user is in (you can find this out by running id). (As a sidenote, there was earlier a typo, someone said chmod -R <user> <directory>, but chmod is for changing permissions [read-write-executable for each of user, group, other], it’s chown for changing ownership.)

1 Like

Or even stay within the user $HOME, rather than using roots $HOME.

To expand, this is likely problematic. You’re in someone else’s directory, so you’ll probably have trouble reading and writing files there. Clone the repository anew in your regular user’s own home directory (Just cd without arguments will quickly get there. echo $HOME will show you where it is.)

Getting permission denied does not automatically mean you need sudo. In fact, if you don’t know why you need root permissions, it’s quite likely that the operating system just prevented you from doing something bad. In this case, as said it prevents you from reading/writing other user’s files.

sudo means (by default) ‘run this as root’. Therefore if you are using it, you aren’t running everything as root. This is something important to note.

1 Like

And… Finally, it’s WORKING!!! YOUHOUUUUUU!!!
Alright. It was combination of last 2 posts of dramforever and KoviRobi:
-On my user session, I went to home directory using cd (instead of being in root directory. Confusion was that I am indeed using another user than root but in fact I was in root directory so that is a problem…)
-Then I installed nix according to instructions.
-Then I went to folder tmp (well, don’t ask me why. It doesn’t work from outside tmp, I tried it)
-Then I typed “nix-shell -p hello” (Again, don’t ask me why. Seems like this is the magic phrase to open a nix-shell session. And when I type nix-shell yes it looks for a file named shell.nix or default.nix and doesn’t find it like KoviRobi was saying)
-And… finally… I get on my shell: [nix-shell:/tmp]$ A nix-shell session!!!
-Now I clone successfully the Cardano repository
-And then to nix-build the Cardano repository I had to " chown -R drtwentyone " of a directory that previously was “permission denied” to write into
-And… some problems here lol… (no space left on device…) but this is not the subject of this forum, I I will be handling this by my own.

So as far as opening a nix-shell session is concerned: PROBLEM SOLVED.

Thank you very much for David Paskevic, Stephane Rolland, Jeff Hykin, Jimmy Brisson, jonringer, dramforever, Kovacsics Robert and Norbert Melzer.

2 Likes

You’re welcome.

Don’t be intimidated seeing nix-shell -p hello as a cargo cult command for opening nix-shell. It is much more straightforward than what you could imagine I think. But it accepts many parameters, so it can do a bunch of things indeed.

Behind the curtain nix-shell -p hello will download (it’s a simplification) a hello.nix file, which will serve as a nix expression to compute (or execute if you prefer that wording). That nix expression to compute, is exactly what it was missing when it was searching for the shell.nix or default.nix that it could not access in the /root directory.

It happens that hello is an extremely simple program that just writes Hello World. You could write your own helloDrTwentyOne program in a language of your choice.

try nix-shell -p emacs then emacs -nw , and nix-shell allows you to use emacs, without you having it installed on your machine permanently. (It will disappear when garbage collection is called, and you could not call it without doing nix-shell -p emacs).

2 Likes

It still feels VERY/EXTREMELY strange that you can only perform your user operations only in /tmp
And it may backlash in unexpected way. For example if tmp is a tmpfs, that could/might explain your out-of-memory error, since it would mean that it tries to write everything in RAM. It’s a possibility. Another example is that /tmp might be erased at every boot, in which case you’d have to reinstall your cardano node every time, which I doubt is the most preferable way :wink:

Please, try: cd /home/drtwentyone

If that directory is not existing, I suggest you create it at the moment you create your user.

something like :

mkdir -p /home/drtwentyone
chown drtwentyone:users /home/drtwentyone

or you can
chown drtwentyone:drtwentyone /home/drtwentyone # if you have a drtwentyone group also created

then your user could do all his stuff in his own directory where he has all the rights.

that’s traditionnally how linux users manipulates their files, in their own /home/myuser folder.

1 Like