diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b63bd9..51f0c68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -468,3 +468,9 @@ install( DESTINATION share/licenses/${PROJECT_NAME} COMPONENT documentation ) + +install( + FILES oshot.desktop + DESTINATION share/applications + COMPONENT documentation +) diff --git a/README.md b/README.md index 91caea4..e0c2798 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,31 @@ If when starting oshot, it starts to flick a screen black (or it won't launch), If still errors, please open an [Issue](https://github.com/Toni500github/oshot/issues) and take a screenshot/paste the text of the error appearing in the console when executing oshot +### NixOS +On NixOS, TESSDATA_PREFIX will need to be set for oshot to find the languages. +You have two ways to do this, depending on how you installed tesseract. + +If you installed tesseract in `environment.systemPackages`, set the following variable: +```nix +environment.sessionVariables = { + # Change tesseract to tesseract5 if that's the package you used. + "TESSDATA_PREFIX" = "${pkgs.tesseract}/share/tessdata"; +}; +``` + +If you installed tesseract in `users.users..packages`, you could use the above method, but it's better you use home-manager. +If you have home-manager, add this in your home.nix: +```nix +systemd.user.sessionVariables = { + # Change tesseract to tesseract5 if that's the package you used. + "TESSDATA_PREFIX" = "${pkgs.tesseract}/share/tessdata"; +}; +``` + +> **__Notice:__** If you're not using systemd, the home-manager solution won't work. We assume you'll be able to find a replacement yourself if you're not using systemd. + +If this doesn't work, while `echo $TESSDATA_PREFIX` returns a valid result, check your config file. + ## Usage https://github.com/user-attachments/assets/8367490a-f7b0-4320-86e9-8ef8764a56b5 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ed20e51 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1781074563, + "narHash": "sha256-md8WlXOlfnIeHeOScMTTHFyf2d6iaTwPl2apR5EQ3P4=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "9ae611a455b90cf061d8f332b977e387bda8e1ca", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..55f9c65 --- /dev/null +++ b/flake.nix @@ -0,0 +1,30 @@ +{ + description = "Nix flake for oshot; a simple and lightweight tool for extracting text from a screenshot/image (on the fly)"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + }; + + outputs = { self, nixpkgs }: { + packages.x86_64-linux.oshot = + with import nixpkgs { system = "x86_64-linux"; }; + stdenv.mkDerivation { + name = "oshot"; + src = self; + nativeBuildInputs = [ cmake gnumake pkg-config git ]; + buildInputs = [ glfw3 leptonica libx11.dev tesseract zbar.dev libappindicator-gtk3.dev dbus.dev systemd.dev libsysprof-capture pcre2.dev libxdmcp.dev libuuid.dev libselinux.dev libsepol.dev libthai.dev libdatrie.dev libdeflate lerc.dev xz.dev zstd.dev libwebp libxkbcommon.dev libepoxy.dev libxtst giflib ]; + configurePhase = '' + cmake -DCMAKE_BUILD_PREFIX=/usr -DDEBUG=0 -G "Unix Makefiles" -B build -S . + ''; + buildPhase = '' + cmake --build build -j$(nproc) + ''; + installPhase = '' + install -Dm755 build/oshot $out/bin/oshot + install -Dm644 oshot.desktop $out/share/applications/oshot.desktop + install -Dm644 LICENSE $out/share/licenses/oshot/LICENSE + ''; + }; + packages.x86_64-linux.default = self.packages.x86_64-linux.oshot; + }; +} diff --git a/include/config.hpp b/include/config.hpp index b605f91..e270123 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -290,6 +290,7 @@ void apply_imgui_theme(); // default config inline constexpr std::string_view AUTOCONFIG = R"#([default] # Default Path to where we'll use all the '.traineddata' models. +# The TESSDATA_PREFIX environment variable supersedes this. ocr-path = "{}" # Default OCR model. diff --git a/src/config.cpp b/src/config.cpp index c2a7f40..85841db 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -61,6 +61,12 @@ void Config::LoadConfigFile(const std::string& filename) File.allow_out_edit = GetValue("default.allow-edit-ocr", false); // deprecated File.allow_out_edit = GetValue("default.allow-text-edit", File.allow_out_edit); + + const char* tessdata_prefix; + if ((tessdata_prefix = getenv("TESSDATA_PREFIX"))) + { + File.ocr_path = tessdata_prefix; + } } void Config::LoadThemeFile(const std::string& filename)