all repos — nixfiles @ 5fdc1a576d0b039e65f8d9238ec34950c5019f55

System and user configuration, managed by nix and home-manager

system/settings/configuration/auto-upgrade.nix (view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{
  config,
  lib,
  pkgs,
  ...
}:
let
  nixfiles = "${config.users.users.alin.home}/projects/alin.ovh/nixfiles";
in
{
  systemd.services.update-nixfiles = {
    startAt = config.system.autoUpgrade.dates;
    wantedBy = [ "nixos-upgrade.service" ];
    path = [ config.programs.git.package ];
    serviceConfig = {
      Type = "oneshot";
      User = "alin";
      WorkingDirectory = "-${nixfiles}";
    };
    script = ''
      if [ ! -d "${nixfiles}" ]
      then
        mkdir -p "${nixfiles}"
        cd "${nixfiles}"
        git clone git+ssh://gitolite@git.alin.ovh/nixfiles .
      else
        git checkout -- flake.lock
        git pull --recurse-submodules=yes
      fi
    '';
  };

  systemd.services.home-manager-update = {
    enable = lib.mkDefault false;
    startAt = "weekly";
    wants = [ "update-nixfiles.service" ];
    path = with pkgs; [
      openssh
      nix
      config.programs.git.package
    ];
    serviceConfig = rec {
      Type = "oneshot";
      User = "alin";
      WorkingDirectory = nixfiles;
      ExecStart = "${lib.getExe pkgs.nh} home switch --file . homeConfigurations.${User}@%H --no-nom";
    };
  };

  system.autoUpgrade = {
    enable = true;
    allowReboot = true;

    dates = "02:10";
    randomizedDelaySec = "59 min";
    rebootWindow = lib.mkDefault {
      lower = "01:00";
      upper = "06:00";
    };

    flake = "${nixfiles}?submodules=1";
    upgrade = false;
  };
}