summaryrefslogtreecommitdiff
path: root/home-modules/quickshell.nix
blob: dac7089f4c652a285af1032d445d63e529839506 (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
{ config, pkgs, lib, ... }:

let
  cfg = config.programs.quickshell;
in {
  disabledModules = ["programs/quickshell.nix"];

  options = {
    programs.quickshell = {
      enable = lib.mkEnableOption "quickshell";
      package = lib.mkPackageOption pkgs "quickshell" { nullable = true; };
      config.src = lib.mkOption {
        type = lib.types.path;
      };
      config.replacements = lib.mkOption {
        type = lib.types.attrsOf lib.types.str;
        default = {};
      };
    };
  };

  config = lib.mkIf cfg.enable {
    home.packages = [ cfg.package ];

    xdg.configFile."quickshell".source = pkgs.stdenvNoCC.mkDerivation {
      name = "quickshell";
      preferLocalBuild = true;
      allowSubstitutes = false;
      dontUnpack = true;
      inherit (cfg.config) src;
      buildPhase = ''
        runHook preBuild

        while IFS= read -r -d $'\0' file <&3; do
          [[ -z $file ]] && continue

          mkdir -p "$out"/"$(dirname "$file")"
          substitute "$src"/"$file" "$out"/"$file" \
            ${lib.concatStringsSep " " (
              lib.concatLists (lib.mapAttrsToList (name: value: [
                "--replace-quiet" (lib.escapeShellArg "@${name}@") (lib.escapeShellArg value)
              ]) cfg.config.replacements)
            )}
        done 3< <(find "$src" -type f -printf '%P\0')

        runHook postBuild
      '';
    };

    systemd.user.services.quickshell = {
      Unit = {
        Description = "quickshell";
        Documentation = "https://quickshell.org/docs/v${cfg.package.version}";
        PartOf = [ "graphical-session.target" ];
        After = [ "graphical-session-pre.target" ];
      };

      Service = {
        ExecStart = lib.getExe cfg.package;
        Restart = "always";
      };

      Install = {
        WantedBy = [ "graphical-session.target" ];
      };
    };
  };
}