mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-26 08:53:21 +00:00
nixos/auto-upgrade: Format
This commit is contained in:
parent
4aa36568d4
commit
b9956ceb87
@ -1,7 +1,14 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
let cfg = config.system.autoUpgrade;
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.system.autoUpgrade;
|
||||
|
||||
in {
|
||||
in
|
||||
{
|
||||
|
||||
options = {
|
||||
|
||||
@ -19,7 +26,10 @@ in {
|
||||
};
|
||||
|
||||
operation = lib.mkOption {
|
||||
type = lib.types.enum ["switch" "boot"];
|
||||
type = lib.types.enum [
|
||||
"switch"
|
||||
"boot"
|
||||
];
|
||||
default = "switch";
|
||||
example = "boot";
|
||||
description = ''
|
||||
@ -125,8 +135,13 @@ in {
|
||||
The default value of `null` means that reboots are allowed at any time.
|
||||
'';
|
||||
default = null;
|
||||
example = { lower = "01:00"; upper = "05:00"; };
|
||||
type = with lib.types; nullOr (submodule {
|
||||
example = {
|
||||
lower = "01:00";
|
||||
upper = "05:00";
|
||||
};
|
||||
type =
|
||||
with lib.types;
|
||||
nullOr (submodule {
|
||||
options = {
|
||||
lower = lib.mkOption {
|
||||
description = "Lower limit of the reboot window";
|
||||
@ -165,20 +180,28 @@ in {
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
|
||||
assertions = [{
|
||||
assertions = [
|
||||
{
|
||||
assertion = !((cfg.channel != null) && (cfg.flake != null));
|
||||
message = ''
|
||||
The options 'system.autoUpgrade.channel' and 'system.autoUpgrade.flake' cannot both be set.
|
||||
'';
|
||||
}];
|
||||
}
|
||||
];
|
||||
|
||||
system.autoUpgrade.flags = (if cfg.flake == null then
|
||||
[ "--no-build-output" ] ++ lib.optionals (cfg.channel != null) [
|
||||
system.autoUpgrade.flags = (
|
||||
if cfg.flake == null then
|
||||
[ "--no-build-output" ]
|
||||
++ lib.optionals (cfg.channel != null) [
|
||||
"-I"
|
||||
"nixpkgs=${cfg.channel}/nixexprs.tar.xz"
|
||||
]
|
||||
else
|
||||
[ "--refresh" "--flake ${cfg.flake}" ]);
|
||||
[
|
||||
"--refresh"
|
||||
"--flake ${cfg.flake}"
|
||||
]
|
||||
);
|
||||
|
||||
systemd.services.nixos-upgrade = {
|
||||
description = "NixOS Upgrade";
|
||||
@ -188,10 +211,13 @@ in {
|
||||
|
||||
serviceConfig.Type = "oneshot";
|
||||
|
||||
environment = config.nix.envVars // {
|
||||
environment =
|
||||
config.nix.envVars
|
||||
// {
|
||||
inherit (config.environment.sessionVariables) NIX_PATH;
|
||||
HOME = "/root";
|
||||
} // config.networking.proxy.envVars;
|
||||
}
|
||||
// config.networking.proxy.envVars;
|
||||
|
||||
path = with pkgs; [
|
||||
coreutils
|
||||
@ -203,13 +229,16 @@ in {
|
||||
config.programs.ssh.package
|
||||
];
|
||||
|
||||
script = let
|
||||
script =
|
||||
let
|
||||
nixos-rebuild = "${config.system.build.nixos-rebuild}/bin/nixos-rebuild";
|
||||
date = "${pkgs.coreutils}/bin/date";
|
||||
readlink = "${pkgs.coreutils}/bin/readlink";
|
||||
shutdown = "${config.systemd.package}/bin/shutdown";
|
||||
upgradeFlag = lib.optional (cfg.channel == null) "--upgrade";
|
||||
in if cfg.allowReboot then ''
|
||||
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})"
|
||||
@ -248,7 +277,9 @@ in {
|
||||
else
|
||||
${shutdown} -r +1
|
||||
fi
|
||||
'' else ''
|
||||
''
|
||||
else
|
||||
''
|
||||
${nixos-rebuild} ${cfg.operation} ${toString (cfg.flags ++ upgradeFlag)}
|
||||
'';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user