Auto-upgrade with NixOS and NixOps

Published on 2.11.2016
Published in nixops nixos

Since the end of last year NixOS has an auto-upgrade feature. Some weeks ago I decided to move my server from an unstable version of NixOS to the latest stable version. That made it easier for me to activate the auto-upgrade feature. However the first time the auto-upgrade was triggered it failed, since I deploy my server with NixOps and therefore there the file /etc/nixos/configuration.nix does not exist.

Until I have a real fix for this problem I decided to live with the workaround of copying the configuration with NixOps to the server and to create a custom configuration.nix that wraps around the NixOps configuration of the server. This resulted in the following code in my server configuration:

system.autoUpgrade.enable = true; =; = pkgs.writeText "configuration.nix" ''
  all@{ lib, ... }: lib.filterAttrs (n: v: n != "deployment")
    ((import /etc/nixos/current/default.nix).server all)

system.activationScripts = {
  configuration = ''
    rm /etc/nixos/current/* #*/
    ln -s ${./.}/* /etc/nixos/current #*/

Here is the full configuration.

Leave a Reply


Kommentare für diesen Eintrag als RSS Feed
Anonymous on 8.11.2018 wrote Reply

Thanks for this! It's just what I needed!

Henri on 23.07.2020 wrote Reply

Thank you, that's a good idea, but it shouldn't go without saying that ${./.} will copy the working directory recursively into the world-readable Nix store. So one has to be wary that there are no secrets lying around anywhere.