nixos-upgrade: Add extraCommands option #1

Merged
batteredbunny merged 3 commits from extraCommands into main 2024-05-25 01:51:43 +03:00
5 changed files with 76 additions and 58 deletions

View file

@ -29,6 +29,8 @@ Adds a few new options to ``system.autoUpgrade``
``failureNotification`` sends a notification to a ntfy topic on an auto upgrade failure ``failureNotification`` sends a notification to a ntfy topic on an auto upgrade failure
``extraCommands`` extra commands to run during auto upgrade
```nix ```nix
system.autoUpgrade = { system.autoUpgrade = {
enable = true; enable = true;

View file

@ -3,18 +3,21 @@
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
}; };
outputs = {nixpkgs, ...}: let outputs = { nixpkgs, ... }:
let
lib = nixpkgs.lib; lib = nixpkgs.lib;
# Stolen from https://github.com/divnix/digga/blob/main/src/importers.nix # Stolen from https://github.com/divnix/digga/blob/main/src/importers.nix
rakeLeaves = dirPath: let rakeLeaves = dirPath:
let
seive = file: type: seive = file: type:
# Only rake `.nix` files or directories # Only rake `.nix` files or directories
(type == "regular" && lib.hasSuffix ".nix" file) || (type == "directory"); (type == "regular" && lib.hasSuffix ".nix" file) || (type == "directory");
collect = file: type: { collect = file: type: {
name = lib.removeSuffix ".nix" file; name = lib.removeSuffix ".nix" file;
value = let value =
let
path = dirPath + "/${file}"; path = dirPath + "/${file}";
in in
if if
@ -28,7 +31,8 @@
files = lib.filterAttrs seive (builtins.readDir dirPath); files = lib.filterAttrs seive (builtins.readDir dirPath);
in in
lib.filterAttrs (n: v: v != { }) (lib.mapAttrs' collect files); lib.filterAttrs (n: v: v != { }) (lib.mapAttrs' collect files);
in { in
{
nixosModules = rakeLeaves ./modules; nixosModules = rakeLeaves ./modules;
}; };
} }

View file

@ -1,9 +1,9 @@
{ { config
config, , lib
lib, , pkgs
pkgs, , ...
... }:
}: let let
cfg = config.system.autoUpgrade; cfg = config.system.autoUpgrade;
updateScript = pkgs.writeShellApplication { updateScript = pkgs.writeShellApplication {
@ -15,26 +15,36 @@
cd ${cfg.flake} cd ${cfg.flake}
git pull git pull
nix flake update --commit-lock-file nix flake update --commit-lock-file
${cfg.extraCommands}
git push git push
''; '';
}; };
in { in
{
options.system.autoUpgrade = { options.system.autoUpgrade = {
# TODO: make sure flake is a local folder # TODO: make sure system.autoUpgrade.flake is a local folder
updateFlake = lib.mkOption { updateFlake = lib.mkOption {
default = false; default = false;
description = "Update lockfile of the flake."; description = "Update lockfile of the flake.";
example = true;
};
extraCommands = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = "Extra commands to run during upgrade";
}; };
failureNotification = { failureNotification = {
enable = lib.mkOption { enable = lib.mkOption {
default = false; default = false;
description = "Enable ntfy notification on upgrade failure."; description = "Enable ntfy notification on upgrade failure.";
example = true;
}; };
ntfyUrlFile = lib.mkOption { ntfyUrlFile = lib.mkOption {
type = lib.types.nullOr lib.types.path; type = lib.types.nullOr lib.types.path;
description = "Environment file containing NTFY_URL"; description = "Environment file containing NTFY_URL";
example = "/etc/secrets/failureNotification.env";
}; };
}; };
}; };

View file

@ -1,11 +1,12 @@
{ { config
config, , pkgs
pkgs, , lib
lib, , ...
... }:
}: let let
cfg = config.services.qbittorrent-nox; cfg = config.services.qbittorrent-nox;
in { in
{
options.services.qbittorrent-nox = { options.services.qbittorrent-nox = {
enable = lib.mkEnableOption "qbittorrent, BitTorrent client."; enable = lib.mkEnableOption "qbittorrent, BitTorrent client.";

View file

@ -1,11 +1,12 @@
{ { config
config, , lib
lib, , pkgs
pkgs, , ...
... }:
}: let let
cfg = config.services.unpackerr; cfg = config.services.unpackerr;
in { in
{
options.services.unpackerr = { options.services.unpackerr = {
enable = lib.mkEnableOption "unpackerr"; enable = lib.mkEnableOption "unpackerr";
package = lib.mkPackageOption pkgs "unpackerr" { }; package = lib.mkPackageOption pkgs "unpackerr" { };