about summary refs log tree commit diff
path: root/nixos/modules/services/web-apps/ifm.nix
blob: d5621866a9a3cd8eb79d1910b214791efd20f62b (plain) (blame)
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
{ config, lib, pkgs, ...}:
let
  cfg = config.services.ifm;

  version = "4.0.2";
  src = pkgs.fetchurl {
    url = "https://github.com/misterunknown/ifm/releases/download/v${version}/cdn.ifm.php";
    hash = "sha256-37WbRM6D7JGmd//06zMhxMGIh8ioY8vRUmxX4OHgqBE=";
  };

  php = pkgs.php83;
in {
  options.services.ifm = {
    enable = lib.mkEnableOption ''
      Improved file manager, a single-file web-based filemanager

      Lightweight and minimal, served using PHP's built-in server
  '';

    dataDir = lib.mkOption {
      type = lib.types.str;
      description = "Directory to serve throught the file managing service";
    };

    listenAddress = lib.mkOption {
      type = lib.types.str;
      default = "127.0.0.1";
      description = "Address on which the service is listening";
      example = "0.0.0.0";
    };

    port = lib.mkOption {
      type = lib.types.port;
      default = 9090;
      description = "Port on which to serve the IFM service";
    };

    settings = lib.mkOption {
      type = with lib.types; attrsOf anything;
      default = {};
      description = ''
        Configuration of the IFM service.

        See [the documentation](https://github.com/misterunknown/ifm/wiki/Configuration)
        for available options and default values.
      '';
      example = {
        IFM_GUI_SHOWPATH = 0;
      };
    };
  };

  config = lib.mkIf cfg.enable {
    systemd.services.ifm = {
      description = "Improved file manager, a single-file web based filemanager";

      after = [ "network-online.target" ];
      wantedBy = [ "multi-user.target" ];

      environment = {
        IFM_ROOT_DIR = "/data";
      } // (builtins.mapAttrs (_: val: toString val) cfg.settings);

      script = ''
        mkdir -p /tmp/ifm
        ln -s ${src} /tmp/ifm/index.php
        ${lib.getExe php} -S ${cfg.listenAddress}:${builtins.toString cfg.port} -t /tmp/ifm
      '';

      serviceConfig = {
        DynamicUser = true;
        User = "ifm";
        StandardOutput = "journal";
        BindPaths = "${cfg.dataDir}:/data";
        PrivateTmp = true;
      };
    };
  };

  meta.maintainers = with lib.maintainers; [ litchipi ];
}