Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 51 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,60 @@ on:
- main

jobs:
check:
prepare:
name: Find Checks 🔍
runs-on: ubuntu-latest
outputs:
checks: ${{ steps.checks.outputs.checks }}
steps:
- uses: actions/checkout@v4

- uses: DeterminateSystems/nix-installer-action@main
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixos-unstable

- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Setup Cachix
uses: cachix/cachix-action@v16
with:
name: kiriwalawren
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"

- name: Run flake checks
run: nix flake check --all-systems
- name: Find Checks 🔍
id: checks
run: |
nix eval --json '.#checks.x86_64-linux' --apply builtins.attrNames | perl -pe 's|(.*)|checks=\1|' >> $GITHUB_OUTPUT

checks:
name: ${{ matrix.check }}
needs: prepare
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
check: ${{ fromJSON(needs.prepare.outputs.checks) }}
steps:
- uses: actions/checkout@v4

- name: Install Nix
uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixos-unstable

- name: Setup Cachix
uses: cachix/cachix-action@v16
with:
name: kiriwalawren
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"

# Enable KVM for VM tests
- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Run Check 📋
run: |
nix build -L .#checks.x86_64-linux.${{ matrix.check }}
11 changes: 9 additions & 2 deletions .github/workflows/update-flake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: DeterminateSystems/nix-installer-action@main
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixos-unstable

- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Setup Cachix
uses: cachix/cachix-action@v16
with:
name: kiriwalawren
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"

- name: Update flake.lock
run: nix flake update
Expand Down
27 changes: 17 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,24 @@

checks = forAllSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
format = pkgs.runCommand "check-format" {} ''
${pkgs.alejandra}/bin/alejandra --check ${./.}
touch $out
'';
tests = import ./tests {
inherit system pkgs;
nixosModules = self.nixosModules.default;
};
in
{
format = pkgs.runCommand "check-format" {} ''
${pkgs.alejandra}/bin/alejandra --check ${./.}
touch $out
'';

statix = pkgs.runCommand "check-statix" {} ''
${pkgs.statix}/bin/statix check ${./.}
touch $out
'';
});
statix = pkgs.runCommand "check-statix" {} ''
${pkgs.statix}/bin/statix check ${./.}
touch $out
'';
}
// tests.vm-tests
// tests.unit-tests);

devShells = forAllSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};
Expand Down
14 changes: 1 addition & 13 deletions modules/arr-common/configModule.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extraConfigOptions: {lib}:
{lib}: extraConfigOptions:
with lib;
types.submodule {
options =
Expand All @@ -20,18 +20,6 @@ with lib;
default = {};
description = "Host configuration options that will be set via the API /config/host endpoint";
};

rootFolders = mkOption {
type = types.listOf types.attrs;
default = [];
description = ''
List of root folders to create via the API /rootfolder endpoint.
Each folder is an attribute set that will be converted to JSON and sent to the API.

For Sonarr/Radarr, a simple path is sufficient: {path = "/path/to/folder";}
For Lidarr, additional fields are required like defaultQualityProfileId, etc.
'';
};
}
// extraConfigOptions;
}
12 changes: 12 additions & 0 deletions modules/arr-common/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
config,
lib,
pkgs,
usesDynamicUser ? false,
...
}: {
arrConfigModule = import ./configModule.nix {inherit lib;};
mkArrHostConfigService = import ./hostConfigService.nix {inherit lib pkgs;};
mkArrRootFoldersService = import ./rootFoldersService.nix {inherit lib pkgs;};
mkArrServiceModule = import ../arr-common/mkArrServiceModule.nix {inherit config lib pkgs usesDynamicUser;};
}
21 changes: 6 additions & 15 deletions modules/arr-common/hostConfigService.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
}:
# Helper function to create a systemd service that configures *arr basic settings via API
serviceName: serviceConfig:
with lib; {
with lib; let
mkWaitForApiScript = import ./mkWaitForApiScript.nix {inherit lib pkgs;};
capitalizedName = lib.toUpper (builtins.substring 0 1 serviceName) + builtins.substring 1 (-1) serviceName;
in {
description = "Configure ${serviceName} via API";
after = ["${serviceName}.service"];
wantedBy = ["multi-user.target"];

serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStartPre = mkWaitForApiScript serviceName serviceConfig;
};

script = let
capitalizedName = lib.toUpper (builtins.substring 0 1 serviceName) + builtins.substring 1 (-1) serviceName;
in ''
script = ''
set -eu

# Read secrets
Expand All @@ -25,17 +27,6 @@ with lib; {

BASE_URL="http://127.0.0.1:${builtins.toString serviceConfig.hostConfig.port}${serviceConfig.hostConfig.urlBase}/api/${serviceConfig.apiVersion}"

# Wait for API to be available (up to 60 seconds)
echo "Waiting for ${capitalizedName} API to be available..."
for i in {1..60}; do
if ${pkgs.curl}/bin/curl -s -f "$BASE_URL/system/status?apiKey=$API_KEY" >/dev/null 2>&1; then
echo "${capitalizedName} API is available"
break
fi
echo "Waiting for ${capitalizedName} API... ($i/60)"
sleep 1
done

# Get current host configuration
echo "Fetching current host configuration..."
HOST_CONFIG=$(${pkgs.curl}/bin/curl -s -f -H "X-Api-Key: $API_KEY" "$BASE_URL/config/host" 2>/dev/null)
Expand Down
Loading