aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
blob: a7f65c480fb28467541d0d44f5debfa812a556d1 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{
  description = "WebTray Flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };

  outputs =
    { self, nixpkgs }:
    let
      pkgs = import nixpkgs { system = "x86_64-linux"; };
    in
    {
      packages.x86_64-linux.default = pkgs.stdenv.mkDerivation {
        name = "webtray";
        src = self;
        buildPhase = "qmake6 . && make";
        installPhase = "mkdir -p $out/bin; install -t $out/bin webtray";

        buildInputs = [
          pkgs.kdePackages.wrapQtAppsHook
          pkgs.kdePackages.qmake
          pkgs.kdePackages.qtwebengine
          pkgs.kdePackages.qtwayland
        ];
      };

      overlays.default = final: prev: { inherit (self.packages.${prev.system}) webtray; };

      nixosModules.default =
        {
          pkgs,
          lib,
          config,
          ...
        }:
        {
          options.webtray.instances = lib.mkOption {
            type = lib.types.attrsOf (
              lib.types.submodule {
                options = {
                  url = lib.mkOption {
                    description = "URL of the WebTray instance";
                    type = lib.types.strMatching "https?://[a-z0-9.]*";
                  };
                  autoStart = lib.mkOption {
                    description = "WebTray Instances to start on login";
                    type = lib.types.bool;
                    default = true;
                  };
                  openInWindow = lib.mkOption {
                    description = "Open Instance as Window";
                    type = lib.types.bool;
                    default = false;
                  };
                };
              }
            );
          };

          config = {
            environment.systemPackages = [ self.packages.${pkgs.system}.default ];

            systemd.user.services = builtins.mapAttrs (name: value: {
              enable = true;
              after =
                if value.autoStart then
                  [
                    "graphical-session.target"
                    "tray.target"
                  ]
                else
                  [ ];
              wantedBy = [ "default.target" ];
              description = "WebTray Instance for ${name}";
              serviceConfig = {
                Type = "simple";
                ExecStart = "${self.packages.${pkgs.system}.default}/bin/webtray ${value.url}${
                  if value.openInWindow then " --open-at-startup" else ""
                }";
              };
            }) config.webtray.instances;
          };
        };
    };
}