summaryrefslogtreecommitdiff
path: root/flake.nix
blob: c187dd97d68dba28bbb0ef46cf5b3269d76de84c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{
  outputs = { ... }:
    let
      batteriewarner = { lib, rustPlatform, makeWrapper }:
        rustPlatform.buildRustPackage rec {
          name = "batteriewarner-${version}";
          version = "2022-08-25";
          src = ./.;
          cargoLock.lockFile = ./Cargo.lock;
          buildInputs = [ makeWrapper ];
          meta = {
            description = "Display low battery status using the power led of Thinkpads X-series";
            homepage = https://github.com/yvesf/batteriewarner;
            platforms = lib.platforms.all;
          };
        };
    in
    {
      nixosModule = { config, lib, pkgs, ... }:
        let
          package = pkgs.callPackage batteriewarner { };
          cfg = config.services.batteriewarner;
        in
        {
          options.services.batteriewarner.enable = lib.mkEnableOption "Batteriewarner";
          config = lib.mkIf cfg.enable {
            systemd.services.batteriewarner = {
              enable = true;
              description = "Batteriewarner";
              wantedBy = [ "multi-user.target" ];
              serviceConfig.ExecStart = "${package}/bin/batteriewarner";
            };
          };
        };
    };
}