anchor.diff:      }];
   
       system.autoUpgrade.flags = (if cfg.flake == null then
  -        [ "--no-build-output" ] ++ (if cfg.channel == null then
  -          [ "--upgrade" ]
  -        else [
  +        [ "--no-build-output" ] ++ optionals (cfg.channel != null) [
             "-I"
             "nixpkgs=${cfg.channel}/nixexprs.tar.xz"
  -        ])
  +        ]
         else
           [ "--flake ${cfg.flake}" ]);
   
  
positive.code:   };
  
  }
  
negative.code:       ];
  
        script = let
          nixos-rebuild = "${config.system.build.nixos-rebuild}/bin/nixos-rebuild";
          date     = "${pkgs.coreutils}/bin/date";
          readlink = "${pkgs.coreutils}/bin/readlink";
          shutdown = "${pkgs.systemd}/bin/shutdown";
          upgradeFlag = optional (cfg.channel == null) "--upgrade";
        in if cfg.allowReboot then ''
          ${nixos-rebuild} boot ${toString (cfg.flags ++ upgradeFlag)}
          booted="$(${readlink} /run/booted-system/{initrd,kernel,kernel-modules})"
          built="$(${readlink} /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})"
  
          ${optionalString (cfg.rebootWindow != null) ''
            current_time="$(${date} +%H:%M)"
  
            lower="${cfg.rebootWindow.lower}"
            upper="${cfg.rebootWindow.upper}"
  
            if [[ "''${lower}" < "''${upper}" ]]; then
              if [[ "''${current_time}" > "''${lower}" ]] && \
                 [[ "''${current_time}" < "''${upper}" ]]; then
                do_reboot="true"
              else
                do_reboot="false"
              fi
            else
              # lower > upper, so we are crossing midnight (e.g. lower=23h, upper=6h)
              # we want to reboot if cur > 23h or cur < 6h
              if [[ "''${current_time}" < "''${upper}" ]] || \
                 [[ "''${current_time}" > "''${lower}" ]]; then
                do_reboot="true"
              else
                do_reboot="false"
              fi
            fi
          ''}
  
          if [ "''${booted}" = "''${built}" ]; then
            ${nixos-rebuild} switch ${toString cfg.flags}
          ${optionalString (cfg.rebootWindow != null) ''
            elif [ "''${do_reboot}" != true ]; then
              echo "Outside of configured reboot window, skipping."
          ''}
          else
            ${shutdown} -r +1
          fi
        '' else ''
          ${nixos-rebuild} switch ${toString (cfg.flags ++ upgradeFlag)}
        '';
  
        startAt = cfg.dates;
  