rename to ptouch-remote

This commit is contained in:
Robin Appelman 2025-10-28 19:25:09 +01:00
commit 1422f9b8be
12 changed files with 43 additions and 40 deletions

View file

@ -21,7 +21,7 @@ jobs:
mkdir assets mkdir assets
for asset in x86_64-unknown-linux-musl aarch64-unknown-linux-musl; do for asset in x86_64-unknown-linux-musl aarch64-unknown-linux-musl; do
nix build .#$asset nix build .#$asset
cp result/bin/ptouch-api assets/$asset cp result/bin/ptouch-remote assets/$asset
done done
- name: Create release - name: Create release
uses: https://code.forgejo.org/actions/forgejo-release@v2.6.0 uses: https://code.forgejo.org/actions/forgejo-release@v2.6.0

View file

@ -1 +1 @@
ENV{ID_VENDOR_ID}=="04f9", ENV{ID_MODEL_ID}=="2001|2004|2007|2011|2019|201f|202c|202d|2030|2031|2041|205e|205f|2061|2062|2064|2065|20df|2073|20e0|2074|20e1|20af|2201", MODE="0600" OWNER="ptouch-api" ENV{ID_VENDOR_ID}=="04f9", ENV{ID_MODEL_ID}=="2001|2004|2007|2011|2019|201f|202c|202d|2030|2031|2041|205e|205f|2061|2062|2064|2065|20df|2073|20e0|2074|20e1|20af|2201", MODE="0600" OWNER="ptouch-remote"

2
Cargo.lock generated
View file

