1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 cfg = config.services.ifm;
9in
10{
11 options.services.ifm = {
12 enable = lib.mkEnableOption ''
13 Improved file manager, a single-file web-based filemanager
14
15 Lightweight and minimal, served using PHP's built-in server
16 '';
17
18 dataDir = lib.mkOption {
19 type = lib.types.str;
20 description = "Directory to serve throught the file managing service";
21 };
22
23 listenAddress = lib.mkOption {
24 type = lib.types.str;
25 default = "127.0.0.1";
26 description = "Address on which the service is listening";
27 example = "0.0.0.0";
28 };
29
30 port = lib.mkOption {
31 type = lib.types.port;
32 default = 9090;
33 description = "Port on which to serve the IFM service";
34 };
35
36 settings = lib.mkOption {
37 type = with lib.types; attrsOf anything;
38 default = { };
39 description = ''
40 Configuration of the IFM service.
41
42 See [the documentation](https://github.com/misterunknown/ifm/wiki/Configuration)
43 for available options and default values.
44 '';
45 example = {
46 IFM_GUI_SHOWPATH = 0;
47 };
48 };
49 };
50
51 config = lib.mkIf cfg.enable {
52 systemd.services.ifm = {
53 description = "Improved file manager, a single-file web based filemanager";
54
55 after = [ "network-online.target" ];
56 wantedBy = [ "multi-user.target" ];
57
58 environment = {
59 } // (builtins.mapAttrs (_: val: toString val) cfg.settings);
60
61 serviceConfig = {
62 DynamicUser = true;
63 User = "ifm";
64 StandardOutput = "journal";
65 BindPaths = "${cfg.dataDir}:/data";
66 PrivateTmp = true;
67 ExecStart = "${lib.getExe pkgs.ifm-web} ${lib.escapeShellArg cfg.listenAddress} ${builtins.toString cfg.port} /data";
68 };
69 };
70 };
71
72 meta.maintainers = with lib.maintainers; [ litchipi ];
73}