diff --git a/.gitignore b/.gitignore index b2be92b..4408f0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ result +.venv +config.json +uploaded-packs/images +downloads +.cache diff --git a/README.md b/README.md index b89c08e..a35acf0 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,6 @@ Here's an example of a stickerpicker myStickerPicker = createStickerPicker { homeserver = "https://my.matrix.server"; userId = "@stickerbot:my.matrix.server"; - # You should probably encrypt this with either agenix, sops-nix or whatever else - accessTokenFile = ./stickerbot_access_token.txt; sha256 = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; packs = [ { diff --git a/createStickerPicker.nix b/downloadStickers.nix similarity index 83% rename from createStickerPicker.nix rename to downloadStickers.nix index 3b3b170..fd5016a 100644 --- a/createStickerPicker.nix +++ b/downloadStickers.nix @@ -14,7 +14,6 @@ { homeserver ? "https://matrix.org", userId, - accessTokenFile, packs, hash ? "", sha256 ? "" @@ -44,14 +43,6 @@ else let (map (x: fetchers."${x.type}-deps")) builtins.concatLists ]; - - config-json = writeText "stickerpicker-config.json" '' - { - "homeserver": "${homeserver}", - "user_id": "${userId}", - "access_token": "${fileContents accessTokenFile}" - } - ''; in stdenvNoCC.mkDerivation { name = "stickerpicker"; src = maunium-stickerpicker; @@ -73,13 +64,11 @@ in stdenvNoCC.mkDerivation { buildPhase = '' mkdir images IMG_DIR="$(pwd)/images" - STICKERPACKS_DIR="$(pwd)/web/packs" - STICKER_CONFIG="${config-json}" ${stickerDownloadInstructions} ''; installPhase = '' - mv web $out + cp -r . $out ''; } diff --git a/fetchers.nix b/fetchers.nix index 22ca7e1..954743c 100644 --- a/fetchers.nix +++ b/fetchers.nix @@ -9,14 +9,6 @@ ${instructions} popd - - sticker-pack \ - --config "$STICKER_CONFIG" \ - --add-to-index "$STICKERPACKS_DIR" \ - --title '${title}' \ - '${dirname}' - - popd ''; in { directory-deps = [ ]; diff --git a/flake.lock b/flake.lock index 3395430..709af59 100644 --- a/flake.lock +++ b/flake.lock @@ -18,16 +18,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1672441588, - "narHash": "sha256-jx5kxOyeObnVD44HRebKYL3cjWrcKhhcDmEYm0/naDY=", + "lastModified": 1714253743, + "narHash": "sha256-mdTQw2XlariysyScCv2tTE45QSU9v/ezLcHJ22f0Nxc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "6a0d2701705c3cf6f42c15aa92b7885f1f8a477f", + "rev": "58a1abdbae3217ca6b702f03d3b35125d88a2994", "type": "github" }, "original": { "id": "nixpkgs", - "ref": "nixos-22.11", + "ref": "nixos-unstable", "type": "indirect" } }, diff --git a/flake.nix b/flake.nix index 2537bc3..5767d1d 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { inputs = { - nixpkgs.url = "nixpkgs/nixos-22.11"; + nixpkgs.url = "nixpkgs/nixos-unstable"; maunium-stickerpicker = { url = "github:maunium/stickerpicker"; @@ -12,15 +12,64 @@ system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; fetchers = pkgs.callPackage ./fetchers.nix { }; - createStickerPicker = pkgs.callPackage ./createStickerPicker.nix { + downloadStickers = pkgs.callPackage ./downloadStickers.nix { inherit maunium-stickerpicker fetchers; inherit (self.packages.${system}) stickerpicker-tools; }; in { - inherit createStickerPicker; + inherit downloadStickers; - packages.${system} = { + devShells.${system}.default = pkgs.mkShell { + name = "python-venv"; + + venvDir = "./.venv"; + + buildInputs = [ + pkgs.python3Packages.python + pkgs.python3Packages.venvShellHook + self.packages.${system}.stickerpicker-tools + self.packages.${system}.sigstickers + ]; + + postVenvCreation = '' + unset SOURCE_DATE_EPOCH + pip install -r requirements.txt + ''; + + postShellHook = '' + # allow pip to install wheels + unset SOURCE_DATE_EPOCH + ''; + }; + + packages.${system} = + let + signalstickers-client = (pkgs.python3Packages.callPackage ./python/signalstickers-client.nix {}); + in + { default = self.packages.${system}.stickerpicker-tools; + sigstickers = (pkgs.python3Packages.callPackage ./python/sigstickers.nix { inherit signalstickers-client; }); + + pub-solar-stickers = downloadStickers { + homeserver = "https://matrix.pub.solar"; + userId = "@hakkonaut:pub.solar"; + sha256 = "sha256-e5KNPhtrETzgcJxbVZtlWwBXK3RlNKXCZPPZ5Zk46ok="; + packs = [ + { + type = "chatsticker"; + name = "donald-and-friends"; + } + { + type = "chatsticker"; + name = "heartwarming-cat-world"; + } + { + type = "chatsticker"; + name = "kawaii-potato-1"; + } + ]; + }; + stickerpicker-tools = pkgs.python3Packages.buildPythonPackage { name = "stickerpicker-tools"; src = maunium-stickerpicker; diff --git a/python/signalstickers-client.nix b/python/signalstickers-client.nix new file mode 100644 index 0000000..b4ae38d --- /dev/null +++ b/python/signalstickers-client.nix @@ -0,0 +1,42 @@ +{ + buildPythonPackage, + fetchPypi, + setuptools, + anyio, + cryptography, + httpx, + protobuf, + pytest +}: +buildPythonPackage rec { + pname = "signalstickers-client"; + version = "3.3.0"; + src = fetchPypi { + pname = "signalstickers-client"; + inherit version; + sha256 = "sha256-5be/SdVhCH8lF2Vq2sJpt9R9htGO+wj+Q7Cp8S8NZXo="; + }; + propagatedBuildInputs = [ + anyio + cryptography + httpx + protobuf + setuptools + ]; + checkInputs = [ + pytest + anyio + httpx + protobuf + ]; + postPatch = '' + substituteInPlace setup.py \ + --replace 'protobuf>=3.13.0,<4.0.0' 'protobuf>=3.13' + substituteInPlace setup.py \ + --replace 'cryptography>=3.1.1,<4.0.0' 'cryptography' + substituteInPlace setup.py \ + --replace 'httpx>=0.16.1,<=0.24.1' 'httpx' + substituteInPlace setup.py \ + --replace 'anyio>=3.0.0,<4.0.0' 'anyio' + ''; +} diff --git a/python/sigstickers.nix b/python/sigstickers.nix new file mode 100644 index 0000000..25ecd72 --- /dev/null +++ b/python/sigstickers.nix @@ -0,0 +1,28 @@ +{ + buildPythonPackage, + fetchPypi, + setuptools, + emoji, + loguru, + pillow, + signalstickers-client +}: +buildPythonPackage rec { + pname = "sigstickers"; + version = "2024.1"; + src = fetchPypi { + pname = "sigstickers"; + inherit version; + sha256 = "sha256-hIfyQokEOzb1kkTIa8/ieCRNuLGUcMDhbIBSpvBVd9o="; + }; + propagatedBuildInputs = [ + setuptools + emoji + loguru + pillow + signalstickers-client + ]; + format = "pyproject"; + checkInputs = [ + ]; +}