Skip to content

Commit 5629210

Browse files
committed
autoupgrade: expose computed enabled option
1 parent bd560d7 commit 5629210

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

hosts/framework/nixos/autoupgrade.nix

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
{ pkgs, lib, ... }:
1+
{
2+
pkgs,
3+
lib,
4+
config,
5+
...
6+
}:
27

38
{
49
my.system.autoUpgrade = {
@@ -7,7 +12,7 @@
712
flake = "github:LorenzBischof/nixfiles";
813
};
914

10-
systemd.services = {
15+
systemd.services = lib.mkIf config.my.system.autoUpgrade.enabled {
1116
nixos-upgrade = {
1217
onSuccess = [ "notify-upgrade-success.service" ];
1318
onFailure = [ "notify-upgrade-failure.service" ];

modules/nixos/autoupgrade.nix

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ in
1919
`nixos-rebuild switch` once a day.
2020
'';
2121
};
22+
enabled = lib.mkOption {
23+
type = lib.types.bool;
24+
readOnly = true;
25+
default = cfg.enable && (builtins.hasAttr "rev" inputs.self);
26+
description = ''
27+
Whether autoupgrade is actually enabled. This is true only when
28+
both `enable` is true and the system is running from a clean git revision.
29+
'';
30+
};
2231
operation = lib.mkOption {
2332
type = lib.types.enum [
2433
"switch"
@@ -108,7 +117,7 @@ in
108117
'';
109118
};
110119
};
111-
config = lib.mkIf (cfg.enable && (builtins.hasAttr "rev" inputs.self)) {
120+
config = lib.mkIf (cfg.enabled) {
112121
environment.etc.git-revision.text = inputs.self.rev;
113122

114123
system.autoUpgrade = {

0 commit comments

Comments
 (0)