# NixOS

- Page: https://shared.btbytes.com/p/nixos
- Date: 2020-04-13
- Tags: devops, nixos

## Why NixOS

[Via this HN Comment](https://news.ycombinator.com/item?id=36262356)
Maintaining your system configuration is an exercise in software development like any other - if you lack rigor or discipline, your codebase will become painful to work with. Nothing is ever one shell incantation away - it has to be carefully architected into the existing system.

That being said, once you get the hang of things, you reap amazing benefits:

- You can clone your system to any machine, and immediately have an identical environment
- You can share system configurations as code (declare the means for hosting a website in its repository, for example)
- You can use a fully-fledged programming language to configure any part of your system
- You can make use of an extensive ecosystem of easily composable, prebuilt NixOS modules
- You can seamlessly integrate with Nix, allowing for ephemeral development environments and shells with packages, eliminating much of the need for imperative package management
- Everything in a Nix-based system must be derived strictly from (lockfiled) inputs, making the reproducibility guarantees incredibly strong (barring any network errors or resources being taken down)
- The declarative nature of anything Nix-based means that every change is documented - your system never shifts from the source of truth, compared to other distros where discipline is required to maintain reproducibility
- Nix is so robust that you could even nuke your filesystems on every log out, if you'd like

## Quick Reference

```bash

nix-env -iA nixpkgs.octave # to install octave
nix-env -e octave # to uninstlal octave
nix-env --delete generations # to delete old generations
# See [GC](https://nixos.org/manual/nix/stable/package-management/garbage-collection.html)
nix-storage --gc # for collecting garbage and actually removing files from HDD

```

See [MyNixOS site](//mynixos.com/) --  [home.sessionVariables - MyNixOS](https://mynixos.com/home-manager/option/home.sessionVariables)

## Nix Language

- <https://nix.dev/> -- An opinionated guide for developers wanting to get things done using the Nix ecosystem.
-  [Nix explained from the ground up - YouTube](https://www.youtube.com/watch?v=5D3nUU1OVx8)
- [Is there good explanation anywhere of the syntax of those files? I tried getting... | Hacker News](https://news.ycombinator.com/item?id=15269705)
- [Learn nix in Y Minutes](https://learnxinyminutes.com/docs/nix/)
- [A Gentle Introduction to the Nix Family](https://ebzzry.io/en/nix/)
- [Nix Language Primer | binary.phile](http://www.binaryphile.com/nix/2018/07/22/nix-language-primer.html)
- [Environments with Nix Shell - Learning Nix pt 1 - sam.today](https://www.sam.today/blog/environments-with-nix-shell-learning-nix-pt-1/); there are 4 posts as of Oct 2022.
- [Explainix](https://zaynetro.com/explainix) -- explain nix visually; Feb 2024.

## Nix Flakes

- [Why did Nix Adopt Flakes?](https://www.jetpack.io/blog/why-did-nix-adopt-flakes/)

## Tutorials

- [Learning Nix from the bottom up](https://fasterthanli.me/series/building-a-rust-service-with-nix/part-9)
- [Matthew Croughan - What Nix Can Do - SCaLE20x - YouTube](https://www.youtube.com/watch?v=6Le0IbPRzOE); Mar 2023. Nix REPL.
- [Zero to Nix](https://zero-to-nix.com/)
- [Learning Nix by Example: Building FFmpeg 4.0 - Nedtes](https://blog.kiloreux.me/2018/05/24/learning-nix-by-example-building-ffmpeg-4-dot-0/)
- [shajra/example-nix: a way to develop software with Nix](https://github.com/shajra/example-nix)
* [How I Start: Nix - Christine Dodrill](http://web.archive.org/web/20200308203205/https://christine.website/blog/how-i-start-nix-2020-03-08); Mar 2020.
- [Building 15-year-old software with Nix](https://blinry.org/nix-time-travel/); Apr 2023. Builds GIMP and Blender from 2008.
- [NixOS & Flakes Book | Home Page](https://nixos-and-flakes.thiscute.world/); Oct 2023.
- [How I use Nix on macOS | Fatih's Personal Blog](https://blog.6nok.org/how-i-use-nix-on-macos/); Feb 2024.

## NixOps

- [How to use NixOps in a team - We Are Wizards Blog](http://web.archive.org/web/20160312153207/https://blog.wearewizards.io/how-to-use-nixops-in-a-team)

## Nix land

via [domenkozar](https://x.com/domenkozar/status/1589662179883896832):

- binary cache service: <http://cachix.org> (2018)
- ci: <http://hercules-ci.com>  (2019)
- documentation site: <http://nix.dev> (2020)
- deploy: <http://app.cachix.org/deploy> (2021)


## Nix + Rust

* [Building Nix flakes from Rust workspaces](https://www.tweag.io/blog/2022-09-22-rust-nix/)


## Articles

- [An unordered list of hidden gems inside NixOS](https://kokada.capivaras.dev/blog/an-unordered-list-of-hidden-gems-inside-nixos/)
- [Nix - Why Now](https://whynowtech.substack.com/p/nix) by Alex Mackenzie. "Containers without Containers". Nov 2022.
- [Erase your darlings: immutable infrastructure for mutable systems - Graham Christensen](https://grahamc.com/blog/erase-your-darlings)
- The best presentation on [Nix package manager](https://arianvp.github.io/nixtalk/slides/slides.html) by Arian Van Putten I've read; Aug 2018.
- [Everything You Always Wanted To Know About Nix (But Were Afraid To Ask)](https://www.youtube.com/watch?v=2mG0zM_wtYs) -- Youtube talk by Edward Amsden.
- [Lightning Introduction to Nix for Developers - sulami's blog](https://blog.sulami.xyz/posts/nix-for-developers/); Nov 27, 2020.
- [Nix, the PhD Thesis](http://philandstuff.github.io/pf-deployment/#/) presentation by Philip Potter.
- [You Are Most Likely Misusing Docker](http://www.mpscholten.de/docker/2016/01/27/you-are-most-likely-misusing-docker.html) -- you could be using Nix instead.
- [What is Nix and Why you should try it!](https://yakking.branchable.com/posts/what-and-why-nix/)
- [What Is Nix](https://shopify.engineering/what-is-nix) by shopify engineering; May 2020.
- [Nix, the purely functional build system](http://www.boronine.com/2018/02/02/Nix/) by Alexei Bornoine. This is a pretty good introduction to set up nix and do a "Hello world!" app build.  Pay special attention to the case study of HSLuv, a website that is built and deployed entirely using Nix. What makes this a good example to study is that the website uses multiple, disparate software systems (JDK, Haxe, Node.js etc.,).
* [A Nix Terminology Primer by a newcomer](https://stephank.nl/p/2020-06-01-a-nix-primer-by-a-newcomer.html)
- [NixOS: A lasting impression | Jeaye's Blog](https://blog.jeaye.com/2017/07/30/nixos-revisited/)
[Anders' Blog - The NixOS Landscape - Nix, nixpkgs, NixOS](http://anderspapitto.com/posts/2016-06-08-nixos-landscape.html) -- what the different words mean.
- [Nix by example, Part 1: The Nix expression language](https://medium.com/@MrJamesFisher/nix-by-example-a0063a1a4c55) -- This is quite good; Oct 24 2019.
- [Intro](http://datakurre.pandala.org/2014/09/nix-expressions-as-executable-commands.html) with python virtualenv/buildout examples.
- [Nix Cookbook](http://funops.co/nix-cookbook/) by Susan Potter.
- [Control your packages with Nix created profiles!](http://web.archive.org/web/20150130105234/http://blog.matejc.com/blogs/myblog/control-your-packages-with-nix-environments/) [Jan 2014]
- [zalora](https://github.com/zalora) has developed quite a nix packages and use it [Production](https://nixos.org/wiki/Nix\(OS\)_in_production)
- [setting up development environments with nix](http://zef.me/5966/setting-up-development-environments-with-nix) is a good, hands-on intro.
- [NixOS + Hydra + Nginx](http://blog.matejc.com/blogs/myblog/nixos-hydra-nginx/) -- setting up your own Hydra build server.
- [Sander van der Burg's blog: Setting up a Hydra build cluster for continuous integration and testing (part 1)](http://sandervanderburg.blogspot.com/2013/04/setting-up-hydra-build-cluster-for.html)
- [Sander van der Burg's blog: Setting up a Hydra build cluster for continuous integration and testing (part 2)](http://sandervanderburg.blogspot.com/2013/04/setting-up-hydra-build-cluster-for_10.html)
- [NixOS and stateless deployment](http://gfxmonk.net/2015/01/03/nixos-and-stateless-deployment.html). good discussion on challenges with downgrade, packaging non-ELF binaries etc.,
- [Nix adoption at Rhodecode](https://garbas.si/2015/thank-you-rhodecode.html) [Aug 2015]
- [A tour of nix](https://nixcloud.io/tour/?id=1) -- practice nix expressions in the browser [Nov 2015]
- [Stack + Nix = portable reproducible builds](http://www.tweag.io/blog/stack-nix-portable-reproducible-builds) [Dec 2015]
- [Tinco.nl](http://blog.tinco.nl/2016/02/05/nixos-on-digital-ocean.html); [discussion](https://redd.it/44attf)
- [How to setup your own hydra server](https://youtu.be/RXV0Y5Bn-QQ) (video). [Source code](https://github.com/peti/hydra-tutorial).
- [Fully setting up a custom nix repository](https://redd.it/4btjnf)
- [A historical perspective on Disnix](http://sandervanderburg.blogspot.jp/2016/01/disnix-05-release-announcement-and-some.html)
- [nixfmt](https://github.com/Gabriel439/nixfmt) -- Automatic code formatter for the Nix programming language.
- [From Vagrant to NixOps - Mayflower Blog](https://blog.mayflower.de/5976-From-Vagrant-to-Nixops.html) 2017
- [NixOS Weekly](http://weekly.nixos.org/)
- [nh2/nix-binary-cache-proxy: An NGINX caching proxy to serve the cache.nixos.org binary cache from your local network, ready-to-deploy with nixops](https://github.com/nh2/nix-binary-cache-proxy)
- [Nix under the hood](https://github.com/Gabriel439/slides/blob/master/nix-internals/slides.md) by Gabriel439 [Dec 2017].
- [Deploy software easily and securely using nix-deploy](http://ixmatus.net/articles/deploy-software-nix-deploy.html) [Dec 2017].
nixos configs to study:
- [Corey O'connor](https://github.com/coreyoconnor/nix_configs)
- [NixOS 2.0 release lobste.rs discussion](https://lobste.rs/s/nodrls/nix_2_0_released)
- [Docker Layers, Caching, and Nix - Graham Christensen](https://grahamc.com/blog/nix-and-layered-docker-images)
- [NixOS for the Impatient](https://borretti.me/article/nixos-for-the-impatient) talks about how to setup home-manager with easy example.

### Blogs

- [Computing - Shen's Essays](https://shen.hong.io/tag/computing/) has many [nixos](https://shared.btbytes.com/p/nixos) articles including how to setup home manager, sway, wayland, FDE, latex on linux friendly laptop like Purism Librem.



## Running log

2022-11-27 [MyNixOS](https://mynixos.com/) (selfnote: account using github.) - Build and share reproducible software environments with Nix and NixOS.

2022-10-24 [Blog posts on Nix](https://ianthehenry.com/posts/how-to-learn-nix/) at `ianthehenry.com`; and [Using Nix on macOS](https://checkoway.net/musings/nix/)

2018-06-05
- [Testing Nix Packages in Docker](https://dzone.com/articles/testing-nix-packages-innbspdocker)
- <https://cachix.org/> tied to my github account.
- [Integration woes with docker containers and NixOS](http://ixmatus.net/articles/hocker-nixos-docker.html)
- [NixOS on prgmr and Failing to Learn Nix | push.cx](https://push.cx/2018/nixos) .. [and comments](https://lobste.rs/s/gqupat/nixos_on_prgmr_failing_learn_nix)

2019-02-24 [Static Nix: a command-line swiss army knife](https://matthewbauer.us/blog/static-nix.html).. looks promising to use even on systems where creating `-nix` is not an option.  Can run `nix` as an unprivileged user.

2019-10-14 [bauer: an Emacs+Nix IDE](https://matthewbauer.us/bauer/)

2019-11-11 [Package a Django website](https://old.reddit.com/r/NixOS/comments/bw8xhl/package_a_django_website/epw8ryv/) -- [acelpb/acelpb: Configuration for acelpb.com](https://github.com/acelpb/acelpb)
2019-11-11 [Nix for Python developers | Asko Soukka](https://datakurre.pandala.org/2015/10/nix-for-python-developers.html/)

2019-11-26 [Nix recipes for Haskellers — Sridhar Ratnakumar](https://www.srid.ca/haskell-nix.html)

2020-02-29 Edit `/etc/configuration.nix` to add default packages. Run `nixos-rebuild switch` to update the system to match the configuration.

`cron` is not installed by default (because nix [uses systemd timers](https://flyingcircus.io/doc/guide/platform_nixos/cron.html)and users not allowed to have crontab by default too! *quelle surprise*. To do that you have to [edit the `/etc/configuration.nix`](https://nixos.wiki/wiki/Cron) file do any thing.

2023-03-06 [Nix-powered development with OCaml - Dimitrije's Website](https://dimitrije.website/posts/2023-03-04-nix-ocaml.html)

2023-09-25 [Fast, Declarative, Reproducible, and Composable Developer Environments - devenv](https://devenv.sh/)

2024-03-28 [Flakes aren't real and cannot hurt you: a guide to using Nix flakes the non-flake way - jade's www site](https://jade.fyi/blog/flakes-arent-real/)
