diff options
author | Yves Fischer <yvesf+git@xapek.org> | 2021-12-31 23:57:29 +0100 |
---|---|---|
committer | Yves Fischer <yvesf+git@xapek.org> | 2021-12-31 23:57:29 +0100 |
commit | d0c7100b706d70dfff342def2bac864693fe8544 (patch) | |
tree | 333268ca977222e2f5a41eff68607b36721f7694 /flake.nix | |
parent | caae83f445935c06cd6aef36f283a4688675278a (diff) | |
parent | 810721ceac0249e747cdf36f3edec22d829d4371 (diff) | |
download | ebus-d0c7100b706d70dfff342def2bac864693fe8544.tar.gz ebus-d0c7100b706d70dfff342def2bac864693fe8544.zip |
Diffstat (limited to 'flake.nix')
-rw-r--r-- | flake.nix | 97 |
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; }; + }; + }; + }; + }; + }; +} |