-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
Added how to doc showing nix-shell and editing config #442
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,76 @@ | ||||||||||||
# How-to | ||||||||||||
|
||||||||||||
## Using packages in nix-shell | ||||||||||||
|
||||||||||||
`nix-shell` can be used to run a temporary shell or command that uses packages | ||||||||||||
you don't want to install into your system permanently, or to use other | ||||||||||||
versions of packages than you have installed. For example there is a | ||||||||||||
'cowsay' command that is like echo but with an ascii cow saying the words. | ||||||||||||
If you type `cowsay Hello, world!`, you will get an error that will tell you | ||||||||||||
the cowsay command is provided by multiple packages and show you the nix-shell | ||||||||||||
commands to use them: | ||||||||||||
|
||||||||||||
``` | ||||||||||||
[nixos@nixos:/mnt/c/t/nix]$ cowsay moo | ||||||||||||
The program 'cowsay' is not in your PATH. It is provided by several packages. | ||||||||||||
You can make it available in an ephemeral shell by typing one of the following: | ||||||||||||
nix-shell -p cowsay | ||||||||||||
nix-shell -p neo-cowsay | ||||||||||||
|
||||||||||||
[nixos@nixos:/mnt/c/t/nix]$ nix-shell -p cowsay | ||||||||||||
this path will be fetched (0.01 MiB download, 0.05 MiB unpacked): | ||||||||||||
/nix/store/pjaiq8m9rjgj9akjgmbzmz86cvxwsyqm-cowsay-3.7.0 | ||||||||||||
copying path '/nix/store/pjaiq8m9rjgj9akjgmbzmz86cvxwsyqm-cowsay-3.7.0' from 'https://cache.nixos.org'... | ||||||||||||
|
||||||||||||
[nix-shell:/mnt/c/t/nix]$ cowsay moo | ||||||||||||
_____ | ||||||||||||
< moo > | ||||||||||||
----- | ||||||||||||
\ ^__^ | ||||||||||||
\ (oo)\_______ | ||||||||||||
(__)\ )\/\ | ||||||||||||
||----w | | ||||||||||||
|| || | ||||||||||||
|
||||||||||||
[nix-shell:/mnt/c/t/nix]$ exit | ||||||||||||
exit | ||||||||||||
|
||||||||||||
[nixos@nixos:/mnt/c/t/nix]$ | ||||||||||||
Comment on lines
+35
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
``` | ||||||||||||
|
||||||||||||
You can also specify multiple packages and specify a `--run` parameter to run | ||||||||||||
a single command and exit instead of leaving you in a shell: | ||||||||||||
|
||||||||||||
``` | ||||||||||||
nix-shell -p cowsay lolcat --run "cowsay Hello, cat! | lolcat" | ||||||||||||
``` | ||||||||||||
|
||||||||||||
|
||||||||||||
## System Packages | ||||||||||||
|
||||||||||||
To add packages, edit `/etc/nixos/configuration.nix` using sudo. You | ||||||||||||
can use the `nano` editor which comes installed and uses CTRL+S to save | ||||||||||||
and CTRL+X to exit: | ||||||||||||
Comment on lines
+51
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We don't need to write blocksatz. |
||||||||||||
|
||||||||||||
``` | ||||||||||||
sudo nano /etc/nixos/configuration.nix | ||||||||||||
``` | ||||||||||||
|
||||||||||||
At the bottom you can add system packages to be available in the system: | ||||||||||||
|
||||||||||||
``` | ||||||||||||
environment.systemPackages = [ pkgs.cowsay pkgs.lolcat ]; | ||||||||||||
} | ||||||||||||
Comment on lines
+61
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
... environment.systemPackages = [ pkgs.cowsay pkgs.lolcat ];
|
||||||||||||
``` | ||||||||||||
|
||||||||||||
To switch to the new configuration use this: | ||||||||||||
|
||||||||||||
``` | ||||||||||||
sudo nixos-rebuild switch | ||||||||||||
``` | ||||||||||||
|
||||||||||||
Now you can use the commands provided in those packages by default: | ||||||||||||
|
||||||||||||
``` | ||||||||||||
cowsay Hello, NixOS! | lolcat | ||||||||||||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't encourage people to run commands inside /mnt/ as it very slow. Please use a normal path like ~ in the examples.