# [[Zero to Nix]]
*An unofficial, opinionated, gentle introduction to Nix*
[zero-to-nix.com](https://zero-to-nix.com/)
- [GitHub repo](https://github.com/DeterminateSystems/zero-to-nix) for the tutorial
- Main [flake.nix](https://github.com/DeterminateSystems/zero-to-nix/blob/main/flake.nix)
- Rust [flake.nix](https://github.com/DeterminateSystems/zero-to-nix/blob/main/nix/templates/dev/rust/flake.nix)
## [Quick start](https://zero-to-nix.com/start)
### Install
Install
```
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
```
Examine then install
```
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix > nix-installer.sh
chmod +x nix-installer.sh
./nix-installer.sh install
```
Verify install
```
nix --version
```
### Run a program
```
echo "Hello Nix" | nix run "nixpkgs#ponysay"
```
### Dev environments
Enter dev environment
```
nix develop "github:DeterminateSystems/zero-to-nix#example"
```
See that installations are different
```
type curl
type git
```
Git hook example
```
nix develop "github:DeterminateSystems/zero-to-nix#hook"
```
Exit the envirenment
```
exit
```
Run commands without entering the environment
```
nix develop "github:DeterminateSystems/zero-to-nix#example" --command git help
nix develop "github:DeterminateSystems/zero-to-nix#example" --command curl https://example.com
```
Rust
```
nix develop "github:DeterminateSystems/zero-to-nix#rust"
```
```
type cargo
```
```
cargo init ./zero-to-nix-rs
cd ./zero-to-nix-rs
cargo run
```
Mixed environment
```
nix develop "github:DeterminateSystems/zero-to-nix#multi"
```
#### Local flake
Get [template](https://github.com/DeterminateSystems/zero-to-nix/blob/main/nix/templates/dev/rust/flake.nix):
```
mkdir nix-rust-dev && cd nix-rust-dev
nix flake init --template "github:DeterminateSystems/zero-to-nix#rust-dev"
```
Enter local flake
```
nix develop
```
### Building packages
#### Build a package from Nixpkgs
Build [[bat]]
```
mkdir build-nix-package && cd build-nix-package
nix build "nixpkgs#bat"
```
See symlink of output
```
readlink result
```
Run [[bat]]
```
./result/bin/bat --help
```
#### Build Rust package
Run [[ripgrep]]
```
nix build "nixpkgs#ripgrep"
./result/bin/rg --help
```
#### Build [[Home Manager]] from [[GitHub]]
Build
```
nix build "github:nix-community/home-manager"
```
Run
```
./result/bin/home-manager --help
```
#### Build a package in a local flake
Fetch the [template](https://github.com/DeterminateSystems/zero-to-nix/blob/main/nix/templates/pkg/rust/flake.nix):
```
mkdir nix-rust-pkg && cd nix-rust-pkg
nix flake init --template "github:DeterminateSystems/zero-to-nix#rust-pkg"
```
```
nix build
```
```
./result/bin/zero-to-nix-rust
```
### Search for Nix packages
```
nix search nixpkgs cargo
```
```
nix search nixpkgs cargo --json
```
```
nix flake show github:nix-community/nixpkgs-wayland
```
### Uninstall Nix
```
/nix/nix-installer uninstall
```
```
ls /nix # error
ls ~/.nix-profile # error
```