Skip to content

Commit

Permalink
v0.1.0: interval option
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-gs committed Dec 29, 2023
1 parent 5c63420 commit 2a6ad29
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 130 deletions.
20 changes: 10 additions & 10 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

246 changes: 128 additions & 118 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,140 +1,150 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-23.05";
nixpkgs.url = "nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
sbt.url = "github:zaninime/sbt-derivation/master";
# recommended for first style of usage documented below, but not necessary
sbt.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = {
self,
nixpkgs,
sbt,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
in {
packages.default = import ./package.nix { pkgs = pkgs; sbt = sbt; self = self; };
#checks.build = self.packages.default;
}
) // {
outputs =
{ self
, nixpkgs
, sbt
, flake-utils
,
}:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
};
in
{
packages.default = import ./package.nix { pkgs = pkgs; sbt = sbt; self = self; };
#checks.build = self.packages.default;
}
) // {

nixosModules.photoprism-slideshow = { lib, pkgs, config, ... }:
let
cfg = config.services.photoprism-slideshow;
in
{
options = with lib; {
services.photoprism-slideshow = {
enable = mkOption {
type = types.bool;
default = false;
};
nixosModules.photoprism-slideshow = { lib, pkgs, config, ... }:
let
cfg = config.services.photoprism-slideshow;
in
{
options = with lib; {
services.photoprism-slideshow = {
enable = mkOption {
type = types.bool;
default = false;
};

preload = mkOption {
type = types.bool;
default = false;
};
preload = mkOption {
type = types.bool;
default = false;
};

port = mkOption {
type = types.int;
default = 23234;
};
port = mkOption {
type = types.int;
default = 23234;
};

database = mkOption {
type = types.str;
default = "/var/lib/photoprism/index.db";
};

basePath = mkOption {
type = types.str;
default = "/slideshow";
};

database = mkOption {
type = types.str;
default = "/var/lib/photoprism/index.db";
package = mkOption {
type = types.package;
default = self.outputs.packages."${pkgs.system}".default;
};

interval = mkOption {
type = types.int;
default = 10;
};
};
};

basePath = mkOption {
type = types.str;
default = "/slideshow";
};
config = with lib; mkIf cfg.enable {

package = mkOption {
type = types.package;
default = self.outputs.packages."${pkgs.system}".default;
};
};
};
systemd.services.photoprism-slideshow-reload = mkIf cfg.preload {
enable = true;
startAt = "*-*-* 01:34:00";
script = ''
${pkgs.systemd}/bin/systemctl restart photoprism-slideshow
'';
};

config = with lib; mkIf cfg.enable {

systemd.services.photoprism-slideshow-reload = mkIf cfg.preload {
enable = true;
startAt = "*-*-* 01:34:00";
script = ''
${pkgs.systemd}/bin/systemctl restart photoprism-slideshow
'';
};


systemd.services.photoprism-slideshow = {
enable = true;
path = [ ];
preStart = if cfg.preload then ''
cd /var/cache/photoprism-slideshow
[ -e photoprism-slideshow.db ] && rm -- photoprism-slideshow.db
${pkgs.sqlite}/bin/sqlite3 ${cfg.database} ".clone photoprism-slideshow.db"
'' else "";
environment = {
SERVER_PORT = toString cfg.port;
DATABASE = if cfg.preload then "/var/cache/photoprism-slideshow/photoprism-slideshow.db" else cfg.database;
BASE_PATH = cfg.basePath;
};
systemd.services.photoprism-slideshow = {
enable = true;
path = [ ];
preStart =
if cfg.preload then ''
cd /var/cache/photoprism-slideshow
[ -e photoprism-slideshow.db ] && rm -- photoprism-slideshow.db
${pkgs.sqlite}/bin/sqlite3 ${cfg.database} ".clone photoprism-slideshow.db"
'' else "";
environment = {
SERVER_PORT = toString cfg.port;
DATABASE = if cfg.preload then "/var/cache/photoprism-slideshow/photoprism-slideshow.db" else cfg.database;
BASE_PATH = cfg.basePath;
INTERVAL = cfg.interval;
};

script = ''
${cfg.package}/bin/photoprism-slideshow
'';
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
DynamicUser = true;
Restart = "on-failure";
CacheDirectory = "photoprism-slideshow";
# Hardening
CapabilityBoundingSet = "";
DeviceAllow = "";
DevicePolicy = "closed";
LockPersonality = true;
MemoryDenyWriteExecute = false;
NoNewPrivileges = true;
PrivateDevices = true;
PrivateUsers = true;
PrivateTmp = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectProc = "invisible";
ProcSubset = "pid";
ProtectSystem = "strict";
RemoveIPC = true;
RestrictAddressFamilies = [
"AF_INET"
"AF_INET6"
];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SupplementaryGroups = [];
SystemCallArchitectures = "native";
SystemCallFilter = [
"@system-service @pkey"
"~@privileged @resources"
];
UMask = "0077";
script = ''
${cfg.package}/bin/photoprism-slideshow
'';
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
DynamicUser = true;
Restart = "on-failure";
CacheDirectory = "photoprism-slideshow";
# Hardening
CapabilityBoundingSet = "";
DeviceAllow = "";
DevicePolicy = "closed";
LockPersonality = true;
MemoryDenyWriteExecute = false;
NoNewPrivileges = true;
PrivateDevices = true;
PrivateUsers = true;
PrivateTmp = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectProc = "invisible";
ProcSubset = "pid";
ProtectSystem = "strict";
RemoveIPC = true;
RestrictAddressFamilies = [
"AF_INET"
"AF_INET6"
];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SupplementaryGroups = [ ];
SystemCallArchitectures = "native";
SystemCallFilter = [
"@system-service @pkey"
"~@privileged @resources"
];
UMask = "0077";
};
};
};
};
};
};
};
}
2 changes: 1 addition & 1 deletion package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sbt.lib.mkSbtDerivation {
inherit pkgs;

pname = "photoprism-slideshow";
version = "0.0.1";
version = "0.1.0";

depsSha256 = "sha256-qwtUYKy51TFA/q/Yd2bwzrPSkA/Xjrsbb8ftQf/0PlM=";

Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/photoprism/slideshow/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ object PhotoprismSlideshowApp extends cask.MainRoutes{

val db = scala.util.Properties.envOrElse("DATABASE", "./index.db")
val basePath = scala.util.Properties.envOrElse("BASE_PATH", "")
val interval = scala.util.Properties.envOrElse("INTERVAL", "10").toInt

val ds: javax.sql.DataSource = {
val ds = org.sqlite.SQLiteDataSource()
Expand Down Expand Up @@ -57,7 +58,7 @@ object PhotoprismSlideshowApp extends cask.MainRoutes{
)
),
tag("script")(raw(s"""
var intervalID = window.setInterval(refreshImage, 10 * 1000);
var intervalID = window.setInterval(refreshImage, ${interval} * 1000);

function refreshImage() {
fetch('./photo/random/' + location.hash.substr(1))
Expand All @@ -69,6 +70,7 @@ object PhotoprismSlideshowApp extends cask.MainRoutes{

// Examine the text in the response
response.json().then(function(data) {
(new Image()).src = data.photo;
document.getElementById('title').innerText = data.title;
document.getElementsByTagName('title')[0].innerText = data.title;
document.getElementById('ts').innerText = data.taken_at;
Expand Down

0 comments on commit 2a6ad29

Please sign in to comment.