mirror of
https://codeberg.org/privacy1st/nix-git
synced 2024-12-23 02:36:05 +01:00
docs: refactor README and NixOS.md
This commit is contained in:
parent
4f4f51b0d0
commit
76eeefcb8f
140
NixOS.md
140
NixOS.md
@ -2,26 +2,130 @@
|
||||
|
||||
This document contains general notes about NixOS that are independent of my NixOS configuration.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
<!-- TOC -->
|
||||
* [NixOS](#nixos)
|
||||
* [Table of Contents](#table-of-contents)
|
||||
* [Misc](#misc)
|
||||
* [niv: Dependency management](#niv-dependency-management)
|
||||
* [Add Home Manager with niv](#add-home-manager-with-niv)
|
||||
* [Add NUR with niv](#add-nur-with-niv)
|
||||
* [Garbage collection](#garbage-collection)
|
||||
* [System information](#system-information)
|
||||
* [Search for packages](#search-for-packages)
|
||||
* [Search for options](#search-for-options)
|
||||
* [Search which package owns a file](#search-which-package-owns-a-file)
|
||||
* [List files of package](#list-files-of-package)
|
||||
* [Compare two versions of NixOS system profile](#compare-two-versions-of-nixos-system-profile)
|
||||
* [NixOS configuration debugging](#nixos-configuration-debugging)
|
||||
* [Show Nix configuration](#show-nix-configuration)
|
||||
* [Evaluate NixOS configuration to JSON](#evaluate-nixos-configuration-to-json)
|
||||
* [Evaluate expressions](#evaluate-expressions)
|
||||
* [Escape strings](#escape-strings)
|
||||
* [Run AppImages](#run-appimages)
|
||||
* [Additional resources](#additional-resources)
|
||||
* [Nix Pills](#nix-pills)
|
||||
* [Papers](#papers)
|
||||
<!-- TOC -->
|
||||
|
||||
## Misc
|
||||
|
||||
* There is controversy about flakes, rather use channels (e.g. with niv)
|
||||
* Prins, P., Suresh, J. and Dolstra, E., "Nix fixes dependency hell on all Linux distributions," [Archived](https://web.archive.org/web/20081226010942/http://www.linux.com/feature/155922) December 26, 2008, at the Wayback Machine linux.com, December 22, 2008
|
||||
|
||||
## Nix Pills
|
||||
## niv: Dependency management
|
||||
|
||||
* https://nixos.org/guides/nix-pills/pr01
|
||||
* https://nix.dev/tutorials/first-steps/towards-reproducibility-pinning-nixpkgs#dependency-management-with-niv
|
||||
|
||||
It provides a tutorial introduction into the Nix package manager and Nixpkgs package collection, in the form of short
|
||||
chapters called 'pills'.
|
||||
niv:
|
||||
|
||||
## Papers
|
||||
> Easy dependency management for Nix projects.
|
||||
>
|
||||
> Nix is a very powerful tool for building code and setting up environments. niv complements it by making it easy to
|
||||
> describe and update remote dependencies (URLs, GitHub repos, etc). It is a simple, practical alternative to Nix
|
||||
> flakes.
|
||||
>
|
||||
> https://github.com/nmattia/niv
|
||||
|
||||
Papers about Nix:
|
||||
> Niv is an easy dependency management for Nix projects with package pinning.
|
||||
>
|
||||
> https://github.com/mikeroyal/NixOS-Guide
|
||||
|
||||
* The Purely Functional Software Deployment Model (2006). http://nixos.org/~eelco/pubs/phd-thesis.pdf, https://edolstra.github.io/pubs/phd-thesis.pdf, https://github.com/edolstra/edolstra.github.io/blob/master/pubs/phd-thesis.pdf
|
||||
* May 2023: Some insights from the thesis in short form. https://jonathanlorimer.dev/posts/nix-thesis.html
|
||||
* NixOS: A Purely Functional Linux Distribution (2008): https://github.com/edolstra/edolstra.github.io/blob/master/pubs/nixos-icfp2008-final.pdf, https://github.com/edolstra/edolstra.github.io/blob/master/pubs/nixos-jfp-final.pdf
|
||||
* Nix: A Safe and Policy-Free System for Software Deployment (2004): https://edolstra.github.io/pubs/nspfssd-lisa2004-final.pdf
|
||||
Initialize:
|
||||
|
||||
```shell
|
||||
niv init
|
||||
```
|
||||
|
||||
Change the tracking branch of nixpkgs from unstable to 23.05:
|
||||
|
||||
```shell
|
||||
niv modify nixpkgs --branch nixos-23.05
|
||||
```
|
||||
|
||||
Add nixpkgs unstable:
|
||||
|
||||
```shell
|
||||
niv add NixOS/nixpkgs -n unstable -b nixpkgs-unstable
|
||||
```
|
||||
|
||||
### Add Home Manager with niv
|
||||
|
||||
Home Manager:
|
||||
|
||||
> [Home Manager] allows declarative configuration of user specific (non-global) packages and dotfiles.
|
||||
>
|
||||
> To avoid breaking users' configurations, Home Manager is released in branches corresponding to NixOS releases (
|
||||
> e.g. `release-23.05`).
|
||||
>
|
||||
> Home Manager provides both the channel-based setup and the flake-based one.
|
||||
>
|
||||
> https://github.com/nix-community/home-manager
|
||||
|
||||
Check your channel:
|
||||
|
||||
```shell
|
||||
sudo nix-channel --list
|
||||
#=> nixos https://nixos.org/channels/nixos-23.05
|
||||
```
|
||||
|
||||
Use the corresponding branch:
|
||||
|
||||
```shell
|
||||
niv add nix-community/home-manager -n home-manager -b release-23.05
|
||||
```
|
||||
|
||||
### Add NUR with niv
|
||||
|
||||
> The Nix User Repository (NUR) is community-driven meta repository for Nix packages.
|
||||
>
|
||||
> ... packages are built from source and are not reviewed by any Nixpkgs member.
|
||||
>
|
||||
> https://github.com/nix-community/NUR
|
||||
|
||||
```shell
|
||||
niv add nix-community/NUR -n NUR
|
||||
```
|
||||
|
||||
## Garbage collection
|
||||
|
||||
* https://nixos.org/manual/nix/stable/package-management/garbage-collection.html
|
||||
* https://discourse.nixos.org/t/why-doesnt-nix-collect-garbage-remove-old-generations-from-efi-menu/17592/4
|
||||
|
||||
This is automated in [base.nix](modules/base.nix) with the `nix.gc` option.
|
||||
|
||||
Run manually for all profiles:
|
||||
|
||||
```shell
|
||||
sudo nix-collect-garbage --delete-older-than 14d
|
||||
```
|
||||
|
||||
Remove leftover EFI entries of removed generations:
|
||||
|
||||
```shell
|
||||
sudo /run/current-system/bin/switch-to-configuration boot
|
||||
```
|
||||
|
||||
## System information
|
||||
|
||||
@ -280,3 +384,19 @@ appimage-run ~/Downloads/ubports-installer_0.10.0_linux_x86_64.AppImage
|
||||
* Nix data types. https://nixos.org/manual/nix/stable/language/values
|
||||
* MkIfElse. https://discourse.nixos.org/t/mkif-vs-if-then/28521/4?u=langfingaz
|
||||
* Nix language basics - a one pager. https://github.com/tazjin/nix-1p#nix---a-one-pager
|
||||
|
||||
### Nix Pills
|
||||
|
||||
* https://nixos.org/guides/nix-pills/pr01
|
||||
|
||||
It provides a tutorial introduction into the Nix package manager and Nixpkgs package collection, in the form of short
|
||||
chapters called 'pills'.
|
||||
|
||||
### Papers
|
||||
|
||||
Papers about Nix:
|
||||
|
||||
* The Purely Functional Software Deployment Model (2006). http://nixos.org/~eelco/pubs/phd-thesis.pdf, https://edolstra.github.io/pubs/phd-thesis.pdf, https://github.com/edolstra/edolstra.github.io/blob/master/pubs/phd-thesis.pdf
|
||||
* May 2023: Some insights from the thesis in short form. https://jonathanlorimer.dev/posts/nix-thesis.html
|
||||
* NixOS: A Purely Functional Linux Distribution (2008): https://github.com/edolstra/edolstra.github.io/blob/master/pubs/nixos-icfp2008-final.pdf, https://github.com/edolstra/edolstra.github.io/blob/master/pubs/nixos-jfp-final.pdf
|
||||
* Nix: A Safe and Policy-Free System for Software Deployment (2004): https://edolstra.github.io/pubs/nspfssd-lisa2004-final.pdf
|
||||
|
123
README.md
123
README.md
@ -18,7 +18,7 @@ See also:
|
||||
* [ISO](#iso)
|
||||
* [Default configuration](#default-configuration)
|
||||
* [Apply modified configuration](#apply-modified-configuration)
|
||||
* [ARM device: Vanilla UEFI boot loader for the Raspberry Pi 3B+](#arm-device-vanilla-uefi-boot-loader-for-the-raspberry-pi-3b)
|
||||
* [ARM device: Vanilla UEFI bootloader for the Raspberry Pi 3B+](#arm-device-vanilla-uefi-bootloader-for-the-raspberry-pi-3b)
|
||||
* [Update, build and switch](#update-build-and-switch)
|
||||
* [Update](#update)
|
||||
* [Build and switch: Using Colmena](#build-and-switch-using-colmena)
|
||||
@ -26,16 +26,11 @@ See also:
|
||||
* [Option I: Build new config and activate it:](#option-i-build-new-config-and-activate-it)
|
||||
* [Option II: Build new config and activate it during next boot:](#option-ii-build-new-config-and-activate-it-during-next-boot)
|
||||
* [Option III: Build config and view changes:](#option-iii-build-config-and-view-changes)
|
||||
* [niv: Dependency management](#niv-dependency-management)
|
||||
* [Add Home Manager with niv](#add-home-manager-with-niv)
|
||||
* [Add NUR with niv](#add-nur-with-niv)
|
||||
* [Colmena: Deployment and secret management](#colmena-deployment-and-secret-management)
|
||||
* [BTRFS swap file](#btrfs-swap-file)
|
||||
* [BTRFS CoW](#btrfs-cow)
|
||||
* [LUKS Parameters](#luks-parameters)
|
||||
* [Automount encrypted drive](#automount-encrypted-drive)
|
||||
* [Failed services](#failed-services)
|
||||
* [Garbage collection](#garbage-collection)
|
||||
* [List failed services](#list-failed-services)
|
||||
<!-- TOC -->
|
||||
|
||||
## NixOS installation
|
||||
@ -111,13 +106,13 @@ nixos-rebuild boot
|
||||
reboot
|
||||
```
|
||||
|
||||
## ARM device: Vanilla UEFI boot loader for the Raspberry Pi 3B+
|
||||
## ARM device: Vanilla UEFI bootloader for the Raspberry Pi 3B+
|
||||
|
||||
**TODO**: The EFI menu was working. But I got many squashfs errors when booting an USB stick with the NixOS installer.
|
||||
|
||||
* https://www.eisfunke.com/posts/2023/uefi-boot-on-raspberry-pi-3.html
|
||||
|
||||
Preparing a micro SD card with an UEFI boot loader:
|
||||
Preparing a micro SD card with an UEFI bootloader:
|
||||
|
||||
```shell
|
||||
nix-shell -p parted gptfdisk
|
||||
@ -230,80 +225,6 @@ sudo ./result/bin/switch-to-configuration boot
|
||||
|
||||
Note: The Perl script executed by both above commands _should_ create a new bootloader menu entry and mark it as default. However, if I remember correctly, the menu entry was once missing and the configuration change thus not permanent. This might need further testing. See also: https://nixos.wiki/wiki/Nixos-rebuild#Internals
|
||||
|
||||
## niv: Dependency management
|
||||
|
||||
* https://nix.dev/tutorials/first-steps/towards-reproducibility-pinning-nixpkgs#dependency-management-with-niv
|
||||
|
||||
niv:
|
||||
|
||||
> Easy dependency management for Nix projects.
|
||||
>
|
||||
> Nix is a very powerful tool for building code and setting up environments. niv complements it by making it easy to
|
||||
> describe and update remote dependencies (URLs, GitHub repos, etc). It is a simple, practical alternative to Nix
|
||||
> flakes.
|
||||
>
|
||||
> https://github.com/nmattia/niv
|
||||
|
||||
> Niv is an easy dependency management for Nix projects with package pinning.
|
||||
>
|
||||
> https://github.com/mikeroyal/NixOS-Guide
|
||||
|
||||
Initialize:
|
||||
|
||||
```shell
|
||||
niv init
|
||||
```
|
||||
|
||||
Change the tracking branch of nixpkgs from unstable to 23.05:
|
||||
|
||||
```shell
|
||||
niv modify nixpkgs --branch nixos-23.05
|
||||
```
|
||||
|
||||
Add nixpkgs unstable:
|
||||
|
||||
```shell
|
||||
niv add NixOS/nixpkgs -n unstable -b nixpkgs-unstable
|
||||
```
|
||||
|
||||
### Add Home Manager with niv
|
||||
|
||||
Home Manager:
|
||||
|
||||
> [Home Manager] allows declarative configuration of user specific (non-global) packages and dotfiles.
|
||||
>
|
||||
> To avoid breaking users' configurations, Home Manager is released in branches corresponding to NixOS releases (
|
||||
> e.g. `release-23.05`).
|
||||
>
|
||||
> Home Manager provides both the channel-based setup and the flake-based one.
|
||||
>
|
||||
> https://github.com/nix-community/home-manager
|
||||
|
||||
Check your channel:
|
||||
|
||||
```shell
|
||||
sudo nix-channel --list
|
||||
#=> nixos https://nixos.org/channels/nixos-23.05
|
||||
```
|
||||
|
||||
Use the corresponding branch:
|
||||
|
||||
```shell
|
||||
niv add nix-community/home-manager -n home-manager -b release-23.05
|
||||
```
|
||||
|
||||
### Add NUR with niv
|
||||
|
||||
> The Nix User Repository (NUR) is community-driven meta repository for Nix packages.
|
||||
>
|
||||
> ... packages are built from source and are not reviewed by any Nixpkgs member.
|
||||
>
|
||||
> https://github.com/nix-community/NUR
|
||||
|
||||
```shell
|
||||
niv add nix-community/NUR -n NUR
|
||||
```
|
||||
|
||||
## Colmena: Deployment and secret management
|
||||
|
||||
* https://github.com/zhaofengli/colmena#colmena
|
||||
@ -326,8 +247,8 @@ Apply to all non-local nodes:
|
||||
colmena apply --on @server switch
|
||||
#colmena apply --on @server boot
|
||||
|
||||
#colmena apply --on @yodaTab switch
|
||||
#colmena apply --on @yodaTab boot
|
||||
#colmena apply --on remoteTab switch
|
||||
#colmena apply --on remoteTab boot
|
||||
```
|
||||
|
||||
Apply to local node:
|
||||
@ -377,14 +298,6 @@ sudo chattr +C /var/log
|
||||
Note from Arch wiki:
|
||||
> If the 'C' flag is set on a directory, it will have no effect on the directory, but new files created in that directory will have the No_COW attribute.
|
||||
|
||||
## LUKS Parameters
|
||||
|
||||
**Warning**: NixOS has a hardcoded timeout of 10 seconds when opening encrypted drives during boot. Please choose `--iter-time` <= `7500`.
|
||||
|
||||
* https://github.com/NixOS/nixpkgs/blob/ed2ccd4d1748e52d5d28c440d5be4b25a4f21c08/nixos/modules/system/boot/luksroot.nix#L498
|
||||
* https://github.com/NixOS/nixpkgs/blob/ed2ccd4d1748e52d5d28c440d5be4b25a4f21c08/nixos/modules/system/boot/luksroot.nix#L30
|
||||
* https://github.com/NixOS/nixpkgs/blob/ed2ccd4d1748e52d5d28c440d5be4b25a4f21c08/nixos/modules/system/boot/luksroot.nix#L36C7-L36C7
|
||||
|
||||
## Automount encrypted drive
|
||||
|
||||
* Use the same password for all attached LUKS devices to be only prompted once while booting
|
||||
@ -399,29 +312,11 @@ sudo nixos-generate-config --dir hosts/$(hostname)
|
||||
|
||||
* If it is an SSD, enable `boot.initrd.luks.devices.<name>.allowDiscards`
|
||||
|
||||
## Failed services
|
||||
## List failed services
|
||||
|
||||
If there are e.g. file conflicts due to preexisting dotfiles, the Home Manager user service might fail. To list all failed services, run:
|
||||
If there are e.g. file conflicts due to preexisting dotfiles, the Home Manager user service might fail.
|
||||
To list all failed services, run:
|
||||
|
||||
```shell
|
||||
systemctl --failed
|
||||
```
|
||||
|
||||
## Garbage collection
|
||||
|
||||
* https://nixos.org/manual/nix/stable/package-management/garbage-collection.html
|
||||
* https://discourse.nixos.org/t/why-doesnt-nix-collect-garbage-remove-old-generations-from-efi-menu/17592/4
|
||||
|
||||
This is automated in [base.nix](modules/base.nix) with the `nix.gc` option.
|
||||
|
||||
Run manually for all profiles:
|
||||
|
||||
```shell
|
||||
sudo nix-collect-garbage --delete-older-than 14d
|
||||
```
|
||||
|
||||
Remove leftover EFI entries of removed generations:
|
||||
|
||||
```shell
|
||||
sudo /run/current-system/bin/switch-to-configuration boot
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user