-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5761aba
Showing
19 changed files
with
1,572 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
result |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
[![built with nix](https://builtwithnix.org/badge.svg)](https://builtwithnix.org) | ||
|
||
# maunium-stickerpicker-nix | ||
|
||
A nix module for [maunium/stickerpicker][maunium-stickerpicker] | ||
|
||
This module hosts one or more stickerpicker instances together with a mock homeserver that hosts the stickerpacks. | ||
The mock server will respond to the relevant matrix endpoints that retrieves mxc urls for the stickers. | ||
Unlike the upstream project, the stickers are never uploaded to the real homeserver, but are instead served from this mock server. | ||
The build steps for the stickerpicker are ignored, and the sticker index is generated using nix and used as a replacement. | ||
|
||
## Usage: | ||
|
||
Here's an example instance of the stickerpicker, using the nixos module: | ||
|
||
```nix | ||
services.maunium-stickerpicker = { | ||
enable = true; | ||
instances."my-sticker-picker" = { | ||
realMatrixDomain = "matrix.myserver.com"; | ||
# This creates a virtualhost in nginx, and will by default request Let's Encrypt certificates | ||
# Feel free to override the virtualHost configuration to your liking | ||
stickerMatrixDomain = "matrix-stickerpacks.myserver.com"; | ||
stickerPacks = [ | ||
{ | ||
id = "stickerpack1"; | ||
title = "Stickerpack 1"; | ||
stickers = [ | ||
{ | ||
id = "sticker1"; | ||
title = "Sticker 1"; | ||
path = ./stickers/stickerpack1/sticker1.png; | ||
} | ||
{ | ||
id = "sticker2"; | ||
title = "Sticker 2"; | ||
path = ./stickers/stickerpack1/sticker2.png; | ||
} | ||
{ | ||
id = "moving-sticker"; | ||
title = "Moving Sticker"; | ||
path = ./stickers/stickerpack1/moving-sticker.gif; | ||
} | ||
{ | ||
id = "single-remote-sticker"; | ||
title = "Single Remote Sticker"; | ||
url = "https://example.com/sticker.png"; | ||
hash = "sha256-AAAAAA..."; | ||
} | ||
]; | ||
} | ||
{ | ||
id = "stickerpack2"; | ||
title = "Stickerpack 2"; | ||
stickers = let | ||
jsonFile = pkgs.writeText "stickerpack2.json" '' | ||
[ | ||
{ "url": "https://example.com/sticker1.png" }, | ||
{ "url": "https://example.com/sticker2.jpg" } | ||
] | ||
''; | ||
in jsonFile; | ||
hash = "sha256-AAAAAA..."; | ||
outputType = "png"; | ||
} | ||
]; | ||
}; | ||
}; | ||
``` | ||
|
||
[maunium-stickerpicker]: https://github.com/maunium/stickerpicker |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
inputs = { | ||
nixpkgs.url = "nixpkgs/nixos-24.05"; | ||
|
||
mauniumStickerpicker = { | ||
url = "github:maunium/stickerpicker"; | ||
flake = false; | ||
}; | ||
}; | ||
|
||
outputs = { self, nixpkgs, mauniumStickerpicker }: let | ||
system = "x86_64-linux"; | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
in { | ||
pipes = { | ||
assignIds = pkgs.callPackage ./src/pipes/assignIds.nix { }; | ||
assignTitles = pkgs.callPackage ./src/pipes/assignTitles.nix { }; | ||
autoFetcher = pkgs.callPackage ./src/pipes/autoFetcher.nix { }; | ||
imagemagickConverter = pkgs.callPackage ./src/pipes/imagemagickConverter.nix { }; | ||
mediainfoExtractor = pkgs.callPackage ./src/pipes/mediainfoExtractor.nix { }; | ||
generateStickerpack = pkgs.callPackage ./src/pipes/generateStickerpack.nix { }; | ||
prefixIdsWithPackId = pkgs.callPackage ./src/pipes/prefixIdsWithPackId.nix { }; | ||
}; | ||
|
||
legacyPackages.generateStickerpicker = pkgs.callPackage ./src/generateStickerpicker.nix { | ||
inherit (self) pipes; | ||
inherit mauniumStickerpicker; | ||
}; | ||
|
||
packages.${system} = { | ||
default = self.packages.${system}.stickerpicker-tools; | ||
stickerpicker-tools = pkgs.callPackage ./src/pkgs/stickerpicker-tools.nix { | ||
inherit mauniumStickerpicker; | ||
}; | ||
}; | ||
|
||
|
||
docs = let | ||
inherit (pkgs) lib; | ||
|
||
scrubbedPkgsModule = { | ||
imports = [{ | ||
_module.args = { | ||
pkgs = pkgs; | ||
pkgs_i686 = lib.mkForce { }; | ||
}; | ||
}]; | ||
}; | ||
|
||
dontCheckDefinitions = { _module.check = false; }; | ||
|
||
options = builtins.removeAttrs ((lib.evalModules { | ||
modules = [ | ||
scrubbedPkgsModule | ||
dontCheckDefinitions | ||
self.nixosModules.default | ||
]; | ||
}).options) ["_module"]; | ||
|
||
in | ||
pkgs.nixosOptionsDoc { | ||
inherit options; | ||
}; | ||
|
||
nixosModules.default = import ./src/module.nix { inherit (self.legacyPackages) generateStickerpicker; }; | ||
|
||
tests = import ./tests { | ||
inherit nixpkgs pkgs; | ||
inherit (pkgs) lib; | ||
inherit (self.legacyPackages) generateStickerpicker; | ||
inherit (self.pipes) assignIds assignTitles autoFetcher imagemagickConverter mediainfoExtractor generateStickerpack; | ||
nixosModule = self.nixosModules.default; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{ pkgs, lib, stdenvNoCC, mauniumStickerpicker, pipes }: | ||
{ | ||
instanceName, # str | ||
stickerMatrixDomain, # str | ||
realMatrixDomain, # str | ||
stickerPacks, # listOf { title: str, id: str, stickers: see module.nix, } | ||
... | ||
}: let | ||
inherit (pkgs.callPackage ./utils.nix { }) withDefaultAttr; | ||
applyStickerPipe = pipe: editArgs: stickerPacks: | ||
map (pack: pack // { stickers = pipe (editArgs pack); }) stickerPacks; | ||
|
||
# packsWithIds :: listOf ({ title: str, id: str, stickers: attrs }}) | ||
packsWithIds = lib.pipe stickerPacks (with pipes; [ | ||
(applyStickerPipe assignIds (pack: pack)) | ||
(applyStickerPipe prefixIdsWithPackId (pack: pack)) | ||
]); | ||
|
||
# processedPacks :: listOf ({ title: str, id: str, stickers: attrs }}) | ||
preProcessedPacks = lib.pipe packsWithIds (with pipes; [ | ||
(applyStickerPipe assignTitles (pack: pack // { titlePrefix = pack.title; })) | ||
(applyStickerPipe autoFetcher (pack: pack)) # Guaranteed "path" | ||
(applyStickerPipe imagemagickConverter (pack: pack)) | ||
(applyStickerPipe mediainfoExtractor (pack: pack)) | ||
(map (pack: withDefaultAttr "title" pack.id pack)) | ||
]); | ||
|
||
# processedPacks :: listOf ({ title: str, id: str, stickers: attrs }}) | ||
processedPacks = | ||
applyStickerPipe pipes.generateStickerpack (pack: { | ||
inherit (pack) stickers id title; | ||
domain = stickerMatrixDomain; | ||
}) preProcessedPacks; | ||
|
||
# environmentSafeNames :: attrsOf str | ||
environmentSafeNames = let | ||
mapAttrVals = f: builtins.mapAttrs (_: f); | ||
in lib.pipe packsWithIds [ | ||
(map (pack: lib.nameValuePair pack.id pack.id)) | ||
builtins.listToAttrs | ||
# NOTE: Yeah, this is lossy, but I don't think it's a problem at the momemt. | ||
# It's an internal detail and won't be exposed in the resulting realized | ||
# derivaiton, so it can be changed later without any harm. | ||
(mapAttrVals (i: builtins.replaceStrings ["-" "."] ["_" "_"] i)) | ||
(mapAttrVals lib.toUpper) | ||
]; | ||
|
||
# finalPacks :: attrsOf (listOf attrs) | ||
finalPacks = lib.pipe processedPacks [ | ||
(map (pack: pack // { stickers = builtins.toJSON pack.stickers; })) | ||
(map (pack: lib.nameValuePair environmentSafeNames.${pack.id} pack.stickers)) | ||
builtins.listToAttrs | ||
]; | ||
|
||
# stickerpackIndex :: str | ||
stickerpackIndex = lib.pipe packsWithIds [ | ||
(map (pack: "${pack.id}.json")) | ||
(packs: { | ||
inherit packs; | ||
homeserver_url = "https://${realMatrixDomain}"; | ||
}) | ||
builtins.toJSON | ||
]; | ||
|
||
# moveStickerpackIndexCommands :: str | ||
moveStickerpackIndexCommands = lib.pipe environmentSafeNames [ | ||
(lib.mapAttrsToList (name: value: ''mv ''$${value}Path $out/packs/${name}.json'')) | ||
(builtins.concatStringsSep "\n") | ||
]; | ||
in | ||
stdenvNoCC.mkDerivation ({ | ||
name = "maunium-stickerpicker-${instanceName}"; | ||
src = mauniumStickerpicker; | ||
|
||
dontBuild = true; | ||
|
||
"INDEX_JSON" = stickerpackIndex; | ||
passAsFile = [ "INDEX_JSON" ] ++ (builtins.attrValues environmentSafeNames); | ||
|
||
passthru.stickerPacks = preProcessedPacks; | ||
|
||
installPhase = '' | ||
cp -r web $out | ||
cp $INDEX_JSONPath $out/packs/index.json | ||
${moveStickerpackIndexCommands} | ||
''; | ||
} // finalPacks) |
Oops, something went wrong.