mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 14:49:14 +00:00
nix: format with alejandra
This commit is contained in:
parent
d5cad148da
commit
95eb4b71e0
118 changed files with 1291 additions and 1703 deletions
|
|
@ -3,152 +3,135 @@
|
|||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
}: let
|
||||
cfg = config.services."autoupdate";
|
||||
in
|
||||
|
||||
{
|
||||
|
||||
options =
|
||||
let
|
||||
eachPathOption = {
|
||||
options = {
|
||||
enable = lib.mkOption {
|
||||
type = with lib.types; bool;
|
||||
description = "Whether to enable this rule";
|
||||
default = true;
|
||||
};
|
||||
startAt = lib.mkOption {
|
||||
type = with lib.types; listOf str;
|
||||
description = "When to update automatically";
|
||||
default = [ "wed,sat 02:00" ];
|
||||
};
|
||||
updateCommand = lib.mkOption {
|
||||
type = with lib.types; str;
|
||||
description = "Command to run to update inputs";
|
||||
};
|
||||
commitOptions = lib.mkOption {
|
||||
type = with lib.types; listOf str;
|
||||
description = "Arguments passed to `git commit'";
|
||||
default = [
|
||||
"--no-verify"
|
||||
"--no-gpg-sign"
|
||||
];
|
||||
};
|
||||
commitMessageCommand = lib.mkOption {
|
||||
type = with lib.types; nullOr str;
|
||||
description = "Optional command to run, which result will be written to the commit message";
|
||||
default = null;
|
||||
};
|
||||
path = lib.mkOption {
|
||||
type = with lib.types; str;
|
||||
description = "The path to be updated";
|
||||
};
|
||||
in {
|
||||
options = let
|
||||
eachPathOption = {
|
||||
options = {
|
||||
enable = lib.mkOption {
|
||||
type = with lib.types; bool;
|
||||
description = "Whether to enable this rule";
|
||||
default = true;
|
||||
};
|
||||
startAt = lib.mkOption {
|
||||
type = with lib.types; listOf str;
|
||||
description = "When to update automatically";
|
||||
default = ["wed,sat 02:00"];
|
||||
};
|
||||
updateCommand = lib.mkOption {
|
||||
type = with lib.types; str;
|
||||
description = "Command to run to update inputs";
|
||||
};
|
||||
commitOptions = lib.mkOption {
|
||||
type = with lib.types; listOf str;
|
||||
description = "Arguments passed to `git commit'";
|
||||
default = [
|
||||
"--no-verify"
|
||||
"--no-gpg-sign"
|
||||
];
|
||||
};
|
||||
commitMessageCommand = lib.mkOption {
|
||||
type = with lib.types; nullOr str;
|
||||
description = "Optional command to run, which result will be written to the commit message";
|
||||
default = null;
|
||||
};
|
||||
path = lib.mkOption {
|
||||
type = with lib.types; str;
|
||||
description = "The path to be updated";
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
|
||||
services."autoupdate" = {
|
||||
enable = lib.mkEnableOption "autoupdate";
|
||||
settings = lib.mkOption {
|
||||
type = with lib.types; attrsOf (submodule eachPathOption);
|
||||
description = "Paths to update";
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
|
||||
systemd.user.services =
|
||||
let
|
||||
toSystemdService =
|
||||
name:
|
||||
{
|
||||
path,
|
||||
enable,
|
||||
updateCommand,
|
||||
commitMessageCommand,
|
||||
commitOptions,
|
||||
...
|
||||
}:
|
||||
lib.nameValuePair "autoupdate-${name}" (
|
||||
lib.mkIf enable {
|
||||
Unit = {
|
||||
Description = "Automatically update ${name} flake inputs";
|
||||
After = [ "network.target" ];
|
||||
};
|
||||
|
||||
Install = {
|
||||
WantedBy = [ "multi-user.target" ];
|
||||
};
|
||||
|
||||
Service = {
|
||||
WorkingDirectory = path;
|
||||
ExecStart =
|
||||
let
|
||||
script = pkgs.writeShellApplication {
|
||||
name = "autoupdate";
|
||||
runtimeInputs = [
|
||||
pkgs.git
|
||||
pkgs.bash
|
||||
pkgs.uutils-coreutils-noprefix
|
||||
config.nix.package
|
||||
];
|
||||
text = ''
|
||||
${updateCommand}
|
||||
|
||||
${
|
||||
if (commitMessageCommand != null) then
|
||||
''
|
||||
changed="$(${commitMessageCommand})"
|
||||
''
|
||||
else
|
||||
''
|
||||
changed=""
|
||||
''
|
||||
}
|
||||
|
||||
git add .
|
||||
git commit ${builtins.concatStringsSep " " commitOptions} -m "$(
|
||||
cat <<-EOF
|
||||
nix: update inputs
|
||||
|
||||
$changed
|
||||
EOF
|
||||
)"
|
||||
'';
|
||||
};
|
||||
in
|
||||
"${lib.getExe script}";
|
||||
};
|
||||
}
|
||||
);
|
||||
in
|
||||
lib.mapAttrs' toSystemdService cfg.settings;
|
||||
|
||||
systemd.user.timers =
|
||||
let
|
||||
toSystemdTimer =
|
||||
name:
|
||||
{ enable, startAt, ... }:
|
||||
lib.nameValuePair "autoupdate-${name}" (
|
||||
lib.mkIf enable {
|
||||
Unit.Description = "Automatically update ${name} flake inputs";
|
||||
Timer = {
|
||||
OnCalendar = startAt;
|
||||
Persistent = true;
|
||||
};
|
||||
Install.WantedBy = [ "timers.target" ];
|
||||
}
|
||||
);
|
||||
in
|
||||
lib.mapAttrs' toSystemdTimer cfg.settings;
|
||||
|
||||
in {
|
||||
services."autoupdate" = {
|
||||
enable = lib.mkEnableOption "autoupdate";
|
||||
settings = lib.mkOption {
|
||||
type = with lib.types; attrsOf (submodule eachPathOption);
|
||||
description = "Paths to update";
|
||||
default = {};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
systemd.user.services = let
|
||||
toSystemdService = name: {
|
||||
path,
|
||||
enable,
|
||||
updateCommand,
|
||||
commitMessageCommand,
|
||||
commitOptions,
|
||||
...
|
||||
}:
|
||||
lib.nameValuePair "autoupdate-${name}" (
|
||||
lib.mkIf enable {
|
||||
Unit = {
|
||||
Description = "Automatically update ${name} flake inputs";
|
||||
After = ["network.target"];
|
||||
};
|
||||
|
||||
Install = {
|
||||
WantedBy = ["multi-user.target"];
|
||||
};
|
||||
|
||||
Service = {
|
||||
WorkingDirectory = path;
|
||||
ExecStart = let
|
||||
script = pkgs.writeShellApplication {
|
||||
name = "autoupdate";
|
||||
runtimeInputs = [
|
||||
pkgs.git
|
||||
pkgs.bash
|
||||
pkgs.uutils-coreutils-noprefix
|
||||
config.nix.package
|
||||
];
|
||||
text = ''
|
||||
${updateCommand}
|
||||
|
||||
${
|
||||
if (commitMessageCommand != null)
|
||||
then ''
|
||||
changed="$(${commitMessageCommand})"
|
||||
''
|
||||
else ''
|
||||
changed=""
|
||||
''
|
||||
}
|
||||
|
||||
git add .
|
||||
git commit ${builtins.concatStringsSep " " commitOptions} -m "$(
|
||||
cat <<-EOF
|
||||
nix: update inputs
|
||||
|
||||
$changed
|
||||
EOF
|
||||
)"
|
||||
'';
|
||||
};
|
||||
in "${lib.getExe script}";
|
||||
};
|
||||
}
|
||||
);
|
||||
in
|
||||
lib.mapAttrs' toSystemdService cfg.settings;
|
||||
|
||||
systemd.user.timers = let
|
||||
toSystemdTimer = name: {
|
||||
enable,
|
||||
startAt,
|
||||
...
|
||||
}:
|
||||
lib.nameValuePair "autoupdate-${name}" (
|
||||
lib.mkIf enable {
|
||||
Unit.Description = "Automatically update ${name} flake inputs";
|
||||
Timer = {
|
||||
OnCalendar = startAt;
|
||||
Persistent = true;
|
||||
};
|
||||
Install.WantedBy = ["timers.target"];
|
||||
}
|
||||
);
|
||||
in
|
||||
lib.mapAttrs' toSystemdTimer cfg.settings;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue