autoupdates
This commit is contained in:
1 parent
6eb90819f0
commit
896d7480c1
7 files changed
+210
-12
No files matched your search
@@ -42,6 +42,7 @@
|
||||
|
||||
# Dockge container service group
|
||||
skyg.nixos.common.container-services.dockge = {
|
||||
enable = false;
|
||||
services.dockge = {
|
||||
image = "louislam/dockge:1";
|
||||
ports = [ "5001:5001" ];
|
||||
@@ -71,6 +72,71 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
skyg.nixos.common.container-services.jellyfin = {
|
||||
enable = true;
|
||||
autoUpdate.enable = true;
|
||||
services = {
|
||||
jellyfin = {
|
||||
image = "jellyfin/jellyfin";
|
||||
deploy = {
|
||||
resources = {
|
||||
reservations = {
|
||||
devices = [
|
||||
{
|
||||
driver = "cdi";
|
||||
device_ids = [ "nvidia.com/gpu=all" ];
|
||||
capabilities = [ "gpu" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
volumes = [
|
||||
"/opt/jellyfin:/mnt/apps/jellyfin"
|
||||
"torrents:/torrents"
|
||||
"family-videos:/family-videos"
|
||||
];
|
||||
devices = [ "/dev/dri:/dev/dri" ];
|
||||
restart = "always";
|
||||
healthcheck = {
|
||||
test = "curl --fail http://0.0.0.0:8096 || exit 1";
|
||||
interval = "60s";
|
||||
timeout = "20s";
|
||||
start_period = "30s";
|
||||
};
|
||||
environment = {
|
||||
JELLYFIN_DATA_DIR = "/mnt/apps/jellyfin/data";
|
||||
JELLYFIN_CACHE_DIR = "/mnt/apps/jellyfin/cache";
|
||||
JELLYFIN_CONFIG_DIR = "/mnt/apps/jellyfin/config";
|
||||
NVIDIA_VISIBLE_DEVICES = "all";
|
||||
};
|
||||
ports = [ "8096:8096" ];
|
||||
};
|
||||
};
|
||||
volumes = {
|
||||
torrents = {
|
||||
driver_opts = {
|
||||
"type" = "nfs";
|
||||
"o" = "addr=tnas1.lab.internal,nfsvers=4";
|
||||
"device" = ":/mnt/EightTerra/DownloadedTorrents";
|
||||
};
|
||||
};
|
||||
family-videos = {
|
||||
driver_opts = {
|
||||
"type" = "nfs";
|
||||
"o" = "addr=tnas1.lab.internal,nfsvers=4";
|
||||
"device" = ":/mnt/EightTerra/FamilyStorage/Video";
|
||||
};
|
||||
};
|
||||
jellyfin = {
|
||||
driver_opts = {
|
||||
"type" = "nfs";
|
||||
"o" = "addr=tnas1.lab.internal,nfsvers=4";
|
||||
"device" = ":/mnt/Data/apps/jellyfin";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
services.displayManager.defaultSession = "gnome";
|
||||
services.displayManager.gdm.enable = false;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
# Dockge container service group
|
||||
skyg.nixos.common.container-services.dockge = {
|
||||
enable = true;
|
||||
services.dockge = {
|
||||
image = "louislam/dockge:1";
|
||||
ports = [ "5001:5001" ];
|
||||
@@ -55,6 +56,8 @@
|
||||
|
||||
# Scrypted container service group
|
||||
skyg.nixos.common.container-services.scrypted = {
|
||||
enable = true;
|
||||
autoUpdate.enable = true;
|
||||
services.scrypted = {
|
||||
image = "ghcr.io/koush/scrypted";
|
||||
volumes = [
|
||||
@@ -81,7 +84,7 @@
|
||||
};
|
||||
};
|
||||
|
||||
# Scrypted backup & autoupdate timers
|
||||
# Scrypted backup timer (image auto-update handled by container-services autoUpdate)
|
||||
skyg.server.timers = {
|
||||
scrypted-backups = {
|
||||
OnCalendar = "daily";
|
||||
@@ -91,13 +94,5 @@
|
||||
${pkgs.rsync}/bin/rsync -avpzP --delete /opt/homelab/scrypted /homelab/terra1/Data/apps/
|
||||
'';
|
||||
};
|
||||
scrypted-autoupdate = {
|
||||
OnCalendar = "weekly";
|
||||
script = ''
|
||||
set -eu
|
||||
${pkgs.docker}/bin/docker pull ghcr.io/koush/scrypted
|
||||
systemctl restart container-services-scrypted.service
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -30,6 +30,15 @@ rec {
|
||||
// lib.optionalAttrs (svcCfg.dependsOn != [ ]) {
|
||||
depends_on = svcCfg.dependsOn;
|
||||
}
|
||||
// lib.optionalAttrs (svcCfg.devices != [ ]) {
|
||||
devices = svcCfg.devices;
|
||||
}
|
||||
// lib.optionalAttrs (svcCfg.healthcheck != { }) {
|
||||
healthcheck = svcCfg.healthcheck;
|
||||
}
|
||||
// lib.optionalAttrs (svcCfg.deploy != { }) {
|
||||
deploy = svcCfg.deploy;
|
||||
}
|
||||
// svcCfg.extraConfig;
|
||||
|
||||
# Build the full compose document attrset for a group.
|
||||
|
||||
@@ -12,8 +12,10 @@ let
|
||||
isDocker = containerLib.isDocker containersCfg.runtime;
|
||||
composeBin = containerLib.composeBin containersCfg.runtime;
|
||||
runtimeService = containerLib.runtimeService isDocker;
|
||||
runtimeBin = containerLib.runtimeBin isDocker;
|
||||
|
||||
enabledGroups = lib.filterAttrs (_: g: g.enable) cfg;
|
||||
autoUpdateGroups = lib.filterAttrs (_: g: g.autoUpdate.enable) enabledGroups;
|
||||
optionsModule = import ./options.nix { inherit lib; };
|
||||
|
||||
in
|
||||
@@ -74,7 +76,12 @@ in
|
||||
(lib.filterAttrs
|
||||
(_: grpCfg: filesLib.getAllFiles grpCfg != { })
|
||||
enabledGroups)
|
||||
);
|
||||
)
|
||||
// lib.mapAttrs'
|
||||
(groupName: grpCfg:
|
||||
let units = systemdLib.mkUpdateUnits groupName grpCfg composeBin runtimeBin;
|
||||
in lib.nameValuePair "container-services-${groupName}-update" units.services."container-services-${groupName}-update")
|
||||
autoUpdateGroups;
|
||||
|
||||
# Path units: one per group with env files
|
||||
systemd.paths =
|
||||
@@ -84,5 +91,13 @@ in
|
||||
systemdLib.mkPathUnit groupName (containerLib.getAllEnvFiles grpCfg))
|
||||
enabledGroups
|
||||
);
|
||||
|
||||
# Timers: one per group with autoUpdate enabled
|
||||
systemd.timers =
|
||||
lib.mapAttrs'
|
||||
(groupName: grpCfg:
|
||||
let units = systemdLib.mkUpdateUnits groupName grpCfg composeBin runtimeBin;
|
||||
in lib.nameValuePair "container-services-${groupName}-update" units.timers."container-services-${groupName}-update")
|
||||
autoUpdateGroups;
|
||||
};
|
||||
}
|
||||
@@ -18,6 +18,12 @@
|
||||
runtimeService = isDocker:
|
||||
if isDocker then "docker.service" else "podman.service";
|
||||
|
||||
# Runtime CLI binary (for operations without a compose equivalent, e.g. prune)
|
||||
runtimeBin = isDocker:
|
||||
if lib.hasAttrByPath [ "docker" ] pkgs
|
||||
then (if isDocker then "${pkgs.docker}/bin/docker" else "${pkgs.podman}/bin/podman")
|
||||
else (if isDocker then "docker" else "podman");
|
||||
|
||||
# Collect all env files from all services in a group
|
||||
getAllEnvFiles = grpCfg:
|
||||
lib.concatLists
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
type = lib.types.attrsOf (lib.types.submodule ({ name, ... }: {
|
||||
options = {
|
||||
|
||||
enable = lib.mkEnableOption "this container service group" // { default = true; };
|
||||
enable = lib.mkEnableOption "this container service group" // { default = false; };
|
||||
|
||||
stateDir = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
@@ -84,6 +84,36 @@
|
||||
description = "Sibling service names that must start first (compose depends_on:).";
|
||||
};
|
||||
|
||||
devices = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
example = [ "/dev/dri:/dev/dri" ];
|
||||
description = "Host device mappings in HOST:CONTAINER format (compose devices:).";
|
||||
};
|
||||
|
||||
healthcheck = lib.mkOption {
|
||||
type = lib.types.attrsOf lib.types.anything;
|
||||
default = { };
|
||||
example = {
|
||||
test = "curl --fail http://0.0.0.0:8096 || exit 1";
|
||||
interval = "60s";
|
||||
timeout = "20s";
|
||||
start_period = "30s";
|
||||
};
|
||||
description = "Container healthcheck definition (compose healthcheck:).";
|
||||
};
|
||||
|
||||
deploy = lib.mkOption {
|
||||
type = lib.types.attrsOf lib.types.anything;
|
||||
default = { };
|
||||
example = {
|
||||
resources.reservations.devices = [
|
||||
{ driver = "cdi"; device_ids = [ "nvidia.com/gpu=all" ]; }
|
||||
];
|
||||
};
|
||||
description = "Deploy block (compose deploy:), e.g. GPU device reservations.";
|
||||
};
|
||||
|
||||
restart = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "unless-stopped";
|
||||
@@ -117,7 +147,7 @@
|
||||
description = ''
|
||||
Free-form attrset merged directly into the compose service
|
||||
block. Use this for keys not modelled above:
|
||||
shm_size, cap_add, devices, healthcheck, etc.
|
||||
shm_size, cap_add, ulimits, etc.
|
||||
'';
|
||||
};
|
||||
|
||||
@@ -156,6 +186,48 @@
|
||||
'';
|
||||
};
|
||||
|
||||
autoUpdate = lib.mkOption {
|
||||
description = ''
|
||||
Scheduled image pull + recreate for this group. When enabled, a
|
||||
systemd timer periodically runs 'compose pull' followed by
|
||||
'compose up -d', so containers whose image changed are recreated.
|
||||
'';
|
||||
default = { };
|
||||
type = lib.types.submodule {
|
||||
options = {
|
||||
enable = lib.mkEnableOption "scheduled image pull + recreate for this group";
|
||||
|
||||
onCalendar = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "weekly";
|
||||
example = "Sun 04:00";
|
||||
description = "systemd OnCalendar expression controlling update frequency.";
|
||||
};
|
||||
|
||||
randomizedDelaySec = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 3600;
|
||||
description = ''
|
||||
Random delay (seconds) added to each trigger, to spread load
|
||||
across groups/hosts (systemd RandomizedDelaySec).
|
||||
'';
|
||||
};
|
||||
|
||||
persistent = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = "Run a missed update on next boot (systemd Persistent).";
|
||||
};
|
||||
|
||||
pruneImages = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "Run 'image prune -f' after updating to reclaim dangling images.";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
extraConfig = lib.mkOption {
|
||||
type = lib.types.attrsOf lib.types.anything;
|
||||
default = { };
|
||||
|
||||
@@ -24,6 +24,41 @@
|
||||
};
|
||||
};
|
||||
|
||||
# Create the update service + timer for a group's autoUpdate config.
|
||||
mkUpdateUnits = groupName: grpCfg: composeBin: runtimeBin:
|
||||
let
|
||||
auCfg = grpCfg.autoUpdate;
|
||||
stateDir = grpCfg.stateDir;
|
||||
unitName = "container-services-${groupName}-update";
|
||||
composeCmd = "${composeBin} -p ${groupName} -f ${stateDir}/compose.yml";
|
||||
in
|
||||
{
|
||||
services."${unitName}" = {
|
||||
description = "Pull latest images and recreate container service group '${groupName}'";
|
||||
after = [ "container-services-${groupName}.service" ];
|
||||
requires = [ "container-services-${groupName}.service" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart =
|
||||
[
|
||||
"${composeCmd} pull"
|
||||
"${composeCmd} up -d --remove-orphans"
|
||||
]
|
||||
++ lib.optional auCfg.pruneImages "${runtimeBin} image prune -f";
|
||||
};
|
||||
};
|
||||
timers."${unitName}" = {
|
||||
description = "Scheduled image update for container service group '${groupName}'";
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnCalendar = auCfg.onCalendar;
|
||||
RandomizedDelaySec = auCfg.randomizedDelaySec;
|
||||
Persistent = auCfg.persistent;
|
||||
Unit = "${unitName}.service";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# Create a path unit that watches env files for changes.
|
||||
mkPathUnit = groupName: envFiles:
|
||||
lib.optionalAttrs (envFiles != [ ]) {
|
||||
|
||||
Reference in new issue
Block a user