From 810721ceac0249e747cdf36f3edec22d829d4371 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Fri, 31 Dec 2021 23:53:52 +0100 Subject: ebus-rust nixos package --- README.md | 16 +++++++++ ebus-rust/flake.lock | 42 ----------------------- ebus-rust/flake.nix | 31 ----------------- ebus-xml/Makefile | 6 ++-- flake.lock | 42 +++++++++++++++++++++++ flake.nix | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 158 insertions(+), 76 deletions(-) delete mode 100644 ebus-rust/flake.lock delete mode 100644 ebus-rust/flake.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/README.md b/README.md index 4a186b9..bce45f8 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,19 @@ - [ebus-racket](ebus-racket/) eBus protocol parser written in racket - [ebus-rust](ebus-rust/) eBus protocol parser writtin in rust - [ebus-xml](ebus-xml/) eBus protocol specification (devices, packets, fields) in xml. + +## Usage of ebus-rust on nixos + +``` + inputs.ebus.url = "github:yvesf/ebus"; + inputs.ebus.inputs.nixpkgs.follows = "template/nixpkgs"; + ... + # add module + ebus.nixosModules.ebus-rust + ... + # configure module + services.ebus-rust.enable = true; + services.ebus-rust.user = settings.username; + services.ebus-rust.device = "/dev/ttyUSB0"; + ... +``` \ No newline at end of file diff --git a/ebus-rust/flake.lock b/ebus-rust/flake.lock deleted file mode 100644 index 1114d39..0000000 --- a/ebus-rust/flake.lock +++ /dev/null @@ -1,42 +0,0 @@ -{ - "nodes": { - "flake-utils": { - "locked": { - "lastModified": 1631561581, - "narHash": "sha256-3VQMV5zvxaVLvqqUrNz3iJelLw30mIVSfZmAaauM3dA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "7e5bf3925f6fbdfaf50a2a7ca0be2879c4261d19", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1633709683, - "narHash": "sha256-KVJEToVd6SuUqc2XFIpfSjns07orqEWzIq9AcF/SIf8=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "ce7a1190a0fa4ba3465b5f5471b08567060ca14c", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixos-21.05", - "type": "indirect" - } - }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/ebus-rust/flake.nix b/ebus-rust/flake.nix deleted file mode 100644 index b39b841..0000000 --- a/ebus-rust/flake.nix +++ /dev/null @@ -1,31 +0,0 @@ -{ - inputs.nixpkgs.url = "nixpkgs/nixos-21.05"; - inputs.flake-utils.url = "github:numtide/flake-utils"; - - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - in - { - devShell = pkgs.mkShell { - nativeBuildInputs = with pkgs; [ - cargo - rustc - pkg-config - rustfmt - rls - clippy - bashInteractive - nixpkgs-fmt - gitFull - xxd - influxdb - ]; - buildInputs = with pkgs; [ - openssl - ]; - RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; - }; - }); -} diff --git a/ebus-xml/Makefile b/ebus-xml/Makefile index 1a8f4fc..3d17503 100644 --- a/ebus-xml/Makefile +++ b/ebus-xml/Makefile @@ -2,14 +2,14 @@ TARGET_DIST=dist/$(shell date --rfc-3339=date) all: doc -doc: +doc: validate test -d build || mkdir build xsltproc ebus.docbook.xslt ebus.xml > build/ebus.docbook.xml - dblatex -T db2latex build/ebus.docbook.xml + pandoc -s -f docbook build/ebus.docbook.xml -o build/ebus.html dist: doc test -d $(TARGET_DIST) || mkdir -p $(TARGET_DIST) - cp build/ebus.docbook.pdf $(TARGET_DIST) + cp build/ebus.html $(TARGET_DIST) cp ebus.xml $(TARGET_DIST) validate: diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..158c6a7 --- /dev/null +++ b/flake.lock @@ -0,0 +1,42 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1638122382, + "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1640887906, + "narHash": "sha256-Eupk1UlNicCD2UNZuEKt6yhE6kFWAxXM/HyziOjG9CA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8a053bc2255659c5ca52706b9e12e76a8f50dbdd", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-21.11", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1d19f5a --- /dev/null +++ b/flake.nix @@ -0,0 +1,97 @@ +{ + inputs.nixpkgs.url = "nixpkgs/nixos-21.11"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.flake-utils.inputs.nixpkgs.follows = "nixpkgs"; + + outputs = { self, nixpkgs, flake-utils }: + let + ebus-rust-derivation = { lib, runCommandNoCC, rustPlatform, pkg-config, openssl }: + rustPlatform.buildRustPackage rec { + name = "ebus-rust"; + # not sure why this hack is needed to make sourceRoot work + src = runCommandNoCC "source" { } '' + mkdir -p $out + cp -r ${./.}/* $out + ''; + cargoLock = { + lockFile = ./ebus-rust/Cargo.lock; + }; + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ openssl ]; + sourceRoot = "source/ebus-rust"; + }; + in + flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + rec { + packages = { + ebus-rust = pkgs.callPackage ebus-rust-derivation { }; + }; + devShell = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + cargo + rustc + pkg-config + rustfmt + rls + clippy + bashInteractive + nixpkgs-fmt + gitFull + xxd + influxdb + # + racket + # + gnumake + libxml2 + libxslt + pandoc + ]; + buildInputs = with pkgs; [ + openssl + ]; + RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + }; + }) + // + { + nixosModules = { + ebus-rust = { config, lib, pkgs, ... }: + let + cfg = config.services.ebus-rust; + ebus-rust = pkgs.callPackage ebus-rust-derivation { }; + in + { + options = { + services.ebus-rust = { + enable = lib.mkEnableOption "enable ebus parser"; + user = lib.mkOption { + default = "root"; + description = "user to run the ebus process"; + }; + device = lib.mkOption { + default = "/dev/ttyUSB0"; + }; + }; + }; + + config = lib.mkIf cfg.enable { + systemd.services.ebus = { + description = "ebus protocol parser and influxdb inserter"; + wantedBy = [ "multi-user.target" ]; + after = [ "networking.target" "influxdb.service" ]; + script = '' + ${pkgs.coreutils}/bin/stty 9600 < ${cfg.device} + RUST_LOG=info ${ebus-rust}/bin/ebus --enhanced influxdb < ${cfg.device} + ''; + serviceConfig = { User = cfg.user; }; + }; + }; + }; + }; + }; +} -- cgit v1.2.1