Skip to content

Commit

Permalink
Merge pull request #334559 from litchipi/ifm_fixup
Browse files Browse the repository at this point in the history
ifm-web: init at 4.0.2
  • Loading branch information
pbsds authored Aug 23, 2024
2 parents 9bd0eef + ef03964 commit d38f701
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 20 deletions.
2 changes: 1 addition & 1 deletion nixos/doc/manual/release-notes/rl-2411.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

- [Misskey](https://misskey-hub.net/en/), an interplanetary microblogging platform. Available as [services.misskey](options.html#opt-services.misskey).

- [Improved File Manager](https://github.com/misterunknown/ifm), or IFM, a single-file web-based file manager.
- [Improved File Manager](https://github.com/misterunknown/ifm), or IFM, a single-file web-based file manager. Available as [services.ifm](options.html#opt-services.ifm.enable)

- [OpenGFW](https://github.com/apernet/OpenGFW), an implementation of the Great Firewall on Linux. Available as [services.opengfw](#opt-services.opengfw.enable).

Expand Down
30 changes: 11 additions & 19 deletions nixos/modules/services/web-apps/ifm.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
{ config, lib, pkgs, ...}:
{
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 {
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;
Expand All @@ -37,7 +35,7 @@ in {

settings = lib.mkOption {
type = with lib.types; attrsOf anything;
default = {};
default = { };
description = ''
Configuration of the IFM service.
Expand All @@ -58,21 +56,15 @@ in {
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;
ExecStart = "${lib.getExe pkgs.ifm-web} ${lib.escapeShellArg cfg.listenAddress} ${builtins.toString cfg.port} /data";
};
};
};
Expand Down
55 changes: 55 additions & 0 deletions pkgs/by-name/if/ifm-web/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
fetchurl,
stdenv,
lib,
php83,
writeShellScript,
nixosTests,
}:
let
version = "4.0.2";
src = fetchurl {
url = "https://github.com/misterunknown/ifm/releases/download/v${version}/cdn.ifm.php";
hash = "sha256-37WbRM6D7JGmd//06zMhxMGIh8ioY8vRUmxX4OHgqBE=";
};

serve_script = writeShellScript "ifm-serve" ''
if [ $# -ne 3 ]; then
echo "Usage: $0 <listen address> <port> <data directory>";
exit 1;
fi
SERVE_DIR=$(dirname "$0")/../php/
IFM_ROOT_DIR="$3" ${lib.getExe php83} -S "$1:$2" -t "$SERVE_DIR"
'';
in
stdenv.mkDerivation {
pname = "ifm";
inherit version src;

dontUnpack = true;

installPhase = ''
runHook preInstall
mkdir -p $out/bin $out/php
cp $src $out/php/index.php
cp ${serve_script} $out/bin/ifm
runHook postInstall
'';

passthru.tests = {
inherit (nixosTests) ifm;
};

meta = {
description = "Improved File Manager, a single-file web-based filemanager";
longDescription = ''
The IFM is a web-based filemanager, which comes as a single file solution using HTML5, CSS3, JavaScript and PHP.
'';
homepage = "https://github.com/misterunknown/ifm";
changelog = "https://github.com/misterunknown/ifm/releases/tag/v${version}";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ litchipi ];
mainProgram = "ifm";
};
}

0 comments on commit d38f701

Please sign in to comment.