Nixos-upgrade.service doesn't work with flakes because '--update-input' flag is deprecated

Hello,

I’m trying to setup autoUpgrade with flakes enabled. Here is my autoUpgrade configuration :

  system.autoUpgrade = {
   enable = true;
   flake = inputs.self.outPath;
   flags = [
     "--update-input"
     "nixpkgs"
     "--commit-lock-file" # commit the lock file
     "-L" # print build logs
   ];
   operation = "boot"; 
   dates = "00:00";
   randomizedDelaySec = "45min";
   # Do not try to upgrade early to compensate
   # a missed reboot
   persistent = false;
   # Do not allow reboots, we are not switching anyway
   allowReboot = false;
   };

The system builds successfully. I wanted to make sure everything worked properly so I ran systemctl start nixos-update.service.

It fails, and the log indicates :

error: unrecognised flag '--update-input'
Try 'nix --help' for more information.

Indeed, (as I’m typing this message, I realize this) the option is deprecated since Nix 2.19 (https://nix.dev/manual/nix/2.22/release-notes/rl-2.19)

Is there any way to migrate this configuration to something that works similarly ?

Thanks

I setup a separate service to update the the flake.

{
  pkgs,
  ...
}: let
  user = "firecat53";
  flakePath = "/home/${user}/nixos/nixos";
in {
  ## Update flake inputs daily
  systemd.services = {
    flake-update = {
      preStart = "${pkgs.host}/bin/host firecat53.net";  # Check network connectivity
      unitConfig = {
        Description = "Update flake inputs";
        StartLimitIntervalSec = 300;
        StartLimitBurst = 5;
      };
      serviceConfig = {
        ExecStart = "${pkgs.nix}/bin/nix flake update --commit-lock-file ${flakePath}";
        Restart = "on-failure";
        RestartSec = "30";
        Type = "oneshot"; # Ensure that it finishes before starting nixos-upgrade
        User = "${user}";
      };
      before = ["nixos-upgrade.service"];
      path = [pkgs.nix pkgs.git pkgs.host];
    };
  };
}

Here’s the autoUpgrade config along with an additional service to restart the update if the network isn’t up yet after the laptop wakes up.

system.autoUpgrade = {
    enable = true;
    flake = "${flakePath}#${config.networking.hostName}";
    flags = [
      "-L"
    ];
    dates = "04:40";
    persistent = true;
    randomizedDelaySec = "45min";
  };
  # Allow nixos-upgrade to restart on failure (e.g. when laptop wakes up before network connection is set)
  systemd.services.nixos-upgrade = {
    preStart = "${pkgs.host}/bin/host firecat53.net";  # Check network connectivity
    serviceConfig = {
      Restart = "on-failure";
      RestartSec = "120";
    };
    unitConfig = {
      StartLimitIntervalSec = 600;
      StartLimitBurst = 2;
    };
    after = ["flake-update.service"];
    wants = ["flake-update.service"];
    path = [pkgs.host];
  };

Hope that helps!

1 Like

Hi folks, it’s nice to know about this. My system runs on the stable branch while I get everything else from the unstable release channel, so I believe that’s why I haven’t encountered this issue yet.

Did you know about GitHub - viperML/nh: Yet another nix cli helper? I absolutely love nh. I have been using it extensively for the last month and a half, to the point that I have forgotten almost completely about the native upgrade method.

The best part is that it has its very own set of options, so it may be worth a shot in your case:

On my side, I’m grabbing these two ones for myself, @sobornost:

   # Do not try to upgrade early to compensate
   # a missed rebo, ot
   persistent = false;
   # Do not allow reboots, we are not switching anyway
   allowReboot = false;

HTH :slight_smile: