Beginner questions: reboot, documentation and own scripts

Hi,

I am new to NixOS and have a few questions now:


  • I have activated the following:
    • system.autoUpgrade.enable = true;
    • How do I know now that I have to reboot, e.g. if the kernel is updated?
  • Is it possible that the documentation is not very up-to-date?
  • Where can I store my own scripts or programs, except ~/bin ?

Thanks!

Hello and welcome!

  • Autoupdate
    I don’t think there’s some official flag that you can check. However there’s a nice trick:
$ ls -l /run/{booted,current}-system/kernel*
lrwxrwxrwx  3 root root 64  1. Jan 1970  /run/booted-system/kernel -> /nix/store/ihxs96q4slbr0hz2gr2xh5yiiw2xhk2p-linux-5.1.14/bzImage
lrwxrwxrwx  2 root root 58  1. Jan 1970  /run/booted-system/kernel-modules -> /nix/store/iwrk0wgd7kdic6dzwfigd5242rx64dgj-kernel-modules
-r--r--r-- 12 root root 10  1. Jan 1970  /run/booted-system/kernel-params
lrwxrwxrwx  3 root root 64  1. Jan 1970  /run/current-system/kernel -> /nix/store/xzx90imganix9s9740c2iw3ak5wr90nq-linux-5.1.15/bzImage
lrwxrwxrwx  2 root root 58  1. Jan 1970  /run/current-system/kernel-modules -> /nix/store/vl7s989c9ch23dgx62mlpapbsf915mvp-kernel-modules
-r--r--r-- 12 root root 10  1. Jan 1970  /run/current-system/kernel-params

You can see that the links point to different images, which is an indication that the kernel has changed. This does not necessarily mean that the current-system/kernel is newer, but it’s a somewhat decent indicator.
Maybe someone else has another idea that I’ve overlooked so far.

  • The documentation
    That’s a good question. Some documentation is generated automatically, like the Options list (https://nixos.org/nixos/options.html) and the manpage for configuration.nix is pretty much guaranteed to be up to date.
    Comparing that with the NixOS manual (https://nixos.org/nixos/manual/) will show a huge difference. All that text doesn’t write itself, so if someone updates a module that’s mentioned in the manual, but forgets to update the manual for some reason… well, then you’ll get differences. It should still be pretty current, but it’s probably not impossible to find an older entry there. If you notice any, feel free to open an issue or maybe open a pull request on GitHub to fix it yourself.

  • Your own binaries
    The idea of NixOS is, that everything is declared in the configuration, so having your own ~/bin isn’t really the Nix way. It does work and you could even use /usr/local/bin if you really want to, but it doesn’t fit well.
    Probably the easiest way is to put them either in a local directory or some git repository that’s reachable and create your own small derivation that just copies the scripts to $out/bin. Then add that package to environment.systemPackages or to users.users.*.packages.
    Here’s an example package:

{ stdenv }:
stdenv.mkDerivation rec {
  name = "bin";
  src = ./bin;
  phases = [ "installPhase" "fixupPhase" ];
  installPhase = ''
    mkdir -p $out/bin
    cp -Rp $src/. $out/bin/
    '';
}

Store that for example as mybinaries.nix and put your scripts in a subdirectory bin in the same directory. Then add the following to environment.systemPackages:
(pkgs.callPackage ./pkgs/mybinaries.nix { })
so that your end result looks for example like this:

environment.systemPackages = with pkgs; [
  lftp
  htop
  (pkgs.callPackage ./pkgs/mybinaries.nix { })
  zip
];
3 Likes

Hello tokudan!

Thanks for your input!

The options list looks very good, you can easily get an overview. I will take a closer look at the code example.

So far NixOS makes a very good impression on me. Now I have the following up and running:

  • Nginx proxy
  • Let’s Encrypt
  • PostgreSQL
  • Gitea

Let’s see if I will replace my FreeBSD servers with NixOS. Need more testing… :smiley:

2 Likes

The next NixOS release will have the option to automatically reboot on a kernel change:

$ nixos-option system.autoUpgrade.allowReboot
Default:
false

Description:

"Reboot the system into the new generation instead of a switch if the new generation uses a different kernel, kernel modules\nor initrd than the booted system."

If you need it now, you can add something like this to your configuration.nix:

  disabledModules = [ "tasks/auto-upgrade.nix" ];
  imports = [ ./auto-upgrade.nix ]

and then put https://github.com/NixOS/nixpkgs/blob/3ac74e8a29464f43425427808b26eb26951ea755/nixos/modules/tasks/auto-upgrade.nix next to it.

1 Like