-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3862,6 +3862,12 @@ | |
githubId = 6608071; | ||
name = "Charles Huyghues-Despointes"; | ||
}; | ||
charludo = { | ||
email = "[email protected]"; | ||
github = "charludo"; | ||
githubId = 47758554; | ||
name = "Charlotte Harludo"; | ||
}; | ||
chayleaf = { | ||
email = "[email protected]"; | ||
github = "chayleaf"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
{ | ||
config, | ||
pkgs, | ||
lib, | ||
... | ||
}: | ||
|
||
with lib; | ||
|
||
let | ||
cfg = config.services.pinchflat; | ||
in | ||
{ | ||
options = { | ||
services.pinchflat = { | ||
enable = mkEnableOption "pinchflat"; | ||
|
||
dataDir = mkOption { | ||
type = types.str; | ||
default = "/var/lib/pinchflat"; | ||
description = "The directory where Pinchflat stores its config and database."; | ||
}; | ||
|
||
mediaDir = mkOption { | ||
type = types.str; | ||
default = "/var/lib/pinchflat/media"; | ||
description = "The directory into which Pinchflat downloads videos."; | ||
}; | ||
|
||
port = mkOption { | ||
type = types.port; | ||
default = 8945; | ||
description = "Port on which Pinchflat should listen."; | ||
}; | ||
|
||
openFirewall = mkOption { | ||
type = types.bool; | ||
default = false; | ||
description = "Open ports in the firewall for the Pinchflat web interface"; | ||
}; | ||
|
||
user = mkOption { | ||
type = types.str; | ||
default = "pinchflat"; | ||
description = "User account under which Pinchflat runs."; | ||
}; | ||
|
||
group = mkOption { | ||
type = types.str; | ||
default = "pinchflat"; | ||
description = "Group under which Pinchflat runs."; | ||
}; | ||
|
||
extraConfig = lib.mkOption { | ||
type = | ||
with lib.types; | ||
attrsOf ( | ||
nullOr (oneOf [ | ||
bool | ||
int | ||
str | ||
]) | ||
); | ||
default = { }; | ||
example = lib.literalExpression '' | ||
{ | ||
LOG_LEVEL = "info"; | ||
} | ||
''; | ||
description = '' | ||
The configuration of Pinchflat is handled through environment variables. | ||
The available configuration options can be found in [the Pinchflat README](https://github.com/kieraneglin/pinchflat/README.md#environment-variables). | ||
''; | ||
}; | ||
|
||
secretsFile = lib.mkOption { | ||
type = with lib.types; nullOr path; | ||
example = "/run/secrets/pinchflat"; | ||
description = '' | ||
Secrets like {env}`SECRET_KEY_BASE` and {env}`BASIC_AUTH_PASSWORD` | ||
should be passed to the service without adding them to the world-readable Nix store. | ||
Note that this file needs to be available on the host on which `pinchflat` is running. | ||
Further, `SECRET_KEY_BASE` has a minimum length requirement of 64 bytes. | ||
As an example, the contents of the file might look like this: | ||
``` | ||
SECRET_KEY_BASE=...copy-paste a secret token here... | ||
BASIC_AUTH_USERNAME=...basic auth username... | ||
BASIC_AUTH_PASSWORD=...basic auth password... | ||
``` | ||
''; | ||
}; | ||
|
||
package = mkPackageOption pkgs "pinchflat" { }; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
systemd.services.pinchflat = { | ||
description = "pinchflat"; | ||
after = [ "network.target" ]; | ||
wantedBy = [ "multi-user.target" ]; | ||
path = [ | ||
pkgs.apprise | ||
pkgs.yt-dlp | ||
]; | ||
|
||
serviceConfig = { | ||
Type = "simple"; | ||
User = cfg.user; | ||
Group = cfg.group; | ||
Environment = [ | ||
"PORT=${builtins.toString cfg.port}" | ||
"TZ=${config.time.timeZone}" | ||
"MEDIA_PATH=${cfg.mediaDir}" | ||
"CONFIG_PATH=${cfg.dataDir}" | ||
"DATABASE_PATH=${cfg.dataDir}/db/pinchflat.db" | ||
"LOG_PATH=${cfg.dataDir}/logs/pinchflat.log" | ||
"METADATA_PATH=${cfg.dataDir}/metadata" | ||
"EXTRAS_PATH=${cfg.dataDir}/extras" | ||
"TMPFILE_PATH=${cfg.dataDir}/tmp" | ||
"TZ_DATA_PATH=${cfg.dataDir}/extras/elixir_tz_data" | ||
"PHX_SERVER=true" | ||
] ++ lib.attrValues (lib.mapAttrs (name: value: name + "=" + lib.toString value) cfg.extraConfig); | ||
EnvironmentFile = lib.optional (cfg.secretsFile != null) cfg.secretsFile; | ||
ExecStartPre = "${cfg.package}/bin/migrate"; | ||
ExecStart = "${cfg.package}/bin/pinchflat start"; | ||
Restart = "on-failure"; | ||
}; | ||
}; | ||
|
||
networking.firewall = mkIf cfg.openFirewall { | ||
allowedTCPPorts = [ cfg.port ]; | ||
}; | ||
|
||
users.users = mkIf (cfg.user == "pinchflat") { | ||
pinchflat = { | ||
group = cfg.group; | ||
home = cfg.dataDir; | ||
createHome = true; | ||
uid = config.ids.uids.pinchflat; | ||
}; | ||
}; | ||
|
||
users.groups = mkIf (cfg.group == "pinchflat") { | ||
pinchflat.gid = config.ids.gids.pinchflat; | ||
}; | ||
}; | ||
} |
Oops, something went wrong.