File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44} :
55# Helper function to create a systemd service that configures *arr basic settings via API
66serviceName : serviceConfig :
7- with lib ; {
7+ with lib ; let
8+ mkWaitForApiScript = import ./mkWaitForApiScript.nix { inherit lib pkgs ; } ;
9+ capitalizedName = lib . toUpper ( builtins . substring 0 1 serviceName ) + builtins . substring 1 ( - 1 ) serviceName ;
10+ in {
811 description = "Configure ${ serviceName } via API" ;
912 after = [ "${ serviceName } .service" ] ;
1013 wantedBy = [ "multi-user.target" ] ;
1114
1215 serviceConfig = {
1316 Type = "oneshot" ;
1417 RemainAfterExit = true ;
18+ ExecStartPre = mkWaitForApiScript serviceName serviceConfig ;
1519 } ;
1620
17- script = let
18- capitalizedName = lib . toUpper ( builtins . substring 0 1 serviceName ) + builtins . substring 1 ( - 1 ) serviceName ;
19- in ''
21+ script = ''
2022 set -eu
2123
2224 # Read secrets
@@ -25,17 +27,6 @@ with lib; {
2527
2628 BASE_URL="http://127.0.0.1:${ builtins . toString serviceConfig . hostConfig . port } ${ serviceConfig . hostConfig . urlBase } /api/${ serviceConfig . apiVersion } "
2729
28- # Wait for API to be available (up to 60 seconds)
29- echo "Waiting for ${ capitalizedName } API to be available..."
30- for i in {1..60}; do
31- if ${ pkgs . curl } /bin/curl -s -f "$BASE_URL/system/status?apiKey=$API_KEY" >/dev/null 2>&1; then
32- echo "${ capitalizedName } API is available"
33- break
34- fi
35- echo "Waiting for ${ capitalizedName } API... ($i/60)"
36- sleep 1
37- done
38-
3930 # Get current host configuration
4031 echo "Fetching current host configuration..."
4132 HOST_CONFIG=$(${ pkgs . curl } /bin/curl -s -f -H "X-Api-Key: $API_KEY" "$BASE_URL/config/host" 2>/dev/null)
Original file line number Diff line number Diff line change 1+ {
2+ lib ,
3+ pkgs ,
4+ } :
5+ # Helper function to create a script that waits for an *arr service API to be ready
6+ serviceName : serviceConfig :
7+ pkgs . writeShellScript "${ serviceName } -wait-for-api" ( let
8+ capitalizedName = lib . toUpper ( builtins . substring 0 1 serviceName ) + builtins . substring 1 ( - 1 ) serviceName ;
9+ in ''
10+ API_KEY=$(cat ${ serviceConfig . apiKeyPath } )
11+ BASE_URL="http://127.0.0.1:${ builtins . toString serviceConfig . hostConfig . port } ${ serviceConfig . hostConfig . urlBase } /api/${ serviceConfig . apiVersion } "
12+
13+ echo "Waiting for ${ capitalizedName } API to be available..."
14+ for i in {1..60}; do
15+ if ${ pkgs . curl } /bin/curl -s -f "$BASE_URL/system/status?apiKey=$API_KEY" >/dev/null 2>&1; then
16+ echo "${ capitalizedName } API is available"
17+ exit 0
18+ fi
19+ echo "Waiting for ${ capitalizedName } API... ($i/60)"
20+ sleep 1
21+ done
22+
23+ echo "${ capitalizedName } API not available after 60 seconds" >&2
24+ exit 1
25+ '' )
Original file line number Diff line number Diff line change 44} :
55# Helper function to create a systemd service that configures *arr root folders via API
66serviceName : serviceConfig :
7- with lib ; {
7+ with lib ; let
8+ mkWaitForApiScript = import ./mkWaitForApiScript.nix { inherit lib pkgs ; } ;
9+ capitalizedName = lib . toUpper ( builtins . substring 0 1 serviceName ) + builtins . substring 1 ( - 1 ) serviceName ;
10+ in {
811 description = "Configure ${ serviceName } root folders via API" ;
912 after = [ "${ serviceName } -config.service" ] ;
1013 wantedBy = [ "multi-user.target" ] ;
1114
1215 serviceConfig = {
1316 Type = "oneshot" ;
1417 RemainAfterExit = true ;
18+ ExecStartPre = mkWaitForApiScript serviceName serviceConfig ;
1519 } ;
1620
17- script = let
18- capitalizedName = lib . toUpper ( builtins . substring 0 1 serviceName ) + builtins . substring 1 ( - 1 ) serviceName ;
19- in ''
21+ script = ''
2022 set -eu
2123
2224 # Read API key secret
2325 API_KEY=$(cat ${ serviceConfig . apiKeyPath } )
2426
2527 BASE_URL="http://127.0.0.1:${ builtins . toString serviceConfig . hostConfig . port } ${ serviceConfig . hostConfig . urlBase } /api/${ serviceConfig . apiVersion } "
2628
27- # Wait for API to be available (up to 60 seconds)
28- echo "Waiting for ${ capitalizedName } API to be available..."
29- for i in {1..60}; do
30- if ${ pkgs . curl } /bin/curl -sSf "$BASE_URL/system/status?apiKey=$API_KEY" >/dev/null 2>&1; then
31- echo "${ capitalizedName } API is available"
32- break
33- fi
34- echo "Waiting for ${ capitalizedName } API... ($i/60)"
35- sleep 1
36- done
37-
3829 # Create root folders if they don't exist
3930 echo "Checking for root folders..."
4031 ROOT_FOLDERS=$(${ pkgs . curl } /bin/curl -sSf -H "X-Api-Key: $API_KEY" "$BASE_URL/rootfolder" 2>/dev/null)
Original file line number Diff line number Diff line change 44} :
55# Helper function to create a systemd service that configures Prowlarr indexers via API
66serviceName : serviceConfig :
7- with lib ; {
7+ with lib ; let
8+ mkWaitForApiScript = import ../arr-common/mkWaitForApiScript.nix { inherit lib pkgs ; } ;
9+ capitalizedName = lib . toUpper ( builtins . substring 0 1 serviceName ) + builtins . substring 1 ( - 1 ) serviceName ;
10+ in {
811 description = "Configure ${ serviceName } indexers via API" ;
912 after = [ "${ serviceName } -config.service" ] ;
1013 requires = [ "${ serviceName } -config.service" ] ;
@@ -13,29 +16,17 @@ with lib; {
1316 serviceConfig = {
1417 Type = "oneshot" ;
1518 RemainAfterExit = true ;
19+ ExecStartPre = mkWaitForApiScript serviceName serviceConfig ;
1620 } ;
1721
18- script = let
19- capitalizedName = lib . toUpper ( builtins . substring 0 1 serviceName ) + builtins . substring 1 ( - 1 ) serviceName ;
20- in ''
22+ script = ''
2123 set -eu
2224
2325 # Read API key secret
2426 API_KEY=$(cat ${ serviceConfig . apiKeyPath } )
2527
2628 BASE_URL="http://127.0.0.1:${ builtins . toString serviceConfig . hostConfig . port } ${ serviceConfig . hostConfig . urlBase } /api/${ serviceConfig . apiVersion } "
2729
28- # Wait for API to be available (up to 60 seconds)
29- echo "Waiting for ${ capitalizedName } API to be available..."
30- for i in {1..60}; do
31- if ${ pkgs . curl } /bin/curl -sSf "$BASE_URL/system/status?apiKey=$API_KEY" >/dev/null 2>&1; then
32- echo "${ capitalizedName } API is available"
33- break
34- fi
35- echo "Waiting for ${ capitalizedName } API... ($i/60)"
36- sleep 1
37- done
38-
3930 # Fetch all indexer schemas
4031 echo "Fetching indexer schemas..."
4132 SCHEMAS=$(${ pkgs . curl } /bin/curl -sS -H "X-Api-Key: $API_KEY" "$BASE_URL/indexer/schema")
You can’t perform that action at this time.
0 commit comments