summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYves Fischer <yvesf+git@xapek.org>2021-12-31 23:53:52 +0100
committerYves Fischer <yvesf+git@xapek.org>2021-12-31 23:57:06 +0100
commit810721ceac0249e747cdf36f3edec22d829d4371 (patch)
tree333268ca977222e2f5a41eff68607b36721f7694
parent76f8611ee3345268e2091a9d2e81b53a8b05889c (diff)
downloadebus-810721ceac0249e747cdf36f3edec22d829d4371.tar.gz
ebus-810721ceac0249e747cdf36f3edec22d829d4371.zip
ebus-rust nixos package
-rw-r--r--README.md16
-rw-r--r--ebus-rust/flake.nix31
-rw-r--r--ebus-xml/Makefile6
-rw-r--r--flake.lock (renamed from ebus-rust/flake.lock)14
-rw-r--r--flake.nix97
5 files changed, 123 insertions, 41 deletions
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.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/ebus-rust/flake.lock b/flake.lock
index 1114d39..158c6a7 100644
--- a/ebus-rust/flake.lock
+++ b/flake.lock
@@ -2,11 +2,11 @@
"nodes": {
"flake-utils": {
"locked": {
- "lastModified": 1631561581,
- "narHash": "sha256-3VQMV5zvxaVLvqqUrNz3iJelLw30mIVSfZmAaauM3dA=",
+ "lastModified": 1638122382,
+ "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=",
"owner": "numtide",
"repo": "flake-utils",
- "rev": "7e5bf3925f6fbdfaf50a2a7ca0be2879c4261d19",
+ "rev": "74f7e4319258e287b0f9cb95426c9853b282730b",
"type": "github"
},
"original": {
@@ -17,16 +17,16 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1633709683,
- "narHash": "sha256-KVJEToVd6SuUqc2XFIpfSjns07orqEWzIq9AcF/SIf8=",
+ "lastModified": 1640887906,
+ "narHash": "sha256-Eupk1UlNicCD2UNZuEKt6yhE6kFWAxXM/HyziOjG9CA=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "ce7a1190a0fa4ba3465b5f5471b08567060ca14c",
+ "rev": "8a053bc2255659c5ca52706b9e12e76a8f50dbdd",
"type": "github"
},
"original": {
"id": "nixpkgs",
- "ref": "nixos-21.05",
+ "ref": "nixos-21.11",
"type": "indirect"
}
},
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; };
+ };
+ };
+ };
+ };
+ };
+}