diff --git a/.gitignore b/.gitignore index 1d082b3..a27f459 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -target/ -result -result-* +remote/target +pi/pi-service/target .direnv diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index d393826..0000000 --- a/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[workspace] -members = [ - "pi/pi-service", - "remote/noisebell-common", - "remote/cache-service", - "remote/discord-bot", - "remote/rss-service", -] -resolver = "2" diff --git a/flake.lock b/flake.lock index 40cda20..8ec41ab 100644 --- a/flake.lock +++ b/flake.lock @@ -25,11 +25,26 @@ }, "crane": { "locked": { - "lastModified": 1773857772, - "narHash": "sha256-5xsK26KRHf0WytBtsBnQYC/lTWDhQuT57HJ7SzuqZcM=", + "lastModified": 1773189535, + "narHash": "sha256-E1G/Or6MWeP+L6mpQ0iTFLpzSzlpGrITfU2220Gq47g=", "owner": "ipetkov", "repo": "crane", - "rev": "b556d7bbae5ff86e378451511873dfd07e4504cd", + "rev": "6fa2fb4cf4a89ba49fc9dd5a3eb6cde99d388269", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "crane_2": { + "locked": { + "lastModified": 1773115265, + "narHash": "sha256-5fDkKTYEgue2klksd52WvcXfZdY1EIlbk0QggAwpFog=", + "owner": "ipetkov", + "repo": "crane", + "rev": "27711550d109bf6236478dc9f53b9e29c1a374c5", "type": "github" }, "original": { @@ -97,26 +112,98 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1773646010, + "narHash": "sha256-iYrs97hS7p5u4lQzuNWzuALGIOdkPXvjz7bviiBjUu8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5b2c2d84341b2afb5647081c1386a80d7a8d8605", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pi-service": { + "inputs": { + "crane": "crane", + "nixpkgs": "nixpkgs_2", + "rust-overlay": "rust-overlay" + }, + "locked": { + "path": "./pi/pi-service", + "type": "path" + }, + "original": { + "path": "./pi/pi-service", + "type": "path" + }, + "parent": [] + }, + "remote": { + "inputs": { + "crane": "crane_2", + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": "rust-overlay_2" + }, + "locked": { + "path": "./remote", + "type": "path" + }, + "original": { + "path": "./remote", + "type": "path" + }, + "parent": [] + }, "root": { "inputs": { "agenix": "agenix", - "crane": "crane", "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" + "pi-service": "pi-service", + "remote": "remote" } }, "rust-overlay": { "inputs": { "nixpkgs": [ + "pi-service", "nixpkgs" ] }, "locked": { - "lastModified": 1773803479, - "narHash": "sha256-GD6i1F2vrSxbsmbS92+8+x3DbHOJ+yrS78Pm4xigW4M=", + "lastModified": 1773716879, + "narHash": "sha256-vXCTasEzzTTd0ZGEuyle20H2hjRom66JeNr7i2ktHD0=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "f17186f52e82ec5cf40920b58eac63b78692ac7c", + "rev": "1a9ddeb45c5751b800331363703641b84d1f41f0", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "rust-overlay_2": { + "inputs": { + "nixpkgs": [ + "remote", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1773115373, + "narHash": "sha256-bfK9FJFcQth6f3ydYggS5m0z2NRGF/PY6Y2XgZDJ6pg=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "1924b4672a2b8e4aee6e6652ec2e59a8d3c5648e", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index dc0dd17..9b4eae4 100644 --- a/flake.nix +++ b/flake.nix @@ -7,135 +7,36 @@ url = "github:ryantm/agenix"; inputs.nixpkgs.follows = "nixpkgs"; }; - crane.url = "github:ipetkov/crane"; - rust-overlay = { - url = "github:oxalica/rust-overlay"; - inputs.nixpkgs.follows = "nixpkgs"; - }; + pi-service.url = "path:./pi/pi-service"; + remote.url = "path:./remote"; + remote.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs, agenix, crane, rust-overlay }: - let - system = "x86_64-linux"; - pkgs = import nixpkgs { - inherit system; - overlays = [ rust-overlay.overlays.default ]; - }; + outputs = { self, nixpkgs, agenix, pi-service, remote }: { + nixosModules = remote.nixosModules; - # --- Remote services (x86_64-linux) --- - - rustToolchain = pkgs.rust-bin.stable.latest.default; - craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; - - src = pkgs.lib.cleanSourceWith { - src = ./.; - filter = path: type: - (builtins.match ".*\.png$" path != null) || (craneLib.filterCargoSources path type); - }; - - remoteArgs = { - inherit src; - pname = "noisebell"; - version = "0.1.0"; - strictDeps = true; - doCheck = false; - }; - - remoteArtifacts = craneLib.buildDepsOnly remoteArgs; - - buildRemoteMember = name: craneLib.buildPackage (remoteArgs // { - cargoArtifacts = remoteArtifacts; - cargoExtraArgs = "-p ${name}"; - }); - - noisebell-cache = buildRemoteMember "noisebell-cache"; - noisebell-discord = buildRemoteMember "noisebell-discord"; - noisebell-rss = buildRemoteMember "noisebell-rss"; - - # --- Pi service (cross-compiled to aarch64-linux) --- - - crossPkgs = import nixpkgs { - inherit system; - crossSystem.config = "aarch64-unknown-linux-gnu"; - overlays = [ rust-overlay.overlays.default ]; - }; - - piRustToolchain = pkgs.rust-bin.stable.latest.default.override { - targets = [ "aarch64-unknown-linux-gnu" ]; - }; - - piCraneLib = (crane.mkLib pkgs).overrideToolchain piRustToolchain; - - piArgs = { - inherit src; - pname = "noisebell-pi"; - version = "0.1.0"; - strictDeps = true; - doCheck = false; - - CARGO_BUILD_TARGET = "aarch64-unknown-linux-gnu"; - CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = - "${crossPkgs.stdenv.cc.targetPrefix}cc"; - TARGET_CC = "${crossPkgs.stdenv.cc.targetPrefix}cc"; - CC_aarch64_unknown_linux_gnu = "${crossPkgs.stdenv.cc.targetPrefix}cc"; - HOST_CC = "${pkgs.stdenv.cc.nativePrefix}cc"; - - depsBuildBuild = [ crossPkgs.stdenv.cc ]; - cargoExtraArgs = "-p noisebell"; - }; - - piArtifacts = piCraneLib.buildDepsOnly piArgs; - - noisebell-pi = piCraneLib.buildPackage (piArgs // { - cargoArtifacts = piArtifacts; - }); - - in - { - packages.${system} = { - inherit noisebell-cache noisebell-discord noisebell-rss; - default = noisebell-cache; - }; - - packages.aarch64-linux = { - noisebell = noisebell-pi; - default = noisebell-pi; - }; - - nixosModules = { - cache = import ./remote/cache-service/module.nix noisebell-cache; - discord = import ./remote/discord-bot/module.nix noisebell-discord; - rss = import ./remote/rss-service/module.nix noisebell-rss; - default = { imports = [ - (import ./remote/cache-service/module.nix noisebell-cache) - (import ./remote/discord-bot/module.nix noisebell-discord) - (import ./remote/rss-service/module.nix noisebell-rss) - ]; }; - }; - - nixosConfigurations.pi = nixpkgs.lib.nixosSystem { - system = "aarch64-linux"; - modules = [ - agenix.nixosModules.default - (import ./pi/module.nix { - pkg = noisebell-pi; - rev = self.shortRev or "dirty"; - }) - ./pi/configuration.nix - ./pi/hardware-configuration.nix - ]; - }; - - nixosConfigurations.bootstrap = nixpkgs.lib.nixosSystem { - system = "aarch64-linux"; - modules = [ ./pi/bootstrap.nix ]; - }; - - devShells.${system}.default = craneLib.devShell { - packages = [ - pkgs.rust-analyzer - agenix.packages.${system}.default - ]; - }; + nixosConfigurations.pi = nixpkgs.lib.nixosSystem { + system = "aarch64-linux"; + modules = [ + agenix.nixosModules.default + (import ./pi/module.nix { + pkg = pi-service.packages.aarch64-linux.default; + rev = self.shortRev or "dirty"; + }) + ./pi/configuration.nix + ./pi/hardware-configuration.nix + ]; }; + + nixosConfigurations.bootstrap = nixpkgs.lib.nixosSystem { + system = "aarch64-linux"; + modules = [ ./pi/bootstrap.nix ]; + }; + + devShells.x86_64-linux.default = let + pkgs = nixpkgs.legacyPackages.x86_64-linux; + in pkgs.mkShell { + packages = [ agenix.packages.x86_64-linux.default ]; + }; + }; } diff --git a/pi/pi-service/Cargo.lock b/pi/pi-service/Cargo.lock new file mode 100644 index 0000000..3156439 --- /dev/null +++ b/pi/pi-service/Cargo.lock @@ -0,0 +1,1663 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "axum" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8" +dependencies = [ + "axum-core", + "bytes", + "form_urlencoded", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde_core", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cc" +version = "1.2.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "wasip2", + "wasm-bindgen", +] + +[[package]] +name = "gpiod-core" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15a60e3beb5444643d049a3f8769b47ce246ec1f57e6cd1aed1e417d57a47110" +dependencies = [ + "nix", +] + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "pin-utils", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "ipnet" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" + +[[package]] +name = "iri-string" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "js-sys" +version = "0.3.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.183" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "nix" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "libc", +] + +[[package]] +name = "noisebell" +version = "0.1.0" +dependencies = [ + "anyhow", + "axum", + "libc", + "reqwest", + "sd-notify", + "serde", + "serde_json", + "tokio", + "tokio-gpiod", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quinn" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "434b42fec591c96ef50e21e886936e66d3cc3f737104fdb9b737c40ffb94c098" +dependencies = [ + "bytes", + "getrandom 0.3.4", + "lru-slab", + "rand", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.60.2", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustls" +version = "0.23.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "758025cb5fccfd3bc2fd74708fd4682be41d99e5dff73c377c0646c6012c73a4" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "sd-notify" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b943eadf71d8b69e661330cb0e2656e31040acf21ee7708e2c238a0ec6af2bf4" +dependencies = [ + "libc", +] + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-gpiod" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce15fa0021a7acacd2be506f72aeb5044a0a8b53d684963f133b37ace5c57f47" +dependencies = [ + "gpiod-core", + "libc", + "tokio", +] + +[[package]] +name = "tokio-macros" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "bitflags 2.11.0", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.2+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9c5522b3a28661442748e09d40924dfb9ca614b21c00d3fd135720e48b67db8" +dependencies = [ + "cfg-if", + "futures-util", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854ba17bb104abfb26ba36da9729addc7ce7f06f5c0f90f3c391f8461cca21f9" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2578b716f8a7a858b7f02d5bd870c14bf4ddbbcf3a4c05414ba6503640505e3" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e6cc098ea4d3bd6246687de65af3f920c430e236bee1e3bf2e441463f08a02f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/pi/pi-service/Cargo.toml b/pi/pi-service/Cargo.toml index 47cd18a..be7ae80 100644 --- a/pi/pi-service/Cargo.toml +++ b/pi/pi-service/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" anyhow = "1.0" axum = "0.8" libc = "0.2" -noisebell-common = { path = "../../remote/noisebell-common" } reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] } sd-notify = "0.4" serde = { version = "1.0", features = ["derive"] } diff --git a/pi/pi-service/flake.lock b/pi/pi-service/flake.lock new file mode 100644 index 0000000..642dc3f --- /dev/null +++ b/pi/pi-service/flake.lock @@ -0,0 +1,64 @@ +{ + "nodes": { + "crane": { + "locked": { + "lastModified": 1773189535, + "narHash": "sha256-E1G/Or6MWeP+L6mpQ0iTFLpzSzlpGrITfU2220Gq47g=", + "owner": "ipetkov", + "repo": "crane", + "rev": "6fa2fb4cf4a89ba49fc9dd5a3eb6cde99d388269", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1773646010, + "narHash": "sha256-iYrs97hS7p5u4lQzuNWzuALGIOdkPXvjz7bviiBjUu8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5b2c2d84341b2afb5647081c1386a80d7a8d8605", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1773716879, + "narHash": "sha256-vXCTasEzzTTd0ZGEuyle20H2hjRom66JeNr7i2ktHD0=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "1a9ddeb45c5751b800331363703641b84d1f41f0", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/pi/pi-service/flake.nix b/pi/pi-service/flake.nix new file mode 100644 index 0000000..964f39f --- /dev/null +++ b/pi/pi-service/flake.nix @@ -0,0 +1,69 @@ +{ + description = "Noisebell - GPIO door monitor service"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + crane.url = "github:ipetkov/crane"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, crane, rust-overlay }: + let + forSystem = system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ rust-overlay.overlays.default ]; + }; + + crossPkgs = import nixpkgs { + inherit system; + crossSystem.config = "aarch64-unknown-linux-gnu"; + overlays = [ rust-overlay.overlays.default ]; + }; + + rustToolchain = pkgs.rust-bin.stable.latest.default.override { + targets = [ "aarch64-unknown-linux-gnu" ]; + }; + + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; + + src = craneLib.cleanCargoSource ./.; + + commonArgs = { + inherit src; + strictDeps = true; + doCheck = false; + + CARGO_BUILD_TARGET = "aarch64-unknown-linux-gnu"; + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = + "${crossPkgs.stdenv.cc.targetPrefix}cc"; + + TARGET_CC = "${crossPkgs.stdenv.cc.targetPrefix}cc"; + CC_aarch64_unknown_linux_gnu = "${crossPkgs.stdenv.cc.targetPrefix}cc"; + + HOST_CC = "${pkgs.stdenv.cc.nativePrefix}cc"; + + depsBuildBuild = [ crossPkgs.stdenv.cc ]; + }; + + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + noisebell = craneLib.buildPackage (commonArgs // { + inherit cargoArtifacts; + }); + in + { + packages.aarch64-linux.default = noisebell; + packages.aarch64-linux.noisebell = noisebell; + + devShells.${system}.default = craneLib.devShell { + packages = [ pkgs.rust-analyzer ]; + }; + }; + in + forSystem "x86_64-linux"; +} diff --git a/pi/pi-service/src/main.rs b/pi/pi-service/src/main.rs index efd0541..f1c62c6 100644 --- a/pi/pi-service/src/main.rs +++ b/pi/pi-service/src/main.rs @@ -7,7 +7,6 @@ use axum::extract::State; use axum::http::{HeaderMap, StatusCode}; use axum::routing::get; use axum::{Json, Router}; -use noisebell_common::{validate_bearer, WebhookPayload}; use serde::Serialize; use tokio_gpiod::{Bias, Chip, Edge, EdgeDetect, Options}; use tracing::{error, info, warn}; @@ -22,6 +21,14 @@ struct AppState { inbound_api_key: String, } +fn validate_bearer(headers: &HeaderMap, expected: &str) -> bool { + headers + .get("authorization") + .and_then(|v| v.to_str().ok()) + .map(|v| v.strip_prefix("Bearer ").unwrap_or("") == expected) + .unwrap_or(false) +} + #[derive(Serialize)] struct StatusResponse { status: &'static str, @@ -317,7 +324,7 @@ async fn main() -> Result<()> { let status = status_str(new_open); info!(status, timestamp, "state changed"); - let payload = WebhookPayload { status: status.to_string(), timestamp }; + let payload = serde_json::json!({ "status": status, "timestamp": timestamp }); for attempt in 0..=retry_attempts { let result = client diff --git a/Cargo.lock b/remote/Cargo.lock similarity index 96% rename from Cargo.lock rename to remote/Cargo.lock index c3428c2..a8f25db 100644 --- a/Cargo.lock +++ b/remote/Cargo.lock @@ -107,12 +107,6 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.11.0" @@ -148,9 +142,9 @@ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" [[package]] name = "cc" -version = "1.2.57" +version = "1.2.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423" +checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2" dependencies = [ "find-msvc-tools", "shlex", @@ -399,15 +393,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "gpiod-core" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15a60e3beb5444643d049a3f8769b47ce246ec1f57e6cd1aed1e417d57a47110" -dependencies = [ - "nix", -] - [[package]] name = "hashbrown" version = "0.15.5" @@ -766,35 +751,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "nix" -version = "0.26.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" -dependencies = [ - "bitflags 1.3.2", - "cfg-if", - "libc", -] - -[[package]] -name = "noisebell" -version = "0.1.0" -dependencies = [ - "anyhow", - "axum", - "libc", - "noisebell-common", - "reqwest", - "sd-notify", - "serde", - "serde_json", - "tokio", - "tokio-gpiod", - "tracing", - "tracing-subscriber", -] - [[package]] name = "noisebell-cache" version = "0.1.0" @@ -818,7 +774,6 @@ version = "0.1.0" dependencies = [ "axum", "serde", - "serde_json", ] [[package]] @@ -828,7 +783,6 @@ dependencies = [ "anyhow", "axum", "noisebell-common", - "reqwest", "serde", "serde_json", "serenity", @@ -871,9 +825,9 @@ checksum = "cf97ec579c3c42f953ef76dbf8d55ac91fb219dde70e49aa4a6b7d74e9919050" [[package]] name = "once_cell" -version = "1.21.4" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "percent-encoding" @@ -1140,7 +1094,7 @@ version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c6d5e5acb6f6129fe3f7ba0a7fc77bca1942cb568535e18e7bc40262baf3110" dependencies = [ - "bitflags 2.11.0", + "bitflags", "fallible-iterator", "fallible-streaming-iterator", "hashlink", @@ -1226,15 +1180,6 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" -[[package]] -name = "sd-notify" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b943eadf71d8b69e661330cb0e2656e31040acf21ee7708e2c238a0ec6af2bf4" -dependencies = [ - "libc", -] - [[package]] name = "secrecy" version = "0.8.0" @@ -1329,7 +1274,7 @@ dependencies = [ "arrayvec", "async-trait", "base64", - "bitflags 2.11.0", + "bitflags", "bytes", "flate2", "futures", @@ -1547,9 +1492,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.11.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" dependencies = [ "tinyvec_macros", ] @@ -1576,17 +1521,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "tokio-gpiod" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce15fa0021a7acacd2be506f72aeb5044a0a8b53d684963f133b37ace5c57f47" -dependencies = [ - "gpiod-core", - "libc", - "tokio", -] - [[package]] name = "tokio-macros" version = "2.6.1" @@ -1670,7 +1604,7 @@ version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" dependencies = [ - "bitflags 2.11.0", + "bitflags", "bytes", "futures-util", "http", @@ -1741,9 +1675,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.23" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" dependencies = [ "matchers", "nu-ansi-term", diff --git a/remote/Cargo.toml b/remote/Cargo.toml new file mode 100644 index 0000000..99fd2cb --- /dev/null +++ b/remote/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +members = ["noisebell-common", "cache-service", "discord-bot", "rss-service"] +resolver = "2" diff --git a/remote/cache-service/assets/closed.png b/remote/cache-service/assets/closed.png deleted file mode 100644 index a5a48c6..0000000 Binary files a/remote/cache-service/assets/closed.png and /dev/null differ diff --git a/remote/cache-service/assets/offline.png b/remote/cache-service/assets/offline.png deleted file mode 100644 index 5233b45..0000000 Binary files a/remote/cache-service/assets/offline.png and /dev/null differ diff --git a/remote/cache-service/assets/open.png b/remote/cache-service/assets/open.png deleted file mode 100644 index 515f2a8..0000000 Binary files a/remote/cache-service/assets/open.png and /dev/null differ diff --git a/remote/cache-service/src/api.rs b/remote/cache-service/src/api.rs index 97ce27c..4a50a48 100644 --- a/remote/cache-service/src/api.rs +++ b/remote/cache-service/src/api.rs @@ -1,8 +1,7 @@ use std::sync::Arc; use axum::extract::State; -use axum::http::{HeaderMap, StatusCode, header}; -use axum::response::IntoResponse; +use axum::http::{HeaderMap, StatusCode}; use axum::Json; use noisebell_common::{validate_bearer, HistoryEntry, WebhookPayload}; use tokio::sync::Mutex; @@ -12,10 +11,6 @@ use crate::db; use crate::types::{DoorStatus, WebhookTarget}; use crate::webhook; -static OPEN_PNG: &[u8] = include_bytes!("../assets/open.png"); -static CLOSED_PNG: &[u8] = include_bytes!("../assets/closed.png"); -static OFFLINE_PNG: &[u8] = include_bytes!("../assets/offline.png"); - pub struct AppState { pub db: Arc>, pub client: reqwest::Client, @@ -23,8 +18,6 @@ pub struct AppState { pub webhooks: Vec, pub retry_attempts: u32, pub retry_base_delay_secs: u64, - pub webhook_last_request: std::sync::atomic::AtomicU64, - pub webhook_tokens: std::sync::atomic::AtomicU32, } fn unix_now() -> u64 { @@ -34,9 +27,6 @@ fn unix_now() -> u64 { .as_secs() } -const WEBHOOK_RATE_LIMIT: u32 = 10; -const WEBHOOK_RATE_WINDOW_SECS: u64 = 60; - pub async fn post_webhook( State(state): State>, headers: HeaderMap, @@ -46,22 +36,6 @@ pub async fn post_webhook( return StatusCode::UNAUTHORIZED; } - // Simple rate limiting: reset tokens every window, reject if exhausted - let now = unix_now(); - let last = state.webhook_last_request.load(std::sync::atomic::Ordering::Relaxed); - if now.saturating_sub(last) >= WEBHOOK_RATE_WINDOW_SECS { - state.webhook_tokens.store(WEBHOOK_RATE_LIMIT, std::sync::atomic::Ordering::Relaxed); - state.webhook_last_request.store(now, std::sync::atomic::Ordering::Relaxed); - } - let remaining = state.webhook_tokens.fetch_update( - std::sync::atomic::Ordering::Relaxed, - std::sync::atomic::Ordering::Relaxed, - |n| if n > 0 { Some(n - 1) } else { None }, - ); - if remaining.is_err() { - return StatusCode::TOO_MANY_REQUESTS; - } - let Some(status) = DoorStatus::from_str(&body.status) else { return StatusCode::BAD_REQUEST; }; @@ -152,84 +126,3 @@ pub async fn get_history( Ok(Json(entries)) } - -pub async fn get_image_open() -> impl IntoResponse { - ([(header::CONTENT_TYPE, "image/png"), (header::CACHE_CONTROL, "public, max-age=86400")], OPEN_PNG) -} - -pub async fn get_image_closed() -> impl IntoResponse { - ([(header::CONTENT_TYPE, "image/png"), (header::CACHE_CONTROL, "public, max-age=86400")], CLOSED_PNG) -} - -pub async fn get_image_offline() -> impl IntoResponse { - ([(header::CONTENT_TYPE, "image/png"), (header::CACHE_CONTROL, "public, max-age=86400")], OFFLINE_PNG) -} - -pub async fn get_image(State(state): State>) -> impl IntoResponse { - let db = state.db.clone(); - let status = tokio::task::spawn_blocking(move || { - let conn = db.blocking_lock(); - db::get_current_status(&conn) - }) - .await - .expect("db task panicked") - .unwrap_or(DoorStatus::Offline); - - let image = match status { - DoorStatus::Open => OPEN_PNG, - DoorStatus::Closed => CLOSED_PNG, - DoorStatus::Offline => OFFLINE_PNG, - }; - ([(header::CONTENT_TYPE, "image/png"), (header::CACHE_CONTROL, "public, max-age=5")], image) -} - -pub async fn get_badge(State(state): State>) -> impl IntoResponse { - let db = state.db.clone(); - let status = tokio::task::spawn_blocking(move || { - let conn = db.blocking_lock(); - db::get_current_status(&conn) - }) - .await - .expect("db task panicked") - .unwrap_or(DoorStatus::Offline); - - let (label, color) = match status { - DoorStatus::Open => ("open", "#57f287"), - DoorStatus::Closed => ("closed", "#ed4245"), - DoorStatus::Offline => ("offline", "#99aab5"), - }; - - let label_width = 70u32; - let value_width = 10 + label.len() as u32 * 7; - let total_width = label_width + value_width; - let label_x = label_width as f32 / 2.0; - let value_x = label_width as f32 + value_width as f32 / 2.0; - - let svg = format!( - "\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - noisebell\ - noisebell\ - {label}\ - {label}\ - " - ); - - ( - [ - (header::CONTENT_TYPE, "image/svg+xml"), - (header::CACHE_CONTROL, "no-cache, max-age=0"), - ], - svg, - ) -} diff --git a/remote/cache-service/src/db.rs b/remote/cache-service/src/db.rs index 0831cf8..77964de 100644 --- a/remote/cache-service/src/db.rs +++ b/remote/cache-service/src/db.rs @@ -12,8 +12,7 @@ pub fn init(path: &str) -> Result { id INTEGER PRIMARY KEY CHECK (id = 1), status TEXT, timestamp INTEGER, - last_seen INTEGER, - last_checked INTEGER + last_seen INTEGER ); CREATE TABLE IF NOT EXISTS state_log ( @@ -29,29 +28,17 @@ pub fn init(path: &str) -> Result { fetched_at INTEGER NOT NULL ); - INSERT OR IGNORE INTO current_state (id, status, timestamp, last_seen, last_checked) VALUES (1, 'offline', NULL, NULL, NULL); + INSERT OR IGNORE INTO current_state (id, status, timestamp, last_seen) VALUES (1, NULL, NULL, NULL); INSERT OR IGNORE INTO pi_info (id, data, fetched_at) VALUES (1, '{}', 0); ", ) .context("failed to initialize database schema")?; - - // Migration: add last_checked column if missing (existing databases) - let has_last_checked: bool = conn - .prepare("SELECT last_checked FROM current_state LIMIT 1") - .is_ok(); - if !has_last_checked { - conn.execute_batch("ALTER TABLE current_state ADD COLUMN last_checked INTEGER")?; - } - - // Migration: convert NULL status to 'offline' - conn.execute("UPDATE current_state SET status = 'offline' WHERE status IS NULL", [])?; - Ok(conn) } pub fn get_status(conn: &Connection) -> Result { - let (status_str, timestamp, last_checked) = conn.query_row( - "SELECT status, timestamp, last_checked FROM current_state WHERE id = 1", + let (status, timestamp, last_seen) = conn.query_row( + "SELECT status, timestamp, last_seen FROM current_state WHERE id = 1", [], |row| { Ok(( @@ -61,14 +48,10 @@ pub fn get_status(conn: &Connection) -> Result { )) }, )?; - let status = status_str - .as_deref() - .and_then(DoorStatus::from_str) - .unwrap_or(DoorStatus::Offline); Ok(StatusResponse { - status, - since: timestamp, - last_checked, + status: status.unwrap_or_else(|| "offline".to_string()), + timestamp, + last_seen, }) } @@ -76,7 +59,7 @@ pub fn update_state(conn: &Connection, status: DoorStatus, timestamp: u64, now: let status_str = status.as_str(); conn.execute( "UPDATE current_state SET status = ?1, timestamp = ?2, last_seen = ?3 WHERE id = 1", - rusqlite::params![status_str, now, now], + rusqlite::params![status_str, timestamp, now], )?; conn.execute( "INSERT INTO state_log (status, timestamp, recorded_at) VALUES (?1, ?2, ?3)", @@ -93,18 +76,10 @@ pub fn update_last_seen(conn: &Connection, now: u64) -> Result<()> { Ok(()) } -pub fn update_last_checked(conn: &Connection, now: u64) -> Result<()> { - conn.execute( - "UPDATE current_state SET last_checked = ?1 WHERE id = 1", - rusqlite::params![now], - )?; - Ok(()) -} - pub fn mark_offline(conn: &Connection, now: u64) -> Result<()> { conn.execute( - "UPDATE current_state SET status = 'offline', timestamp = ?1 WHERE id = 1", - rusqlite::params![now], + "UPDATE current_state SET status = NULL WHERE id = 1", + [], )?; conn.execute( "INSERT INTO state_log (status, timestamp, recorded_at) VALUES ('offline', ?1, ?1)", @@ -113,16 +88,13 @@ pub fn mark_offline(conn: &Connection, now: u64) -> Result<()> { Ok(()) } -pub fn get_current_status(conn: &Connection) -> Result { - let status_str: Option = conn.query_row( +pub fn get_current_status_str(conn: &Connection) -> Result> { + let status = conn.query_row( "SELECT status FROM current_state WHERE id = 1", [], - |row| row.get(0), + |row| row.get::<_, Option>(0), )?; - Ok(status_str - .as_deref() - .and_then(DoorStatus::from_str) - .unwrap_or(DoorStatus::Offline)) + Ok(status) } pub fn get_history(conn: &Connection, limit: u32) -> Result> { @@ -159,105 +131,3 @@ pub fn update_pi_info(conn: &Connection, data: &serde_json::Value, now: u64) -> )?; Ok(()) } - -#[cfg(test)] -mod tests { - use super::*; - - fn test_db() -> Connection { - init(":memory:").expect("failed to init test db") - } - - #[test] - fn initial_status_is_offline() { - let conn = test_db(); - let status = get_status(&conn).unwrap(); - assert_eq!(status.status, DoorStatus::Offline); - assert!(status.since.is_none()); - assert!(status.last_checked.is_none()); - } - - #[test] - fn update_state_changes_status() { - let conn = test_db(); - update_state(&conn, DoorStatus::Open, 1000, 1001).unwrap(); - - let status = get_status(&conn).unwrap(); - assert_eq!(status.status, DoorStatus::Open); - assert_eq!(status.since, Some(1001)); - } - - #[test] - fn mark_offline_sets_offline_status() { - let conn = test_db(); - update_state(&conn, DoorStatus::Open, 1000, 1001).unwrap(); - mark_offline(&conn, 2000).unwrap(); - - let status = get_status(&conn).unwrap(); - assert_eq!(status.status, DoorStatus::Offline); - assert_eq!(status.since, Some(2000)); - } - - #[test] - fn get_current_status_matches_get_status() { - let conn = test_db(); - assert_eq!(get_current_status(&conn).unwrap(), DoorStatus::Offline); - - update_state(&conn, DoorStatus::Closed, 1000, 1001).unwrap(); - assert_eq!(get_current_status(&conn).unwrap(), DoorStatus::Closed); - } - - #[test] - fn update_last_checked_is_readable() { - let conn = test_db(); - update_last_checked(&conn, 5000).unwrap(); - - let status = get_status(&conn).unwrap(); - assert_eq!(status.last_checked, Some(5000)); - } - - #[test] - fn history_records_state_changes() { - let conn = test_db(); - update_state(&conn, DoorStatus::Open, 1000, 1001).unwrap(); - update_state(&conn, DoorStatus::Closed, 2000, 2001).unwrap(); - mark_offline(&conn, 3000).unwrap(); - - let history = get_history(&conn, 10).unwrap(); - assert_eq!(history.len(), 3); - assert_eq!(history[0].status, "offline"); - assert_eq!(history[1].status, "closed"); - assert_eq!(history[2].status, "open"); - } - - #[test] - fn status_response_serializes_correctly() { - let resp = StatusResponse { - status: DoorStatus::Open, - since: Some(1234), - last_checked: Some(5678), - }; - let json = serde_json::to_value(&resp).unwrap(); - assert_eq!(json["status"], "open"); - assert_eq!(json["since"], 1234); - assert_eq!(json["last_checked"], 5678); - } - - #[test] - fn null_status_migration_converts_to_offline() { - // Simulate an old database with NULL status - let conn = Connection::open_in_memory().unwrap(); - conn.execute_batch(" - CREATE TABLE current_state (id INTEGER PRIMARY KEY CHECK (id = 1), status TEXT, timestamp INTEGER, last_seen INTEGER); - INSERT INTO current_state (id, status, timestamp, last_seen) VALUES (1, NULL, NULL, NULL); - CREATE TABLE state_log (id INTEGER PRIMARY KEY AUTOINCREMENT, status TEXT NOT NULL, timestamp INTEGER NOT NULL, recorded_at INTEGER NOT NULL); - CREATE TABLE pi_info (id INTEGER PRIMARY KEY CHECK (id = 1), data TEXT NOT NULL, fetched_at INTEGER NOT NULL); - INSERT INTO pi_info (id, data, fetched_at) VALUES (1, '{}', 0); - ").unwrap(); - - // Re-init should migrate - let conn = init(":memory:").unwrap(); - let status = get_current_status(&conn).unwrap(); - assert_eq!(status, DoorStatus::Offline); - } -} diff --git a/remote/cache-service/src/main.rs b/remote/cache-service/src/main.rs index a39014f..d2dc86d 100644 --- a/remote/cache-service/src/main.rs +++ b/remote/cache-service/src/main.rs @@ -5,7 +5,6 @@ use anyhow::{Context, Result}; use axum::routing::{get, post}; use axum::Router; use tokio::sync::Mutex; -use std::sync::atomic::AtomicU64; use tower_http::trace::TraceLayer; use tracing::{info, Level}; @@ -123,8 +122,6 @@ async fn main() -> Result<()> { webhooks, retry_attempts, retry_base_delay_secs, - webhook_last_request: AtomicU64::new(0), - webhook_tokens: std::sync::atomic::AtomicU32::new(10), }); let app = Router::new() @@ -133,11 +130,6 @@ async fn main() -> Result<()> { .route("/status", get(api::get_status)) .route("/info", get(api::get_info)) .route("/history", get(api::get_history)) - .route("/image", get(api::get_image)) - .route("/image/open.png", get(api::get_image_open)) - .route("/image/closed.png", get(api::get_image_closed)) - .route("/image/offline.png", get(api::get_image_offline)) - .route("/badge.svg", get(api::get_badge)) .layer( TraceLayer::new_for_http() .make_span_with(tower_http::trace::DefaultMakeSpan::new().level(Level::INFO)) diff --git a/remote/cache-service/src/poller.rs b/remote/cache-service/src/poller.rs index 68affb7..aac7321 100644 --- a/remote/cache-service/src/poller.rs +++ b/remote/cache-service/src/poller.rs @@ -37,18 +37,6 @@ pub fn spawn_status_poller( let mut was_offline = false; loop { - { - let now = unix_now(); - let db = db.clone(); - let _ = tokio::task::spawn_blocking(move || { - let conn = db.blocking_lock(); - if let Err(e) = db::update_last_checked(&conn, now) { - error!(error = %e, "failed to update last_checked"); - } - }) - .await; - } - let result = client .get(format!("{}/", config.pi_address)) .bearer_auth(&config.pi_api_key) @@ -77,9 +65,10 @@ pub fn spawn_status_poller( if let Some(ref status_str) = status_str { if let Some(status) = DoorStatus::from_str(status_str) { - let current = db::get_current_status(&conn); + let current = db::get_current_status_str(&conn); let changed = match ¤t { - Ok(current) => *current != status, + Ok(Some(s)) => s != status.as_str(), + Ok(None) => true, Err(_) => true, }; if changed { diff --git a/remote/cache-service/src/types.rs b/remote/cache-service/src/types.rs index 16c7c18..978fc16 100644 --- a/remote/cache-service/src/types.rs +++ b/remote/cache-service/src/types.rs @@ -5,7 +5,6 @@ use serde::{Deserialize, Serialize}; pub enum DoorStatus { Open, Closed, - Offline, } impl DoorStatus { @@ -13,7 +12,6 @@ impl DoorStatus { match self { DoorStatus::Open => "open", DoorStatus::Closed => "closed", - DoorStatus::Offline => "offline", } } @@ -21,7 +19,6 @@ impl DoorStatus { match s { "open" => Some(DoorStatus::Open), "closed" => Some(DoorStatus::Closed), - "offline" => Some(DoorStatus::Offline), _ => None, } } @@ -29,9 +26,9 @@ impl DoorStatus { #[derive(Debug, Clone, Serialize)] pub struct StatusResponse { - pub status: DoorStatus, - pub since: Option, // when the current status was set - pub last_checked: Option, // when the cache last attempted to poll + pub status: String, // "open", "closed", or "offline" + pub timestamp: Option, + pub last_seen: Option, } #[derive(Debug, Clone)] @@ -39,34 +36,3 @@ pub struct WebhookTarget { pub url: String, pub secret: Option, } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn door_status_round_trip() { - for status in [DoorStatus::Open, DoorStatus::Closed, DoorStatus::Offline] { - let s = status.as_str(); - assert_eq!(DoorStatus::from_str(s), Some(status)); - } - } - - #[test] - fn door_status_from_str_rejects_unknown() { - assert_eq!(DoorStatus::from_str("unknown"), None); - assert_eq!(DoorStatus::from_str(""), None); - } - - #[test] - fn door_status_serde_lowercase() { - let json = serde_json::to_string(&DoorStatus::Open).unwrap(); - assert_eq!(json, "\"open\""); - - let deserialized: DoorStatus = serde_json::from_str("\"closed\"").unwrap(); - assert_eq!(deserialized, DoorStatus::Closed); - - let deserialized: DoorStatus = serde_json::from_str("\"offline\"").unwrap(); - assert_eq!(deserialized, DoorStatus::Offline); - } -} diff --git a/remote/discord-bot/Cargo.toml b/remote/discord-bot/Cargo.toml index 3dd4a51..a14b659 100644 --- a/remote/discord-bot/Cargo.toml +++ b/remote/discord-bot/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" anyhow = "1.0" axum = "0.8" noisebell-common = { path = "../noisebell-common" } -reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serenity = { version = "0.12", default-features = false, features = ["client", "gateway", "model", "rustls_backend"] } diff --git a/remote/discord-bot/module.nix b/remote/discord-bot/module.nix index faad73d..3eff505 100644 --- a/remote/discord-bot/module.nix +++ b/remote/discord-bot/module.nix @@ -33,17 +33,6 @@ in type = lib.types.path; description = "Path to file containing the webhook secret."; }; - - imageBaseUrl = lib.mkOption { - type = lib.types.str; - default = "https://noisebell.extremist.software/image"; - description = "Base URL for status images used in Discord embeds."; - }; - - cacheUrl = lib.mkOption { - type = lib.types.str; - description = "URL of the cache service for slash commands (e.g. http://localhost:3000)."; - }; }; config = lib.mkIf cfg.enable { @@ -65,8 +54,6 @@ in environment = { NOISEBELL_DISCORD_PORT = toString cfg.port; NOISEBELL_DISCORD_CHANNEL_ID = cfg.channelId; - NOISEBELL_DISCORD_IMAGE_BASE_URL = cfg.imageBaseUrl; - NOISEBELL_DISCORD_CACHE_URL = cfg.cacheUrl; RUST_LOG = "info"; }; script = '' diff --git a/remote/discord-bot/src/main.rs b/remote/discord-bot/src/main.rs index 14e7006..b375293 100644 --- a/remote/discord-bot/src/main.rs +++ b/remote/discord-bot/src/main.rs @@ -2,47 +2,37 @@ use std::sync::Arc; use std::time::Duration; use anyhow::{Context, Result}; -use axum::extract::State as AxumState; +use axum::extract::State; use axum::http::{HeaderMap, StatusCode}; use axum::routing::{get, post}; use axum::{Json, Router}; use noisebell_common::{validate_bearer, WebhookPayload}; -use serenity::all::{ - ChannelId, Colour, CommandInteraction, CreateCommand, CreateEmbed, CreateInteractionResponse, - CreateInteractionResponseMessage, CreateMessage, GatewayIntents, Interaction, -}; -use serenity::async_trait; +use serenity::all::{ChannelId, Colour, CreateEmbed, CreateMessage, GatewayIntents}; use tower_http::trace::TraceLayer; -use tracing::{error, info, warn, Level}; +use tracing::{error, info, Level}; struct AppState { http: Arc, channel_id: ChannelId, webhook_secret: String, - image_base_url: String, - cache_url: String, - client: reqwest::Client, } -fn build_embed(status: &str, timestamp: u64, image_base_url: &str) -> CreateEmbed { - let (colour, title, description, image_file) = match status { - "open" => (Colour::from_rgb(0, 255, 0), "Noisebridge is Open!", "It's time to start hacking.", "open.png"), - "closed" => (Colour::from_rgb(255, 0, 0), "Noisebridge is Closed!", "We'll see you again soon.", "closed.png"), - _ => (Colour::from_rgb(153, 170, 181), "Noisebridge is Offline", "The Noisebridge Pi is not responding.", "offline.png"), +fn build_embed(status: &str, timestamp: u64) -> CreateEmbed { + let (colour, title, description) = match status { + "open" => (Colour::from_rgb(87, 242, 135), "Door is open", "The door at Noisebridge is open."), + "closed" => (Colour::from_rgb(237, 66, 69), "Door is closed", "The door at Noisebridge is closed."), + _ => (Colour::from_rgb(153, 170, 181), "Pi is offline", "The Noisebridge Pi is offline."), }; - let image_url = format!("{image_base_url}/{image_file}"); - CreateEmbed::new() .title(title) .description(description) .colour(colour) - .thumbnail(image_url) .timestamp(serenity::model::Timestamp::from_unix_timestamp(timestamp as i64).unwrap_or_else(|_| serenity::model::Timestamp::now())) } async fn post_webhook( - AxumState(state): AxumState>, + State(state): State>, headers: HeaderMap, Json(body): Json, ) -> StatusCode { @@ -52,7 +42,7 @@ async fn post_webhook( info!(status = %body.status, timestamp = body.timestamp, "received webhook"); - let embed = build_embed(&body.status, body.timestamp, &state.image_base_url); + let embed = build_embed(&body.status, body.timestamp); let message = CreateMessage::new().embed(embed); match state.channel_id.send_message(&state.http, message).await { @@ -67,227 +57,9 @@ async fn post_webhook( } } -fn unix_now() -> u64 { - std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .unwrap() - .as_secs() -} +struct Handler; -fn format_timestamp(ts: u64) -> String { - format!("", ts) -} - -async fn handle_status(state: &AppState, _command: &CommandInteraction) -> CreateInteractionResponse { - let url = format!("{}/status", state.cache_url); - let resp = state.client.get(&url).send().await; - - let embed = match resp { - Ok(resp) if resp.status().is_success() => { - match resp.json::().await { - Ok(data) => { - let status = data.get("status").and_then(|s| s.as_str()).unwrap_or("unknown"); - let since = data.get("since").and_then(|t| t.as_u64()); - let last_checked = data.get("last_checked").and_then(|t| t.as_u64()); - - let mut embed = build_embed(status, since.unwrap_or(unix_now()), &state.image_base_url); - - let mut fields = Vec::new(); - if let Some(ts) = since { - fields.push(("Since", format_timestamp(ts), true)); - } - if let Some(ts) = last_checked { - fields.push(("Last Checked", format_timestamp(ts), true)); - } - if !fields.is_empty() { - embed = embed.fields(fields); - } - embed - } - Err(e) => { - error!(error = %e, "failed to parse status response"); - CreateEmbed::new() - .title("Error") - .description("Failed to parse status response.") - .colour(Colour::from_rgb(255, 0, 0)) - } - } - } - _ => { - CreateEmbed::new() - .title("Error") - .description("Failed to reach the cache service.") - .colour(Colour::from_rgb(255, 0, 0)) - } - }; - - CreateInteractionResponse::Message( - CreateInteractionResponseMessage::new().embed(embed) - ) -} - -async fn handle_info(state: &AppState, _command: &CommandInteraction) -> CreateInteractionResponse { - let url = format!("{}/info", state.cache_url); - let resp = state.client.get(&url).send().await; - - let embed = match resp { - Ok(resp) if resp.status().is_success() => { - match resp.json::().await { - Ok(data) => { - let mut fields = Vec::new(); - - if let Some(temp) = data.get("cpu_temp_celsius").and_then(|t| t.as_f64()) { - fields.push(("CPU Temp", format!("{:.1}°C", temp), true)); - } - if let Some(load) = data.get("load_average").and_then(|l| l.as_array()) { - let loads: Vec = load.iter().filter_map(|v| v.as_f64()).map(|v| format!("{:.2}", v)).collect(); - fields.push(("Load Average", loads.join(", "), true)); - } - if let Some(total) = data.get("memory_total_kb").and_then(|t| t.as_u64()) { - if let Some(avail) = data.get("memory_available_kb").and_then(|a| a.as_u64()) { - let used = total.saturating_sub(avail); - fields.push(("Memory", format!("{} / {} MB", used / 1024, total / 1024), true)); - } - } - if let Some(total) = data.get("disk_total_bytes").and_then(|t| t.as_u64()) { - if let Some(avail) = data.get("disk_available_bytes").and_then(|a| a.as_u64()) { - let used = total.saturating_sub(avail); - fields.push(("Disk", format!("{:.1} / {:.1} GB", used as f64 / 1e9, total as f64 / 1e9), true)); - } - } - if let Some(uptime) = data.get("uptime_secs").and_then(|u| u.as_u64()) { - let hours = uptime / 3600; - let mins = (uptime % 3600) / 60; - fields.push(("Uptime", format!("{}h {}m", hours, mins), true)); - } - if let Some(version) = data.get("nixos_version").and_then(|v| v.as_str()) { - fields.push(("NixOS", version.to_string(), true)); - } - if let Some(commit) = data.get("commit").and_then(|c| c.as_str()) { - fields.push(("Commit", commit.to_string(), true)); - } - - CreateEmbed::new() - .title("Noisebridge Pi Info") - .colour(Colour::BLUE) - .fields(fields) - } - Err(e) => { - error!(error = %e, "failed to parse info response"); - CreateEmbed::new() - .title("Error") - .description("Failed to parse Pi info.") - .colour(Colour::from_rgb(255, 0, 0)) - } - } - } - _ => { - CreateEmbed::new() - .title("Error") - .description("Failed to reach the cache service.") - .colour(Colour::from_rgb(255, 0, 0)) - } - }; - - CreateInteractionResponse::Message( - CreateInteractionResponseMessage::new().embed(embed) - ) -} - -async fn handle_history(state: &AppState, _command: &CommandInteraction) -> CreateInteractionResponse { - let url = format!("{}/history", state.cache_url); - let resp = state.client.get(&url).send().await; - - let embed = match resp { - Ok(resp) if resp.status().is_success() => { - match resp.json::>().await { - Ok(entries) => { - let lines: Vec = entries.iter().take(10).map(|entry| { - let status = entry.get("status").and_then(|s| s.as_str()).unwrap_or("unknown"); - let ts = entry.get("timestamp").and_then(|t| t.as_u64()).unwrap_or(0); - let emoji = match status { - "open" => "🟢", - "closed" => "🔴", - "offline" => "⚪", - _ => "❓", - }; - format!("{} **{}** — {}", emoji, status, format_timestamp(ts)) - }).collect(); - - let description = if lines.is_empty() { - "No history available.".to_string() - } else { - lines.join("\n") - }; - - CreateEmbed::new() - .title("Recent Door History") - .description(description) - .colour(Colour::BLUE) - } - Err(e) => { - error!(error = %e, "failed to parse history response"); - CreateEmbed::new() - .title("Error") - .description("Failed to parse history.") - .colour(Colour::from_rgb(255, 0, 0)) - } - } - } - _ => { - CreateEmbed::new() - .title("Error") - .description("Failed to reach the cache service.") - .colour(Colour::from_rgb(255, 0, 0)) - } - }; - - CreateInteractionResponse::Message( - CreateInteractionResponseMessage::new().embed(embed) - ) -} - -struct Handler { - state: Arc, -} - -#[async_trait] -impl serenity::all::EventHandler for Handler { - async fn ready(&self, ctx: serenity::all::Context, ready: serenity::model::gateway::Ready) { - info!(user = %ready.user.name, "Discord bot connected"); - - let commands = vec![ - CreateCommand::new("status").description("Show the current door status"), - CreateCommand::new("info").description("Show Pi system information"), - CreateCommand::new("history").description("Show recent door history"), - ]; - - if let Err(e) = serenity::all::Command::set_global_commands(&ctx.http, commands).await { - error!(error = %e, "failed to register slash commands"); - } else { - info!("slash commands registered"); - } - } - - async fn interaction_create(&self, ctx: serenity::all::Context, interaction: Interaction) { - if let Interaction::Command(command) = interaction { - let response = match command.data.name.as_str() { - "status" => handle_status(&self.state, &command).await, - "info" => handle_info(&self.state, &command).await, - "history" => handle_history(&self.state, &command).await, - _ => { - CreateInteractionResponse::Message( - CreateInteractionResponseMessage::new().content("Unknown command.") - ) - } - }; - - if let Err(e) = command.create_response(&ctx.http, response).await { - error!(error = %e, command = %command.data.name, "failed to respond to slash command"); - } - } - } -} +impl serenity::all::EventHandler for Handler {} #[tokio::main] async fn main() -> Result<()> { @@ -311,47 +83,20 @@ async fn main() -> Result<()> { .parse() .context("NOISEBELL_DISCORD_PORT must be a valid u16")?; - let image_base_url = std::env::var("NOISEBELL_DISCORD_IMAGE_BASE_URL") - .unwrap_or_else(|_| "https://noisebell.extremist.software/image".into()) - .trim_end_matches('/') - .to_string(); - - let cache_url = std::env::var("NOISEBELL_DISCORD_CACHE_URL") - .context("NOISEBELL_DISCORD_CACHE_URL is required")? - .trim_end_matches('/') - .to_string(); - info!(port, channel_id, "starting noisebell-discord"); - let client = reqwest::Client::builder() - .timeout(Duration::from_secs(10)) - .build() - .context("failed to build HTTP client")?; - let intents = GatewayIntents::empty(); - let mut discord_client = serenity::Client::builder(&discord_token, intents) - .event_handler_arc(Arc::new(Handler { - state: Arc::new(AppState { - http: Arc::new(serenity::all::Http::new(&discord_token)), - channel_id: ChannelId::new(channel_id), - webhook_secret: webhook_secret.clone(), - image_base_url: image_base_url.clone(), - cache_url: cache_url.clone(), - client: client.clone(), - }), - })) + let mut initial_client = serenity::Client::builder(&discord_token, intents) + .event_handler(Handler) .await .context("failed to create Discord client")?; - let http = discord_client.http.clone(); + let http = initial_client.http.clone(); let app_state = Arc::new(AppState { http, channel_id: ChannelId::new(channel_id), webhook_secret, - image_base_url, - cache_url, - client, }); let app = Router::new() @@ -370,14 +115,28 @@ async fn main() -> Result<()> { info!(port, "webhook listener ready"); - // Spawn gateway connection for slash commands + // Gateway reconnect loop — the Http client for sending messages is independent + let token_for_gateway = discord_token.clone(); tokio::spawn(async move { + if let Err(e) = initial_client.start().await { + error!(error = %e, "Discord gateway disconnected"); + } loop { - if let Err(e) = discord_client.start().await { - error!(error = %e, "Discord gateway disconnected"); - } - warn!("reconnecting to Discord gateway in 5s"); tokio::time::sleep(Duration::from_secs(5)).await; + info!("reconnecting to Discord gateway"); + match serenity::Client::builder(&token_for_gateway, GatewayIntents::empty()) + .event_handler(Handler) + .await + { + Ok(mut client) => { + if let Err(e) = client.start().await { + error!(error = %e, "Discord gateway disconnected"); + } + } + Err(e) => { + error!(error = %e, "failed to create Discord client"); + } + } } }); diff --git a/remote/flake.lock b/remote/flake.lock new file mode 100644 index 0000000..5385057 --- /dev/null +++ b/remote/flake.lock @@ -0,0 +1,64 @@ +{ + "nodes": { + "crane": { + "locked": { + "lastModified": 1773115265, + "narHash": "sha256-5fDkKTYEgue2klksd52WvcXfZdY1EIlbk0QggAwpFog=", + "owner": "ipetkov", + "repo": "crane", + "rev": "27711550d109bf6236478dc9f53b9e29c1a374c5", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1772963539, + "narHash": "sha256-9jVDGZnvCckTGdYT53d/EfznygLskyLQXYwJLKMPsZs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9dcb002ca1690658be4a04645215baea8b95f31d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1773115373, + "narHash": "sha256-bfK9FJFcQth6f3ydYggS5m0z2NRGF/PY6Y2XgZDJ6pg=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "1924b4672a2b8e4aee6e6652ec2e59a8d3c5648e", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/remote/flake.nix b/remote/flake.nix new file mode 100644 index 0000000..0af03a3 --- /dev/null +++ b/remote/flake.nix @@ -0,0 +1,66 @@ +{ + description = "Noisebell remote services"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + crane.url = "github:ipetkov/crane"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, crane, rust-overlay }: + let + system = "x86_64-linux"; + pkgs = import nixpkgs { + inherit system; + overlays = [ rust-overlay.overlays.default ]; + }; + + rustToolchain = pkgs.rust-bin.stable.latest.default; + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; + + src = craneLib.cleanCargoSource ./.; + + commonArgs = { + inherit src; + pname = "noisebell"; + version = "0.1.0"; + strictDeps = true; + doCheck = false; + }; + + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + buildMember = name: craneLib.buildPackage (commonArgs // { + inherit cargoArtifacts; + cargoExtraArgs = "-p ${name}"; + }); + + noisebell-cache = buildMember "noisebell-cache"; + noisebell-discord = buildMember "noisebell-discord"; + noisebell-rss = buildMember "noisebell-rss"; + in + { + packages.${system} = { + inherit noisebell-cache noisebell-discord noisebell-rss; + default = noisebell-cache; + }; + + nixosModules = { + cache = import ./cache-service/module.nix noisebell-cache; + discord = import ./discord-bot/module.nix noisebell-discord; + rss = import ./rss-service/module.nix noisebell-rss; + default = { imports = [ + (import ./cache-service/module.nix noisebell-cache) + (import ./discord-bot/module.nix noisebell-discord) + (import ./rss-service/module.nix noisebell-rss) + ]; }; + }; + + devShells.${system}.default = craneLib.devShell { + packages = [ pkgs.rust-analyzer ]; + }; + }; +} diff --git a/remote/noisebell-common/Cargo.toml b/remote/noisebell-common/Cargo.toml index 6cb2d0e..7f0eece 100644 --- a/remote/noisebell-common/Cargo.toml +++ b/remote/noisebell-common/Cargo.toml @@ -6,6 +6,3 @@ edition = "2021" [dependencies] axum = "0.8" serde = { version = "1.0", features = ["derive"] } - -[dev-dependencies] -serde_json = "1.0" diff --git a/remote/noisebell-common/src/lib.rs b/remote/noisebell-common/src/lib.rs index 2c96ade..002214d 100644 --- a/remote/noisebell-common/src/lib.rs +++ b/remote/noisebell-common/src/lib.rs @@ -22,44 +22,3 @@ pub struct HistoryEntry { pub timestamp: u64, pub recorded_at: u64, } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn validate_bearer_accepts_correct_token() { - let mut headers = HeaderMap::new(); - headers.insert("authorization", "Bearer secret123".parse().unwrap()); - assert!(validate_bearer(&headers, "secret123")); - } - - #[test] - fn validate_bearer_rejects_wrong_token() { - let mut headers = HeaderMap::new(); - headers.insert("authorization", "Bearer wrong".parse().unwrap()); - assert!(!validate_bearer(&headers, "secret123")); - } - - #[test] - fn validate_bearer_rejects_missing_header() { - let headers = HeaderMap::new(); - assert!(!validate_bearer(&headers, "secret123")); - } - - #[test] - fn validate_bearer_rejects_non_bearer_scheme() { - let mut headers = HeaderMap::new(); - headers.insert("authorization", "Basic secret123".parse().unwrap()); - assert!(!validate_bearer(&headers, "secret123")); - } - - #[test] - fn webhook_payload_round_trips() { - let payload = WebhookPayload { status: "open".into(), timestamp: 1234567890 }; - let json = serde_json::to_string(&payload).unwrap(); - let deserialized: WebhookPayload = serde_json::from_str(&json).unwrap(); - assert_eq!(deserialized.status, "open"); - assert_eq!(deserialized.timestamp, 1234567890); - } -}