@ -1212,7 +1212,7 @@ dependencies = [
] ]
[[package]] [[package]]
name = "ptouch-api" name = "ptouch-remote"
version = "0.1.1" version = "0.1.1"
dependencies = [ dependencies = [
"axum", "axum",

View file

@ -1,5 +1,5 @@
[package] [package]
name = "ptouch-api" name = "ptouch-remote"
version = "0.1.1" version = "0.1.1"
edition = "2024" edition = "2024"

View file

@ -1,11 +1,14 @@
# ptouch-api # ptouch-remote
Simple REST api for Brother P-touch label printers. Web interface and REST api for Brother P-touch label printers.
![ptouch remote screenshot](./images/light.png#gh-light-mode-only)
![ptouch remote screenshot](./images/dark.png#gh-dark-mode-only)
## Installation ## Installation
You can download pre-built binaries from the You can download pre-built binaries from the
[releases page](https://codeberg.org/icewind/ptouch-api/releases) or build it [releases page](https://codeberg.org/icewind/ptouch-remote/releases) or build it
yourself using `cargo build`. yourself using `cargo build`.
## Configuring ## Configuring
@ -16,7 +19,7 @@ yourself using `cargo build`.
# address = "0.0.0.0" # defaults to "127.0.0.1" # address = "0.0.0.0" # defaults to "127.0.0.1"
# port = 1234 # defaults to 7074 # port = 1234 # defaults to 7074
# you can set it to listen over a unix socket instead. # you can set it to listen over a unix socket instead.
socket = "/run/ptouch-api.sock" socket = "/run/ptouch-remote.sock"
``` ```
In additional to the `listen` configuration, the server will automatically In additional to the `listen` configuration, the server will automatically
@ -26,21 +29,21 @@ provided socket.
## Usage ## Usage
```bash ```bash
ptouch-api [--config config.toml] ptouch-remote [--config config.toml]
``` ```
## Permissions ## Permissions
You'll need to either run `ptouch-api` as root or setup a udev rule to change You'll need to either run `ptouch-remote` as root or setup a udev rule to change
the owner or permissions to allow `ptouch-api` to access the label printer over the owner or permissions to allow `ptouch-remote` to access the label printer over
usb. usb.
See [51-ptouch-api.rules](./51-ptouch-api.rules) for an example udev rule, See [51-ptouch-remote.rules](./51-ptouch-remote.rules) for an example udev rule,
placing this into `/etc/udev/rules.d` and adjusting the username as desired placing this into `/etc/udev/rules.d` and adjusting the username as desired
should give the specified user access to the ptouch printer. should give the specified user access to the ptouch printer.
Alternatively you can use Alternatively you can use
[51-ptouch-api-everyone.rules](./51-ptouch-api-everyone.rules) to give all users [51-ptouch-remote-everyone.rules](./51-ptouch-remote-everyone.rules) to give all users
on the system access to the label printer. on the system access to the label printer.
## API ## API
@ -97,24 +100,24 @@ needed run the api.
```nix ```nix
{ {
inputs.ptouch-api.url = "git+ssh://git@codeberg.org/icewind/ptouch-api.git"; inputs.ptouch-remote.url = "git+ssh://git@codeberg.org/icewind/ptouch-remote.git";
outputs = { self, nixpkgs, ptouch-api }: { outputs = { self, nixpkgs, ptouch-remote }: {
nixosConfigurations.my-machine = nixpkgs.lib.nixosSystem { nixosConfigurations.my-machine = nixpkgs.lib.nixosSystem {
modules = modules =
[ [
ptouch-api.nixosModules.default ptouch-remote.nixosModules.default
({config, ...}: { ({config, ...}: {
# enable the api service and setup the udev rules # enable the api service and setup the udev rules
services.ptouch-api = { services.ptouch-remote = {
enable = true; enable = true;
# socket = "/path/for/socket/to/listen"; # defaults to /run/ptouch-api/ptouch-api.sock # socket = "/path/for/socket/to/listen"; # defaults to /run/ptouch-remote/ptouch-remote.sock
}; };
# expose the api to the outside world # expose the api to the outside world
services.nginx = { services.nginx = {
virtualHosts."ptouch.example.com" = { virtualHosts."ptouch.example.com" = {
locations."/" = { locations."/" = {
proxyPass = "http://unix://${config.services.ptouch-api.socket}"; proxyPass = "http://unix://${config.services.ptouch-remote.socket}";
}; };
}; };
}; };

View file

@ -14,12 +14,12 @@
mill-scale ./. { mill-scale ./. {
withOverlays = [(import ./nix/overlay.nix)]; withOverlays = [(import ./nix/overlay.nix)];
extraPaths = [ extraPaths = [
./51-ptouch-api.rules ./51-ptouch-remote.rules
./web ./web
]; ];
packages = rec { packages = rec {
ptouch-api = pkgs: pkgs.ptouch-api; ptouch-remote = pkgs: pkgs.ptouch-remote;
}; };
crossTargets = [ crossTargets = [
@ -35,9 +35,9 @@
... ...
}: { }: {
imports = [./nix/module.nix]; imports = [./nix/module.nix];
config = lib.mkIf config.services.ptouch-api.enable { config = lib.mkIf config.services.ptouch-remote.enable {
nixpkgs.overlays = [outputs.overlays.default]; nixpkgs.overlays = [outputs.overlays.default];
services.ptouch-api.package = lib.mkDefault pkgs.ptouch-api; services.ptouch-remote.package = lib.mkDefault pkgs.ptouch-remote;
}; };
}; };
}; };

BIN
images/dark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
images/light.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View file

@ -5,14 +5,14 @@
... ...
}: }:
with lib; let with lib; let
cfg = config.services.ptouch-api; cfg = config.services.ptouch-remote;
in { in {
options.services.ptouch-api = { options.services.ptouch-remote = {
enable = mkEnableOption "Enables the ptouch-api service"; enable = mkEnableOption "Enables the ptouch-remote service";
socket = mkOption rec { socket = mkOption rec {
type = types.str; type = types.str;
default = "/run/ptouch-api/ptouch-api.sock"; default = "/run/ptouch-remote/ptouch-remote.sock";
description = "The socket to listen on"; description = "The socket to listen on";
}; };
@ -29,17 +29,17 @@ in {
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
users.users.ptouch-api = { users.users.ptouch-remote = {
isSystemUser = true; isSystemUser = true;
group = "ptouch-api"; group = "ptouch-remote";
}; };
users.groups.ptouch-api = {}; users.groups.ptouch-remote = {};
services.udev.packages = [cfg.package]; services.udev.packages = [cfg.package];
systemd.services.ptouch-api = { systemd.services.ptouch-remote = {
wants = ["ptouch-api.socket"]; wants = ["ptouch-remote.socket"];
after = ["ptouch-api.socket"]; after = ["ptouch-remote.socket"];
environment = { environment = {
RUST_LOG = cfg.logLevel; RUST_LOG = cfg.logLevel;
}; };
@ -47,7 +47,7 @@ in {
serviceConfig = { serviceConfig = {
Restart = "on-failure"; Restart = "on-failure";
ExecStart = getExe cfg.package; ExecStart = getExe cfg.package;
User = "ptouch-api"; User = "ptouch-remote";
PrivateUsers = true; PrivateUsers = true;
PrivateTmp = true; PrivateTmp = true;
ProtectSystem = "strict"; ProtectSystem = "strict";
@ -67,12 +67,12 @@ in {
RestrictRealtime = true; RestrictRealtime = true;
SystemCallFilter = ["~@reboot" "~@cpu-emulation" "~@obsolete" "~@debug" "~@swap" "~@clock" "~@module"]; SystemCallFilter = ["~@reboot" "~@cpu-emulation" "~@obsolete" "~@debug" "~@swap" "~@clock" "~@module"];
RestrictNamespaces = ["~cgroup"]; RestrictNamespaces = ["~cgroup"];
RuntimeDirectory = "ptouch-api"; RuntimeDirectory = "ptouch-remote";
UMask = "0007"; UMask = "0007";
}; };
}; };
systemd.sockets.ptouch-api = { systemd.sockets.ptouch-remote = {
enable = true; enable = true;
wantedBy = ["sockets.target"]; wantedBy = ["sockets.target"];

View file

@ -1,3 +1,3 @@
final: prev: { final: prev: {
ptouch-api = final.callPackage ./package.nix {}; ptouch-remote = final.callPackage ./package.nix {};
} }

View file

@ -9,7 +9,7 @@
version = (fromTOML (readFile ../Cargo.toml)).package.version; version = (fromTOML (readFile ../Cargo.toml)).package.version;
in in
rustPlatform.buildRustPackage rec { rustPlatform.buildRustPackage rec {
pname = "ptouch-api"; pname = "ptouch-remote";
inherit src version; inherit src version;
@ -19,8 +19,8 @@ in
postInstall = '' postInstall = ''
mkdir -p $out/lib/udev/rules.d/ mkdir -p $out/lib/udev/rules.d/
cp ./51-ptouch-api.rules $out/lib/udev/rules.d/ cp ./51-ptouch-remote.rules $out/lib/udev/rules.d/
''; '';
meta.mainProgram = "ptouch-api"; meta.mainProgram = "ptouch-remote";
} }