nix-dotfiles/modules/flake-update-service.nix
Alice Huston b77a34415d
Add attic cache (#117)
* add attic

* change formatter to nixfmt-rfc-style

Signed-off-by: ahuston-0 <aliceghuston@gmail.com>

* update lock

Signed-off-by: ahuston-0 <aliceghuston@gmail.com>

* initial format

Signed-off-by: ahuston-0 <aliceghuston@gmail.com>

* move back to postgres

Signed-off-by: ahuston-0 <aliceghuston@gmail.com>

* fix attic

* fix signing key

* formatting

Signed-off-by: ahuston-0 <aliceghuston@gmail.com>

---------

Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
2024-03-24 13:08:42 -04:00

77 lines
2.0 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.autopull;
in
{
options = {
services.autopull = {
enable = lib.mkEnableOption "autopull";
name = lib.mkOption {
type = lib.types.str;
default = "dotfiles";
description = "A name for the service which needs to be pulled";
};
path = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = "Path that needs to be updated via git pull";
};
frequency = lib.mkOption {
type = lib.types.str;
description = "systemd-timer compatible time between pulls";
default = "1h";
};
ssh-key = lib.mkOption {
type = lib.types.str;
default = "";
description = "ssh-key used to pull the repository";
};
triggersRebuild = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether or not the rebuild service should be triggered after pulling. Note that system.autoUpgrade must be pointed at the same directory as this service if you'd like to use this option.";
};
};
};
config = lib.mkIf (cfg.enable && !(builtins.isNull cfg.path)) {
environment.systemPackages = [
pkgs.openssh
pkgs.git
];
systemd.services."autopull@${cfg.name}" = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
description = "Pull the latest data for ${cfg.name}";
environment = lib.mkIf (cfg.ssh-key != "") {
GIT_SSH_COMMAND = "${pkgs.openssh}/bin/ssh -i ${cfg.ssh-key} -o IdentitiesOnly=yes";
};
serviceConfig = {
Type = "oneshot";
User = "root";
WorkingDirectory = cfg.path;
ExecStart = "${pkgs.git}/bin/git pull --all";
};
};
systemd.timers."autopull@${cfg.name}" = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = cfg.frequency;
OnUnitActiveSec = cfg.frequency;
Unit = "autopull@${cfg.name}.service";
};
};
};
}