\(\newcommand{\footnotename}{footnote}\) \(\def \LWRfootnote {1}\) \(\newcommand {\footnote }[2][\LWRfootnote ]{{}^{\mathrm {#1}}}\) \(\newcommand {\footnotemark }[1][\LWRfootnote ]{{}^{\mathrm {#1}}}\) \(\let \LWRorighspace \hspace \) \(\renewcommand {\hspace }{\ifstar \LWRorighspace \LWRorighspace }\) \(\newcommand {\mathnormal }[1]{{#1}}\) \(\newcommand \ensuremath [1]{#1}\) \(\newcommand {\LWRframebox }[2][]{\fbox {#2}} \newcommand {\framebox }[1][]{\LWRframebox } \) \(\newcommand {\setlength }[2]{}\) \(\newcommand {\addtolength }[2]{}\) \(\newcommand {\setcounter }[2]{}\) \(\newcommand {\addtocounter }[2]{}\) \(\newcommand {\arabic }[1]{}\) \(\newcommand {\number }[1]{}\) \(\newcommand {\noalign }[1]{\text {#1}\notag \\}\) \(\newcommand {\cline }[1]{}\) \(\newcommand {\directlua }[1]{\text {(directlua)}}\) \(\newcommand {\luatexdirectlua }[1]{\text {(directlua)}}\) \(\newcommand {\protect }{}\) \(\def \LWRabsorbnumber #1 {}\) \(\def \LWRabsorbquotenumber "#1 {}\) \(\newcommand {\LWRabsorboption }[1][]{}\) \(\newcommand {\LWRabsorbtwooptions }[1][]{\LWRabsorboption }\) \(\def \mathchar {\ifnextchar "\LWRabsorbquotenumber \LWRabsorbnumber }\) \(\def \mathcode #1={\mathchar }\) \(\let \delcode \mathcode \) \(\let \delimiter \mathchar \) \(\def \oe {\unicode {x0153}}\) \(\def \OE {\unicode {x0152}}\) \(\def \ae {\unicode {x00E6}}\) \(\def \AE {\unicode {x00C6}}\) \(\def \aa {\unicode {x00E5}}\) \(\def \AA {\unicode {x00C5}}\) \(\def \o {\unicode {x00F8}}\) \(\def \O {\unicode {x00D8}}\) \(\def \l {\unicode {x0142}}\) \(\def \L {\unicode {x0141}}\) \(\def \ss {\unicode {x00DF}}\) \(\def \SS {\unicode {x1E9E}}\) \(\def \dag {\unicode {x2020}}\) \(\def \ddag {\unicode {x2021}}\) \(\def \P {\unicode {x00B6}}\) \(\def \copyright {\unicode {x00A9}}\) \(\def \pounds {\unicode {x00A3}}\) \(\let \LWRref \ref \) \(\renewcommand {\ref }{\ifstar \LWRref \LWRref }\) \( \newcommand {\multicolumn }[3]{#3}\) \(\require {textcomp}\) \(\newcommand {\intertext }[1]{\text {#1}\notag \\}\) \(\let \Hat \hat \) \(\let \Check \check \) \(\let \Tilde \tilde \) \(\let \Acute \acute \) \(\let \Grave \grave \) \(\let \Dot \dot \) \(\let \Ddot \ddot \) \(\let \Breve \breve \) \(\let \Bar \bar \) \(\let \Vec \vec \)

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.

Update

Switching to 2024.05 worked, but there were some problems and I decided to reinstall from the latest iso.

Problem with unstable under 23.11

Changing to unstable to get plasma6 caused problems and failed rebuilds. Now with 24.05 we have plasma6 without problems.

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

If we have

nix.extraOptions = ''
  experimental-features = nix-command
'';

the above command can be simplified to

nix store gc

Then it is also 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 ];

With 24.05, applications were defaulting to Letter size because of the contents of /etc/cups/ppd/hplj.ppd. This can be temporarily fixed via the cups web interface. The permanent fix is a timer that runs after boot:

[root@star:~]# cat /etc/nixos/run-fix-ppd.nix
{ config, pkgs, ... }:
{
    systemd.timers."run-fix-ppd" = {
         wantedBy = [ "timers.target" ];
         timerConfig = {
           OnBootSec="1min";
           Persistent=true;
           Unit = "run-fix-ppd.service";
         };
    };
    systemd.services."run-fix-ppd" = {
         script = ''
source /etc/profile
sed -i "s/: Letter/: A4/g" /etc/cups/ppd/hplj.ppd
'';
         serviceConfig = {
           Type = "oneshot";
           User = "root";
         };
    };
}

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
 ];

In a new installation corefonts can fail because it relies on downloading from third-party web locations.

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 plasma6.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.

Upgrade to 24.05
nix-channel --add https://channels.nixos.org/nixos-24.05 nixos
nixos-rebuild switch --upgrade

Problems

Needed to change

services.xserver.displayManager.sddm.enable = true;

to

services.displayManager.sddm.enable = true;

Needed to comments out corefonts, from-file.nix and hello.nix.

The firmware file for the scanner was no longer available at the URL stated.

Re-install

Bigger problem with from-file.nix because it was preventing garbage collection from happening due to first character being “.”.

Re-installed because this would have led to space problems over time.

Tried to manually adjust the database but failed.

rw 10-06-2024