summaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
authorYves Fischer <yvesf+git@xapek.org>2021-12-31 23:57:29 +0100
committerYves Fischer <yvesf+git@xapek.org>2021-12-31 23:57:29 +0100
commitd0c7100b706d70dfff342def2bac864693fe8544 (patch)
tree333268ca977222e2f5a41eff68607b36721f7694 /flake.nix
parentcaae83f445935c06cd6aef36f283a4688675278a (diff)
parent810721ceac0249e747cdf36f3edec22d829d4371 (diff)
downloadebus-master.tar.gz
ebus-master.zip
Merge branch 'ebus-rust'HEADmaster
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix97
1 files changed, 97 insertions, 0 deletions
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; };
+ };
+ };
+ };
+ };
+ };
+}