From 470802003ab42eefc91c3028c5c1a0732a718cde Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Fri, 3 Mar 2023 13:42:06 -0800 Subject: [PATCH] flake: Add module to configure daemon --- flake.nix | 17 ++++++++++++----- module.nix | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 module.nix diff --git a/flake.nix b/flake.nix index 7f458a0..f81aade 100644 --- a/flake.nix +++ b/flake.nix @@ -14,6 +14,9 @@ outputs = { self, nixpkgs, flake-utils, rust-overlay, crane }: let + inherit (nixpkgs) lib; + inherit (flake-utils.lib) eachSystem system; + overlays = [ (import rust-overlay) # Build Rust toolchain with helpers from rust-overlay @@ -22,7 +25,11 @@ }) ]; in - flake-utils.lib.eachDefaultSystem + { + nixosModules.hw-gauge-daemon = import ./module.nix self; + nixosModules.default = self.nixosModules.hw-gauge-daemon; + } // + eachSystem [ system.x86_64-linux ] (system: let pkgs = import nixpkgs { inherit overlays system; }; @@ -32,6 +39,10 @@ scripts = import ./scripts.nix { inherit pkgs; }; in { + packages = { + daemon = code.daemon; + }; + devShells.default = pkgs.mkShell { buildInputs = with pkgs; [ flip-link @@ -47,9 +58,5 @@ scripts.daemon.linux.ci ]; }; - - packages = { - daemon = code.daemon; - }; }); } diff --git a/module.nix b/module.nix new file mode 100644 index 0000000..15686ea --- /dev/null +++ b/module.nix @@ -0,0 +1,28 @@ +flake: { config, lib, pkgs, self, ... }: +with lib; let + cfg = config.services.hw-gauge-daemon; +in +{ + options.services.hw-gauge-daemon = { + enable = mkEnableOption "Enable the hw-gauge daemon to display HW info"; + + package = mkOption { + type = types.package; + default = flake.packages.${pkgs.system}.daemon; + }; + }; + + config = mkIf cfg.enable { + systemd.services.hw-gauge-daemon = { + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + ExecStart = "${cfg.package}/bin/hw-gauge-daemon"; + DynamicUser = "yes"; + Group = "dialout"; + Restart = "on-failure"; + }; + }; + }; +} +