refactor: only download stickers with nix,
manually invoke sticker-pack from the devshell to upload stickers to matrix, to avoid leaking the access token from config.json to the nix store. Nixify SigStickers https://github.com/FHPythonUtils/SigStickers and dependency https://github.com/signalstickers/signalstickers-client to download Signal stickers
This commit is contained in:
parent
d441327099
commit
f19ee88860
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1 +1,6 @@
|
|||
result
|
||||
.venv
|
||||
config.json
|
||||
uploaded-packs/images
|
||||
downloads
|
||||
.cache
|
||||
|
|
|
@ -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 = [
|
||||
{
|
||||
|
|
|
@ -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
|
||||
'';
|
||||
}
|
|
@ -9,14 +9,6 @@
|
|||
${instructions}
|
||||
|
||||
popd
|
||||
|
||||
sticker-pack \
|
||||
--config "$STICKER_CONFIG" \
|
||||
--add-to-index "$STICKERPACKS_DIR" \
|
||||
--title '${title}' \
|
||||
'${dirname}'
|
||||
|
||||
popd
|
||||
'';
|
||||
in {
|
||||
directory-deps = [ ];
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
},
|
||||
|
|
57
flake.nix
57
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;
|
||||
|
|
42
python/signalstickers-client.nix
Normal file
42
python/signalstickers-client.nix
Normal file
|
@ -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'
|
||||
'';
|
||||
}
|
28
python/sigstickers.nix
Normal file
28
python/sigstickers.nix
Normal file
|
@ -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 = [
|
||||
];
|
||||
}
|
Loading…
Reference in a new issue