commit dee0348c05c5752795041e6c378acee90d389d8f Author: Adithya Nair Date: Sun Nov 3 19:11:03 2024 +0530 initial commit diff --git a/.forgejo/workflows/cachix.yaml b/.forgejo/workflows/cachix.yaml new file mode 100644 index 0000000..fa60945 --- /dev/null +++ b/.forgejo/workflows/cachix.yaml @@ -0,0 +1,60 @@ +name: Build and Push to Cachix +on: + push: + branches: + - main + workflow_run: + workflows: ['Update Inputs'] + types: [completed] + branches: + - main + workflow_dispatch: + +jobs: + publish-x86_64: + name: Push to Binary Cache (X86-64) + runs-on: x86_64-docker + container: + image: ghcr.io/catthehacker/ubuntu:act-22.04 + steps: + - uses: https://github.com/DeterminateSystems/nix-installer-action@main + with: + extra-conf: | + access-tokens = ${{ secrets.GH_PUBLIC_REPO_ACCESS_TOKEN }} + + - uses: https://github.com/DeterminateSystems/magic-nix-cache-action@main + + - uses: https://github.com/cachix/cachix-action@v15 + with: + name: ${{ vars.CACHIX_CACHE_NAME }} + authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} + + - uses: actions/checkout@v4 + + - name: Build and push flake output + run: | + nix build -L .#autobrr + + publish-aarch64: + name: Push to Binary Cache (aarch64) + runs-on: aarch64-docker + container: + image: ghcr.io/catthehacker/ubuntu:act-22.04 + steps: + - uses: https://github.com/DeterminateSystems/nix-installer-action@main + with: + extra-conf: | + access-tokens = ${{ secrets.GH_PUBLIC_REPO_ACCESS_TOKEN }} + + - uses: https://github.com/DeterminateSystems/magic-nix-cache-action@main + + - uses: https://github.com/cachix/cachix-action@v15 + with: + name: ${{ vars.CACHIX_CACHE_NAME }} + authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} + + - uses: actions/checkout@v4 + + - run: | + nix build -L .#autobrr + diff --git a/.forgejo/workflows/update-inputs.yml b/.forgejo/workflows/update-inputs.yml new file mode 100644 index 0000000..e8ff4d4 --- /dev/null +++ b/.forgejo/workflows/update-inputs.yml @@ -0,0 +1,30 @@ +name: Update Inputs + +on: + schedule: + - cron: "0 0 * * 5" + workflow_dispatch: + +jobs: + update-inputs: + runs-on: docker + container: + image: ghcr.io/catthehacker/ubuntu:act-22.04 + name: Update Inputs + steps: + - uses: actions/checkout@v4 + with: + token: ${{ github.token }} + ref: ${{ github.head_ref }} + - uses: https://github.com/cachix/install-nix-action@v27 + with: + nix_path: nixpkgs=channel:nixos-unstable + github_access_token: ${{ secrets.GH_PUBLIC_REPO_ACCESS_TOKEN }} + - name: Update inputs + run: | + nix flake update --access-tokens "github.com=${{ secrets.GH_PUBLIC_REPO_ACCESS_TOKEN }}" + - name: Commit changes + uses: https://github.com/EndBug/add-and-commit@v9 + with: + message: 'Actions: Update Inputs' + add: 'flake.lock' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fcfc4a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result* diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c357e5b --- /dev/null +++ b/flake.lock @@ -0,0 +1,62 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "ref": "main", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1730531603, + "narHash": "sha256-Dqg6si5CqIzm87sp57j5nTaeBbWhHFaVyG7V6L8k3lY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7ffd9ae656aec493492b44d0ddfb28e79a1ea25d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..aeb1c37 --- /dev/null +++ b/flake.nix @@ -0,0 +1,29 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils?ref=main"; + }; + outputs = { nixpkgs, flake-utils, ... }: + let + pkgs_x86_64-linux = import nixpkgs { + system = "x86_64-linux"; + }; + pkgs_aarch64-linux = import nixpkgs { + system = "aarch64-linux"; + }; + in + { + overlays.default = import ./overlay.nix; + packages.x86_64-linux.autobrr = pkgs_x86_64-linux.callPackage ./packages/autobrr { }; + packages.aarch64-linux.autobrr = pkgs_aarch64-linux.callPackage ./packages/autobrr { }; + } // flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + }; + in + { + formatter = pkgs.nixpkgs-fmt; + } + ); +} diff --git a/overlay.nix b/overlay.nix new file mode 100644 index 0000000..161d034 --- /dev/null +++ b/overlay.nix @@ -0,0 +1,3 @@ +final: prev: { + autobrr = prev.callPackage ./packages/autobrr { }; +} diff --git a/packages/autobrr/default.nix b/packages/autobrr/default.nix new file mode 100644 index 0000000..0564edc --- /dev/null +++ b/packages/autobrr/default.nix @@ -0,0 +1,28 @@ +{ lib +, buildGoModule +, fetchFromGitHub +, callPackage +, nodejs +, pnpm +}: +let + inherit (import ./sources.nix { inherit fetchFromGitHub; }) pname version src vendorHash; + web = callPackage ./web.nix { inherit nodejs pnpm fetchFromGitHub; }; +in +buildGoModule rec { + inherit pname version src vendorHash; + + ldflags = [ "-s" "-w" "-X main.commit=${src.rev}" "-X main.tag=${version}" ]; + + postPatch = '' + cp -r ${web}/share/autobrr-web/* web/dist/ + ''; + + meta = { + description = "Modern, easy to use download automation for torrents and usenet"; + homepage = "https://github.com/autobrr/autobrr"; + license = lib.licenses.gpl2Only; + maintainers = with lib.maintainers; [ adtya ]; + mainProgram = "autobrr"; + }; +} diff --git a/packages/autobrr/sources.nix b/packages/autobrr/sources.nix new file mode 100644 index 0000000..acd9630 --- /dev/null +++ b/packages/autobrr/sources.nix @@ -0,0 +1,15 @@ +{ fetchFromGitHub }: +rec { + pname = "autobrr"; + version = "1.48.0"; + src = fetchFromGitHub { + owner = "autobrr"; + repo = "autobrr"; + rev = "v${version}"; + hash = "sha256-aCIjdVSBxR2Uq96ZtKrU97LpzIR6Pcfv0vLJNCdRrC0="; + }; + + vendorHash = "sha256-C+SzLqdzOLp4BDwE097RtsrR34davPzylgWN3mMoGaU="; + pnpmDepsHash = "sha256-Fkr/VFTh7foQBKbw0C5oJLr3pFA1wdYNmjEsoCemJ/I="; +} + diff --git a/packages/autobrr/web.nix b/packages/autobrr/web.nix new file mode 100644 index 0000000..6e00a6b --- /dev/null +++ b/packages/autobrr/web.nix @@ -0,0 +1,40 @@ +{ stdenv, nodejs, pnpm, fetchFromGitHub }: + +let + inherit (import ./sources.nix { inherit fetchFromGitHub; }) pname version src pnpmDepsHash; +in +stdenv.mkDerivation (finalAttrs: { + pname = "${pname}-web"; + inherit src version; + + sourceRoot = "${finalAttrs.src.name}/web"; + + nativeBuildInputs = [ + nodejs + pnpm.configHook + ]; + + pnpmDeps = pnpm.fetchDeps { + inherit (finalAttrs) pname version src sourceRoot; + hash = pnpmDepsHash; + }; + + # postPatch = '' + #substituteInPlace ./vite.config.ts \ + # --replace 'outDir: "../internal/server/public_html"' 'outDir: "dist"' + #''; + + postBuild = '' + pnpm run build + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out/share + mv dist $out/share/autobrr-web + + runHook postInstall + ''; +}) +