NixOS notes
Installation
Installed from the current iso:
nixos-gnome-23.11.5541.56528ee42526-x86_64-linux.iso
This does not enforce gnome. We can choose the desktop environment during the install. The installer includes partitioning. The alternative isos seem more limited.
A newer version will be available in May 2024 and it should be possible to switch to it via the setting system.autoUpgrade.channel or a suitable nix-channel --add command.
TODO: document this when done.
Problem with unstable
Changing to unstable to get plasma6 caused problems and failed rebuilds.
Rebuilding
nixos-rebuild switch
Removing old generations
In /nix/var/nix/profiles/ remove the unwanted symlinks, then run
nix --extra-experimental-features nix-command store gc
Then it may also be necessary to remove the corresponding boot loader entries in /boot/loader/entries.
Re-installing or installing on a different machine
The old /etc/nixos/configuration.nix can be dropped in to the new installation but we need to import the new hardware-configuration.nix.
Note that hardware-configuration.nix contains the partition layout.
Wireless
The relevant modules are blacklisted at the moment.
# cat /etc/nixos/networking/wireless-off.nix { config, pkgs, ... }: { boot.blacklistedKernelModules = [ "iwlwifi" "iwlmvm" ]; }
Autofs
# cat /etc/nixos/networking/autofs.nix { config, pkgs, ... }: { services.autofs.enable = true; services.autofs.autoMaster = let mapConf = pkgs.writeText "auto" '' isos -fstype=nfs4,ro teapot:/isos rmt -fstype=nfs4,ro rmt:/repo smt -fstype=nfs4,ro teapot:/repo ins -fstype=nfs,ro,nolock tigerlily:/ins tisos -fstype=nfs,ro,nolock tigerlily:/isos ''; in ''/autofs file:${mapConf}''; }
Problems
Getting openvpn to work
Using environment.etc to drop in
NetworkManager/system-connections/InfraVPN_Access_Corp_CZ.nmconnection
and then using nmcli failed for unclear reasons (apparently related to the bridged interface) with a message:
Error: Connection activation failed: Could not find source connection.
So we now have /etc/openvpn/openvpn.conf and dnsmasq for split DNS and scripts in /root/bin to start and stop the connection while replacing /etc/dnsmasq-conf.conf as needed.
Printing
Initially command line printing of pdf files did not work.
This was fixed by using
services.printing.drivers = [ pkgs.hplip ];
instead of
services.printing.drivers = [ pkgs.gutenprint ];
Fonts
It seems we need to deal with these separately from system packages:
fonts.packages = with pkgs; [ corefonts fantasque-sans-mono google-fonts libertine monaspace nika-fonts noto-fonts open-sans stix-two stix-otf ];
Cron
Using crontab -e as root sets up a cron job that seems to work, but this is not the NixOS way. Using services.cron.systemCronJobs seems to fail, and there are complaints online about this. See below.
Mplayer
After just installing Mplayer, we see
No such driver: v4l2
This comment shows how to fix it:
https://www.reddit.com/r/NixOS/comments/xx5za7/no_such_driver_v4l2/
We need:
nixpkgs.config = { packageOverrides = super: { mplayer = super.mplayer.override { v4lSupport = true; }; }; };
Systemd timers instead of cron
This works fine. Note that we need to source /etc/profile in the script section to make it work, otherwise the commands are not in the path.
[root@star:/etc/nixos]# cat run-config-backup.nix { config, pkgs, ... }: { systemd.timers."run-config-backup" = { wantedBy = [ "timers.target" ]; timerConfig = { OnCalendar="*-*-* 10:30:00"; Persistent = true; Unit = "run-config-backup.service"; }; }; systemd.services."run-config-backup" = { script = '' source /etc/profile DATE=$(date +%Y%m%d-%H%M) fdisk -l > /tmp/fdisk-l mount > /tmp/mount ssh root@tigerlily mkdir -p /install/backup/star/$DATE ssh root@tigerlily mkdir -p /install/backup/star/$DATE/etc rsync -avvL /etc/nixos root@tigerlily:/install/backup/star/$DATE/etc rsync -avv /root root@tigerlily:/install/backup/star/$DATE/ rsync -avv /tmp/fdisk-l /tmp/mount root@tigerlily:/install/backup/star/$DATE/ ''; serviceConfig = { Type = "oneshot"; User = "root"; }; }; }
User owned example:
[root@star:/etc/nixos]# cat run-upload-nixos-notes.nix { config, pkgs, ... }: { systemd.timers."run-upload-nixos-notes" = { wantedBy = [ "timers.target" ]; timerConfig = { OnCalendar="*-*-* 13:20:00"; Persistent = true; Unit = "run-upload-nixos-notes.service"; }; }; systemd.services."run-upload-nixos-notes" = { script = '' source /etc/profile rsync -a -e 'ssh -p 2122' /home/roger/nixos-notes/out/lwarp.css \ /home/roger/nixos-notes/out/index.html \ /home/roger/nixos-notes/out/notes.html \ roger@disruptive.org.uk:/home/roger/WEB/doc/nixos-notes/ ''; serviceConfig = { Type = "oneshot"; User = "roger"; }; }; }
Desktop
desktop.nix is a symlink to plasma5.nix and can be swapped out for xfce.nix or another desktop setup.
Python
See: https://wiki.nixos.org/wiki/Python – section “Using the Nixpkgs Python infrastructure”.
Example: put the following into a file named shell.nix in a directory and then run nix-shell.
let pkgs = import{}; in pkgs.mkShell { packages = [ (pkgs.python3.withPackages (python-pkgs: [ python-pkgs.pexpect ])) ]; }
The prompt will change to:
[nix-shell:~/test]$
and the python environment will be available.
rw 13-05-2024