fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
2.1 KiB82 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.flameshot;
8
9  iniFormat = pkgs.formats.ini { };
10
11  iniFile = iniFormat.generate "flameshot.ini" cfg.settings;
12
13in {
14  meta.maintainers = [ maintainers.hamhut1066 ];
15
16  options.services.flameshot = {
17    enable = mkEnableOption "Flameshot";
18
19    package = mkOption {
20      type = types.package;
21      default = pkgs.flameshot;
22      defaultText = literalExpression "pkgs.flameshot";
23      description = "Package providing {command}`flameshot`.";
24    };
25
26    settings = mkOption {
27      type = iniFormat.type;
28      default = { };
29      example = {
30        General = {
31          disabledTrayIcon = true;
32          showStartupLaunchMessage = false;
33        };
34      };
35      description = ''
36        Configuration to use for Flameshot. See
37        <https://github.com/flameshot-org/flameshot/blob/master/flameshot.example.ini>
38        for available options.
39      '';
40    };
41  };
42
43  config = mkIf cfg.enable {
44    assertions = [
45      (lib.hm.assertions.assertPlatform "services.flameshot" pkgs
46        lib.platforms.linux)
47    ];
48
49    home.packages = [ cfg.package ];
50
51    xdg.configFile = mkIf (cfg.settings != { }) {
52      "flameshot/flameshot.ini".source = iniFile;
53    };
54
55    systemd.user.services.flameshot = {
56      Unit = {
57        Description = "Flameshot screenshot tool";
58        Requires = [ "tray.target" ];
59        After = [ "graphical-session-pre.target" "tray.target" ];
60        PartOf = [ "graphical-session.target" ];
61        X-Restart-Triggers = mkIf (cfg.settings != { }) [ "${iniFile}" ];
62      };
63
64      Install = { WantedBy = [ "graphical-session.target" ]; };
65
66      Service = {
67        Environment = "PATH=${config.home.profileDirectory}/bin";
68        ExecStart = "${cfg.package}/bin/flameshot";
69        Restart = "on-abort";
70
71        # Sandboxing.
72        LockPersonality = true;
73        MemoryDenyWriteExecute = true;
74        NoNewPrivileges = true;
75        PrivateUsers = true;
76        RestrictNamespaces = true;
77        SystemCallArchitectures = "native";
78        SystemCallFilter = "@system-service";
79      };
80    };
81  };
82}