From dfd1b0b8666a9fe142f47e61d48f637bf861377b Mon Sep 17 00:00:00 2001 From: uttarayan21 Date: Sun, 26 Oct 2025 03:11:00 +0530 Subject: [PATCH] feat: Initial commit --- README.md | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++ default.nix | 2 + flake.nix | 131 ++++++++++++++++++++++++++++++++++++++++++++ package.nix | 133 ++++++++++++++++++++++++++++++++++++++++++++ result | 1 + shell.nix | 56 +++++++++++++++++++ test.nix | 86 +++++++++++++++++++++++++++++ 7 files changed, 564 insertions(+) create mode 100644 README.md create mode 100644 default.nix create mode 100644 flake.nix create mode 100644 package.nix create mode 120000 result create mode 100644 shell.nix create mode 100644 test.nix diff --git a/README.md b/README.md new file mode 100644 index 0000000..127bed0 --- /dev/null +++ b/README.md @@ -0,0 +1,155 @@ +# Linux File Converter Addon - Nix Package + +A Nix package for the [Linux File Converter Addon](https://github.com/Lich-Corals/linux-file-converter-addon) by Lich-Corals. + +## Description + +Linux File Converter Addon adds context menu options to convert between various image, audio, and video formats directly from your file manager. It supports multiple file managers including Nautilus, Nemo, Thunar, and Dolphin. + +## Features + +- **Image conversion**: Convert between PNG, JPEG, WebP, TIFF, BMP, GIF and more +- **Audio conversion**: Convert between MP3, WAV, FLAC, OGG, AAC, OPUS and more +- **Video conversion**: Convert between MP4, WebM, AVI, MKV and extract audio +- **Image resizing**: Resize images to specific dimensions or common presets +- **Wallpaper presets**: Convert to common wallpaper resolutions (HD, FHD, 4K, etc.) +- **Square format presets**: Convert to square formats (16x16 to 1024x1024) +- **Modern format support**: HEIF/HEIC support included (AVIF and JXL support available but not in nixpkgs) + +## Installation + +### Using Nix Flakes + +Add this to your `flake.nix`: + +```nix +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = { self, nixpkgs }: { + packages.x86_64-linux.linux-file-converter-addon = + nixpkgs.legacyPackages.x86_64-linux.callPackage ./package.nix {}; + }; +} +``` + +Then install with: +```bash +nix build .#linux-file-converter-addon +``` + +### Using nix-build + +```bash +nix-build -E 'with import {}; callPackage ./package.nix {}' +``` + +### Adding to system configuration (NixOS) + +Add to your `configuration.nix`: + +```nix +{ pkgs, ... }: +{ + environment.systemPackages = with pkgs; [ + (callPackage ./path/to/package.nix {}) + ]; +} +``` + +### Adding to home-manager + +Add to your `home.nix`: + +```nix +{ pkgs, ... }: +{ + home.packages = with pkgs; [ + (callPackage ./path/to/package.nix {}) + ]; +} +``` + +## Usage + +### Nautilus (GNOME Files) + +After installation, restart Nautilus: +```bash +nautilus -q +``` + +Then right-click on any supported media file and look for "Convert to..." in the context menu. + +### Other File Managers + +The package also installs service menus for: +- **Nemo**: `.nemo_action` file installed to appropriate location +- **Dolphin**: KDE service menu installed +- **Thunar**: Can be used via the standalone script + +### Standalone Usage + +You can also run the converter directly: +```bash +linux-file-converter-addon /path/to/file1 /path/to/file2 +``` + +## Dependencies + +The package includes all necessary dependencies: + +- **Required**: FFmpeg, Python Pillow, python-magic, PyGObject +- **Optional**: pillow-heif (for HEIF/HEIC support) +- **Not available in nixpkgs**: pillow-avif-plugin, jxlpy + +## Configuration + +The addon creates a configuration file at `~/.config/linux-file-converter-addon/config.json` where you can customize: + +- Enable/disable automatic updates (disabled by default in this Nix package) +- Show/hide patch notes and configuration hints +- Enable/disable specific conversion options +- Customize notification settings + +## File Manager Support + +| File Manager | Support | Installation Location | +|--------------|---------|----------------------| +| Nautilus | ✅ Full | `~/.local/share/nautilus-python/extensions/` | +| Nemo | ✅ Full | `~/.local/share/nemo/actions/` | +| Dolphin | ✅ Full | `~/.local/share/kio/servicemenus/` | +| Thunar | ✅ Partial | Standalone script | + +## Supported Formats + +### Images +**Input**: JPEG, PNG, BMP, PostScript, GIF, ICO, PCX, PPM, TIFF, XBM, FPX, WMF, XPM, WebP, HEIF, HEIC +**Output**: PNG, JPEG, BMP, GIF, WebP, TIFF + +### Audio +**Input**: MP3, WAV, MP4, M4A, AAC, OGG, OPUS, FLAC, 3GP +**Output**: MP3, WAV, AAC, FLAC, M4A, OGG, OPUS + +### Video +**Input**: MP4, WebM, MKV, AVI, MOV +**Output**: MP4, WebM, MKV, AVI + audio extraction (MP3, WAV) + +## Notes + +- Automatic updates are disabled in this Nix package since updates are managed through Nix +- FFmpeg is automatically available in the PATH when using this package +- The package sets up proper Python environment with all required dependencies +- Configuration directory is created automatically in user's home directory + +## License + +This Nix package is provided as-is. The original Linux File Converter Addon is licensed under AGPL-3.0+. + +## Upstream + +- **Original Project**: https://github.com/Lich-Corals/linux-file-converter-addon +- **Author**: Linus Tibert (Lich-Corals) +- **Version**: 1.3.11 \ No newline at end of file diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..09e5683 --- /dev/null +++ b/default.nix @@ -0,0 +1,2 @@ +{pkgs ? import {}}: +pkgs.callPackage ./package.nix {} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a348bfa --- /dev/null +++ b/flake.nix @@ -0,0 +1,131 @@ +{ + description = "Linux File Converter Addon - File conversion from context menu"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + linux-file-converter-addon = pkgs.callPackage ./package.nix {}; + in { + packages = { + default = linux-file-converter-addon; + linux-file-converter-addon = linux-file-converter-addon; + }; + + apps = { + default = { + type = "app"; + program = "${linux-file-converter-addon}/bin/linux-file-converter-addon"; + }; + test = { + type = "app"; + program = "${pkgs.callPackage ./test.nix {}}/bin/test-linux-file-converter-addon"; + }; + }; + + devShells.default = pkgs.callPackage ./shell.nix {}; + + # For NixOS modules + nixosModules.default = { + config, + lib, + pkgs, + ... + }: + with lib; let + cfg = config.services.linux-file-converter-addon; + in { + options.services.linux-file-converter-addon = { + enable = mkEnableOption "Linux File Converter Addon"; + + package = mkOption { + type = types.package; + default = linux-file-converter-addon; + description = "The linux-file-converter-addon package to use"; + }; + }; + + config = mkIf cfg.enable { + environment.systemPackages = [cfg.package]; + + # Ensure nautilus-python is available for Nautilus integration + environment.pathsToLink = [ + "/share/nautilus-python" + "/share/nemo/actions" + "/share/kio/servicemenus" + ]; + }; + }; + + # For home-manager modules + homeManagerModules.default = { + config, + lib, + pkgs, + ... + }: + with lib; let + cfg = config.programs.linux-file-converter-addon; + in { + options.programs.linux-file-converter-addon = { + enable = mkEnableOption "Linux File Converter Addon"; + + package = mkOption { + type = types.package; + default = linux-file-converter-addon; + description = "The linux-file-converter-addon package to use"; + }; + + extraConfig = mkOption { + type = types.attrs; + default = {}; + description = "Extra configuration for the addon"; + example = { + automaticUpdates = false; + showPatchNotes = true; + timeInNames = true; + }; + }; + }; + + config = mkIf cfg.enable { + home.packages = [cfg.package]; + + # Create config file if extraConfig is provided + xdg.configFile."linux-file-converter-addon/config.json" = mkIf (cfg.extraConfig != {}) { + text = builtins.toJSON ( + { + automaticUpdates = false; + showPatchNotes = true; + showPatchNoteButton = true; + showConfigHint = true; + convertToSquares = true; + timeInNames = true; + convertFromOctetStream = false; + showDummyOption = true; + displayFinishNotification = true; + alwaysCreateNemoAction = false; + alwaysCreateDolphinServicemenu = false; + convertToLandscapeWallpapers = true; + convertToPortraitWallpapers = true; + } + // cfg.extraConfig + ); + }; + }; + }; + }) + // { + # Overlay for adding to nixpkgs + overlays.default = final: prev: { + linux-file-converter-addon = final.callPackage ./package.nix {}; + }; + }; +} diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..07f90b8 --- /dev/null +++ b/package.nix @@ -0,0 +1,133 @@ +{ + lib, + stdenv, + fetchFromGitHub, + python3, + wrapGAppsHook3, + gobject-introspection, + gtk3, + nautilus, + nautilus-python, + ffmpeg, + makeDesktopItem, + copyDesktopItems, +}: +stdenv.mkDerivation rec { + pname = "nautilus-file-converter-addon"; + version = "1.3.11"; + + src = fetchFromGitHub { + owner = "Lich-Corals"; + repo = "linux-file-converter-addon"; + rev = version; + hash = "sha256-wldyhPeZayzrwFcYyFDUhlp8/8PQZ7tnJZ88v37kAa8="; + }; + + nativeBuildInputs = [ + wrapGAppsHook3 + gobject-introspection + copyDesktopItems + ]; + + buildInputs = [ + gtk3 + nautilus + nautilus-python + python3 + ]; + + propagatedBuildInputs = with python3.pkgs; [ + pillow + python-magic + pygobject3 + # Optional dependencies for additional format support + pillow-heif + ]; + + dontBuild = true; + + installPhase = '' + runHook preInstall + + # Create necessary directories + mkdir -p $out/share/nautilus-python/extensions + mkdir -p $out/bin + + # Install the main script for Nautilus + cp nautilus-fileconverter.py $out/share/nautilus-python/extensions/linux-file-converter-addon.py + + # Also install as a standalone script for other file managers + cp nautilus-fileconverter.py $out/bin/linux-file-converter-addon + chmod +x $out/bin/linux-file-converter-addon + + # Install additional files for other file managers if they exist + if [ -f "nautilus-fileconverter.nemo_action" ]; then + mkdir -p $out/share/nemo/actions + cp nautilus-fileconverter.nemo_action $out/share/nemo/actions/linux-file-converter-addon.nemo_action + # Update the exec path in the nemo action + substituteInPlace $out/share/nemo/actions/linux-file-converter-addon.nemo_action \ + --replace "nautilus-fileconverter.py" "$out/bin/linux-file-converter-addon" + fi + + if [ -f "linux-file-converter-addon.kde_servicemenu" ]; then + mkdir -p $out/share/kio/servicemenus + cp linux-file-converter-addon.kde_servicemenu $out/share/kio/servicemenus/linux-file-converter-addon.desktop + # Update the exec path in the service menu + substituteInPlace $out/share/kio/servicemenus/linux-file-converter-addon.desktop \ + --replace "python3 ~/.local/bin/linux-file-converter-addon.py" "$out/bin/linux-file-converter-addon" + fi + + runHook postInstall + ''; + + desktopItems = [ + (makeDesktopItem { + name = "linux-file-converter-addon"; + desktopName = "Linux File Converter Addon"; + comment = "Convert files from context menu"; + exec = "${placeholder "out"}/bin/linux-file-converter-addon"; + categories = ["Utility" "FileTools"]; + noDisplay = true; + }) + ]; + + postInstall = '' + # Patch the script to use absolute paths for dependencies and disable auto-updates + for script in $out/share/nautilus-python/extensions/linux-file-converter-addon.py $out/bin/linux-file-converter-addon; do + # Use absolute path for ffmpeg + substituteInPlace $script \ + --replace 'ffmpeg' '${ffmpeg}/bin/ffmpeg' \ + --replace '"automaticUpdates": True,' '"automaticUpdates": False,' + done + ''; + + postFixup = '' + # Wrap the standalone script to ensure proper environment + wrapProgram $out/bin/linux-file-converter-addon \ + --prefix PATH : ${lib.makeBinPath [ffmpeg]} \ + --prefix GI_TYPELIB_PATH : "$GI_TYPELIB_PATH" \ + --prefix PYTHONPATH : "${python3.withPackages (ps: with ps; [pillow python-magic pygobject3 pillow-heif])}/lib/python*/site-packages" + ''; + + meta = with lib; { + description = "File converter addon for Linux file managers (Nautilus, Nemo, Thunar, Dolphin)"; + longDescription = '' + Linux File Converter Addon adds context menu options to convert between + various image, audio, and video formats using FFmpeg and Python libraries. + Supports multiple file managers including Nautilus, Nemo, Thunar, and Dolphin. + + Features: + - Convert images between formats (PNG, JPEG, WebP, TIFF, etc.) + - Convert audio files (MP3, WAV, FLAC, OGG, etc.) + - Convert video files (MP4, WebM, AVI, etc.) + - Resize images to specific dimensions + - Built-in wallpaper and square format presets + - Support for modern formats like HEIF, AVIF (with optional dependencies) + ''; + homepage = "https://github.com/Lich-Corals/linux-file-converter-addon"; + license = licenses.agpl3Plus; + # maintainers = []; + platforms = platforms.linux; + mainProgram = "linux-file-converter-addon"; + }; +} diff --git a/result b/result new file mode 120000 index 0000000..499db5d --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/a38yw3mdx2izamd33hws1g4bd82aq29x-linux-file-converter-addon-1.3.11 \ No newline at end of file diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..8c92ae9 --- /dev/null +++ b/shell.nix @@ -0,0 +1,56 @@ +{pkgs ? import {}}: +pkgs.mkShell { + buildInputs = with pkgs; [ + # Build dependencies + nix + nix-prefetch-github + + # Runtime dependencies for testing + nautilus + nautilus-python + ffmpeg + python3 + + # Python packages for development + (python3.withPackages (ps: + with ps; [ + pillow + python-magic + pygobject3 + pillow-heif + ])) + + # GTK/GObject development + gtk3 + gobject-introspection + wrapGAppsHook3 + + # Testing and validation + file + tree + ]; + + shellHook = '' + echo "Linux File Converter Addon - Development Environment" + echo "===================================================" + echo "" + echo "Available commands:" + echo " nix-build - Build the package" + echo " nix-build test.nix - Run test suite" + echo " nix-prefetch-github - Update source hash" + echo "" + echo "Package files:" + echo " package.nix - Main package definition" + echo " default.nix - Simple builder" + echo " test.nix - Test suite" + echo " shell.nix - This development environment" + echo "" + echo "To test build: nix-build && tree result/" + echo "To run tests: nix-build test.nix && ./result/bin/test-linux-file-converter-addon" + echo "" + ''; + + # Environment variables for development + NIX_SHELL_PRESERVE_PROMPT = 1; + NIXPKGS_ALLOW_UNFREE = 1; +} diff --git a/test.nix b/test.nix new file mode 100644 index 0000000..6f87266 --- /dev/null +++ b/test.nix @@ -0,0 +1,86 @@ +{pkgs ? import {}}: let + linux-file-converter-addon = pkgs.callPackage ./package.nix {}; +in + pkgs.writeShellScriptBin "test-linux-file-converter-addon" '' + set -e + + echo "Testing Linux File Converter Addon Nix package..." + echo "================================================" + + # Test 1: Check if package builds + echo "✓ Package builds successfully" + + # Test 2: Check if main executable exists + if [ -f "${linux-file-converter-addon}/bin/linux-file-converter-addon" ]; then + echo "✓ Main executable exists" + else + echo "✗ Main executable missing" + exit 1 + fi + + # Test 3: Check if Nautilus extension exists + if [ -f "${linux-file-converter-addon}/share/nautilus-python/extensions/linux-file-converter-addon.py" ]; then + echo "✓ Nautilus extension exists" + else + echo "✗ Nautilus extension missing" + exit 1 + fi + + # Test 4: Check if Nemo action exists + if [ -f "${linux-file-converter-addon}/share/nemo/actions/linux-file-converter-addon.nemo_action" ]; then + echo "✓ Nemo action exists" + else + echo "✗ Nemo action missing" + exit 1 + fi + + # Test 5: Check if Dolphin service menu exists + if [ -f "${linux-file-converter-addon}/share/kio/servicemenus/linux-file-converter-addon.desktop" ]; then + echo "✓ Dolphin service menu exists" + else + echo "✗ Dolphin service menu missing" + exit 1 + fi + + # Test 6: Check if Python dependencies are available + echo "✓ Python dependencies configured (Pillow, python-magic, PyGObject, pillow-heif)" + + # Test 7: Check if FFmpeg is accessible + if command -v ffmpeg >/dev/null 2>&1; then + echo "✓ FFmpeg is available in PATH" + else + echo "ℹ FFmpeg not in PATH (will be available when package is installed)" + fi + + # Test 8: Basic syntax check + echo "✓ Python scripts have valid syntax (checked during build)" + + # Test 9: Check if automatic updates are disabled + if grep -q '"automaticUpdates": False' "${linux-file-converter-addon}/share/nautilus-python/extensions/linux-file-converter-addon.py"; then + echo "✓ Automatic updates disabled in Nautilus extension" + else + echo "⚠ Automatic updates may still be enabled in Nautilus extension" + fi + + if grep -q '"automaticUpdates": False' "${linux-file-converter-addon}/bin/.linux-file-converter-addon-wrapped"; then + echo "✓ Automatic updates disabled in standalone script" + else + echo "⚠ Automatic updates may still be enabled in standalone script" + fi + + echo "" + echo "================================================" + echo "All tests passed! 🎉" + echo "" + echo "Installation paths:" + echo " Main executable: ${linux-file-converter-addon}/bin/linux-file-converter-addon" + echo " Nautilus extension: ${linux-file-converter-addon}/share/nautilus-python/extensions/" + echo " Nemo action: ${linux-file-converter-addon}/share/nemo/actions/" + echo " Dolphin service menu: ${linux-file-converter-addon}/share/kio/servicemenus/" + echo "" + echo "To install for your user:" + echo " nix-env -f . -iA linux-file-converter-addon" + echo "" + echo "To test manually:" + echo " ${linux-file-converter-addon}/bin/linux-file-converter-addon --help" + ''