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

Added how to doc showing nix-shell and editing config #442

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/SUMMARY.md
Expand Up @@ -7,7 +7,7 @@
- [Installation](./install.md)
- [Design](./design.md)
- [Building](./building.md)
- [How-To]()
- [How-To](./how-to.md)
- [Troubleshooting](./troubleshooting/README.md)
- [Recovery Shell](./troubleshooting/recovery-shell.md)

Expand Down
76 changes: 76 additions & 0 deletions docs/src/how-to.md
@@ -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
Copy link
Member

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.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[nix-shell:/mnt/c/t/nix]$ exit
exit
[nixos@nixos:/mnt/c/t/nix]$

```

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
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:

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
environment.systemPackages = [ pkgs.cowsay pkgs.lolcat ];
}

...

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
```