diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6735ca6bb..724c9611e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -301,6 +301,22 @@ jobs: name: Twitch.Drops.Miner.Linux.AppImage-${{matrix.arch}} path: Twitch.Drops.Miner.Linux.AppImage-${{matrix.arch}}.zip + linux-nix: + name: Linux (Nix) + runs-on: ubuntu-latest + needs: + - validate + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Nix + uses: cachix/install-nix-action@v27 + + - name: Build Nix flake + run: nix build -L + update_releases_page: name: Upload builds to Releases if: github.event_name != 'pull_request' @@ -309,6 +325,7 @@ jobs: - linux-pyinstaller - linux-appimage - macos + - linux-nix runs-on: ubuntu-latest permissions: contents: write diff --git a/README.md b/README.md index 38589506e..d3063ae86 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,24 @@ Every several seconds, the application pretends to watch a particular stream by ### Usage: - Download and unzip [the latest release](https://github.com/DevilXD/TwitchDropsMiner/releases) - it's recommended to keep it in the folder it comes in. +- **Nix Users**: You can run the application directly from the flake using `nix run github:DevilXD/TwitchDropsMiner`, or add it to your NixOS/Home Manager configuration: +
+ Example Flake configuration + + ```nix + # flake.nix + inputs.TwitchDropsMiner = { + url = "github:DevilXD/TwitchDropsMiner"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + # configuration.nix / home.nix + environment.systemPackages = [ # or home.packages + inputs.TwitchDropsMiner.packages.${pkgs.stdenv.hostPlatform.system}.twitch-drops-miner + ]; + ``` + +
- Run it and login/connect the miner to your Twitch account by using the in-app login form. - After a successful login, the app should fetch a list of all available campaigns and games you can mine drops for - you can then select and add games of choice to the Priority List available on the Settings tab, and then press on the `Reload` button to start processing. It will fetch a list of all applicable streams it can watch, and start mining right away. You can also manually switch to a different channel as needed. - If you wish to keep the miner occupied with mining anything it can, beyond what you've selected via the Priority List, you can use the Priority Mode setting to specify the mining order for the rest of the games. diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..8be25e949 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1774709303, + "narHash": "sha256-D3Q07BbIA2KnTcSXIqqu9P586uWxN74zNoCH3h2ESHg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8110df5ad7abf5d4c0f6fb0f8f978390e77f9685", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..b4580c692 --- /dev/null +++ b/flake.nix @@ -0,0 +1,52 @@ +{ + description = "An app that allows you to AFK mine Twitch drops, without having to worry about switching channels or claiming drops"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = + { self, nixpkgs }: + let + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + pkgsFor = system: nixpkgs.legacyPackages.${system}; + in + { + packages = forAllSystems (system: { + default = (pkgsFor system).callPackage ./nix/package.nix { }; + twitch-drops-miner = (pkgsFor system).callPackage ./nix/package.nix { }; + }); + + apps = forAllSystems (system: { + default = { + type = "app"; + program = "${self.packages.${system}.default}/bin/twitch-drops-miner"; + }; + twitch-drops-miner = { + type = "app"; + program = "${self.packages.${system}.twitch-drops-miner}/bin/twitch-drops-miner"; + }; + }); + + devShells = forAllSystems ( + system: + let + pkgs = pkgsFor system; + in + { + default = pkgs.mkShell { + inputsFrom = [ self.packages.${system}.default ]; + + packages = with pkgs; [ + python3Packages.pytest + python3Packages.black + ]; + }; + } + ); + }; +} diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 000000000..36c01388a --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,107 @@ +{ + lib, + python3Packages, + wrapGAppsHook3, + gobject-introspection, + gtk3, + libnotify, + copyDesktopItems, + makeDesktopItem, +}: + +python3Packages.buildPythonApplication rec { + pname = "twitch-drops-miner"; + version = "15-dev"; + + # Use the local repository as the source + src = ../.; + + format = "other"; + + nativeBuildInputs = [ + wrapGAppsHook3 + gobject-introspection + copyDesktopItems + ]; + + buildInputs = [ + gtk3 + libnotify + ]; + + propagatedBuildInputs = with python3Packages; [ + aiohttp + pillow + pystray + pygobject3 + truststore + tkinter + ]; + + dontWrapGApps = true; + + # Patch the immutable path behavior for Linux + postPatch = '' + substituteInPlace constants.py \ + --replace-fail 'IS_PACKAGED = hasattr(sys, "_MEIPASS") or IS_APPIMAGE' 'IS_PACKAGED = True' \ + --replace-fail 'WORKING_DIR = SELF_PATH.parent' 'import os; WORKING_DIR = Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config"), "twitch-drops-miner"); WORKING_DIR.mkdir(parents=True, exist_ok=True)' + substituteInPlace utils.py \ + --replace-fail 'if IS_PACKAGED and sys.platform == "linux":' 'if False:' + ''; + + desktopItems = [ + (makeDesktopItem { + name = "twitch-drops-miner"; + exec = "twitch-drops-miner"; + icon = "twitch-drops-miner"; + desktopName = "Twitch Drops Miner"; + comment = "An app that allows you to AFK mine Twitch drops"; + categories = [ + "Utility" + "Network" + "Game" + ]; + }) + ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/share/twitch-drops-miner + cp -r * $out/share/twitch-drops-miner/ + + # Install icon + install -Dm644 appimage/pickaxe.png $out/share/icons/hicolor/256x256/apps/twitch-drops-miner.png + + # Create the executable wrapper + mkdir -p $out/bin + cat > $out/bin/twitch-drops-miner <