Add README.md
Signed-off-by: George Kaklamanos <gkaklas@gkaklas.gr>
This commit is contained in:
parent
f30bdd45ce
commit
e83ba04cf4
1 changed files with 129 additions and 0 deletions
129
README.md
Normal file
129
README.md
Normal file
|
@ -0,0 +1,129 @@
|
|||
# nix-stuff
|
||||
|
||||
## What is nix?
|
||||
|
||||
|
||||
Nix is a package manager, like `apt`,`yum`,`dnf`,`pip`, etc. It can be installed in any operating system, although there is a Linux distribution that uses it by default: NixOS.
|
||||
|
||||
When installed independently, it doesn't interfere with the system's package manager (e.g. `apt`), as it uses a separate directory for everything: `/nix`.
|
||||
|
||||
## Why nix?
|
||||
|
||||
It allows for creating *reproducible* environments. This means that once a development environment has been created, its configuration can be shared with other developers on the team, and have it work exactly the same way!
|
||||
|
||||
This has multiple benefits:
|
||||
* Each developer doesn't need to struggle with installing every library one-by-one, taking care of incompatible versions, missing packages, adding third-party repositories (e.g PPAs for Ubuntu), etc
|
||||
* Easy on-boarding means contributors can start more easily!
|
||||
|
||||
## Why not...
|
||||
|
||||
* Docker/Podman:
|
||||
* It's not reproducible! The versions for every package installed depends on what was available the day the image was built. Some distribution package managers support version pinning, but that might not always work as expected. Nix references packages not only by version, but also by the hash of its contents, and one can also easily reference the `nixpkgs` repository's snapshot at a specific point in time (it's a git repository == commit!). This also means that multiple versions of the same library can be installed at the same time.
|
||||
* Inconvenient for everyday use: A large image will take a few seconds to start; the user needs to mount every directory needed as volumes; UID and file permissions and ownership inconsistencies; the user's system's familiar shell configuration, aliases, and utilities, are not available inside the container, etc
|
||||
* `pip`:
|
||||
* Is language-specific; nix can manage *everything*, so the way it is used across an organization would be more uniform and familiar across projects
|
||||
* It isn't able to install system utilities, compilers, etc (which some pypi packages need during installation!)
|
||||
* `chroot`/`lxc` containers
|
||||
* Harder to use for a development workflow
|
||||
* Similar problems with Docker/Podman
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
### `nix`
|
||||
|
||||
The [recommended way](https://nixos.org/download/#download-nix) is:
|
||||
|
||||
```sh
|
||||
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --daemon
|
||||
```
|
||||
|
||||
If you encounter any issues during installation, for example if your Linux distribution uses SELinux, you can try the single-user installation:
|
||||
|
||||
```sh
|
||||
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --no-daemon
|
||||
```
|
||||
|
||||
or [Determinate nix](https://docs.determinate.systems/), a nix distribution (!= Linux distribution):
|
||||
|
||||
```sh
|
||||
curl -fsSL https://install.determinate.systems/nix | sh -s -- install --determinate
|
||||
```
|
||||
|
||||
### `devbox`
|
||||
As using nix by its own can be daunting for new users, we can use [devbox](https://jetify-com.vercel.app/docs/devbox/) (think of it as a wrapper for nix, which can be used like python/pip but for any package we need!)
|
||||
|
||||
```sh
|
||||
nix profile install nixpkgs#devbox
|
||||
```
|
||||
|
||||
## Using `devbox`
|
||||
|
||||
To create a `devbox` configuration:
|
||||
|
||||
```sh
|
||||
cd project
|
||||
devbox init
|
||||
```
|
||||
|
||||
To manage your project's dependencies:
|
||||
|
||||
```sh
|
||||
devbox add gcc@4.9.4
|
||||
devbox list
|
||||
devbox rm gcc
|
||||
devbox add gcc
|
||||
```
|
||||
|
||||
You can search for packges on [nixhub](https://www.nixhub.io), or directly from the terminal:
|
||||
|
||||
```sh
|
||||
devbox search numpy
|
||||
devbox add python313Packages.numpy
|
||||
```
|
||||
|
||||
Then, enter the environment with:
|
||||
|
||||
```sh
|
||||
devbox shell
|
||||
```
|
||||
|
||||
`devbox` also supports various programming languages. For example, [Python](https://jetify-com.vercel.app/docs/devbox/devbox_examples/languages/python/):
|
||||
once you add it as a dependency, devbox will also manage and activate a Python virtual environment for you:
|
||||
|
||||
```sh
|
||||
devbox add python@3.6.12
|
||||
devbox add gcc git ipcalc
|
||||
devbox shell
|
||||
pip install numpy
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### Bonus use-cases
|
||||
|
||||
[devbox](https://jetify-com.vercel.app/docs/devbox/ide_configuration/direnv/) can also be used with [direnv](https://direnv.net/#basic-installation):
|
||||
|
||||
```sh
|
||||
nix profile install nixpkgs#direnv
|
||||
cd project
|
||||
devbox generate direnv
|
||||
```
|
||||
|
||||
Then, the environment is activated automatically when you enter a project:
|
||||
|
||||
```sh
|
||||
cd project
|
||||
make
|
||||
```
|
||||
|
||||
You could also use `devbox` as a [general package manager](https://jetify-com.vercel.app/docs/devbox/devbox_global/), without needing to `devbox shell` in a project to keep software available:
|
||||
|
||||
```sh
|
||||
devbox global add ripgrep vim git
|
||||
devbox global list
|
||||
```
|
||||
|
||||
The same is possible with a nix command (although `devbox` might still seem easier for beginners): just search [nix packages](https://search.nixos.org/packages) to find the name of a package you want to install
|
||||
```sh
|
||||
nix profile install nixpkgs#wget
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue