From e9db1f8c039fe3292a925e2283146e35ad47eaeb Mon Sep 17 00:00:00 2001 From: Pyric Date: Mon, 31 Aug 2026 21:53:02 -0500 Subject: [PATCH] Add flake configuration --- .gitignore | 4 +++ flake.nix | 99 ++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 86 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index c9c7da0..fd4475d 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,7 @@ imgui.ini compile_commands.json include/xdg-output-unstable-v1-client-protocol.h src/xdg-output-unstable-v1-protocol.c + +# Nix Flakes +result +result-* diff --git a/flake.nix b/flake.nix index 55f9c65..78029f4 100644 --- a/flake.nix +++ b/flake.nix @@ -5,26 +5,91 @@ 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) + outputs = { self, nixpkgs }: + let + supportedSystems = [ "x86_64-linux" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); + in + { + packages = forAllSystems (system: + let + pkgs = nixpkgsFor.${system}; + in + { + oshot = pkgs.stdenv.mkDerivation { + pname = "oshot"; + version = "0.5.0-rc1"; + + src = ./.; + + nativeBuildInputs = with pkgs; [ + cmake + gnumake + pkg-config + git + wrapGAppsHook3 + wayland-scanner + ]; + + buildInputs = with pkgs; [ + glfw3 + leptonica + tesseract + zbar + gtk3 + libappindicator-gtk3 + dbus + systemd + libX11 + libXtst + giflib + libwebp + libsysprof-capture + libXdmcp + zenity + pcre2 + ]; + + preConfigure = '' + export SOURCE_DATE_EPOCH=1 + export GIT_AUTHOR_DATE="1970-01-01T00:00:01Z" + export GIT_COMMENTOR_DATE="1970-01-01T00:00:01Z" + + git init -b nix-build + git config user.name "Nix" + git config user.email "nix@localhost" + git add . + git commit -m "dummy commit for build" + git tag -a v0.1.0 -m "v0.1.0" ''; + 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 + runHook preInstall + + install -Dm755 oshot $out/bin/oshot + if [ -f oshot.desktop ]; then + install -Dm644 oshot.desktop $out/share/applications/oshot.desktop + fi + if [ -f LICENSE ]; then + install -Dm644 LICENSE $out/share/licenses/oshot/LICENSE + fi + + runHook postInstall ''; }; - packages.x86_64-linux.default = self.packages.x86_64-linux.oshot; + + default = self.packages.${system}.oshot; + }); + + nixosModules.default = { config, lib, pkgs, ... }: { + options.programs.oshot.enable = lib.mkEnableOption "oshot text extraction and screenshot tool"; + + config = lib.mkIf config.programs.oshot.enable { + environment.systemPackages = [ + self.packages.${pkgs.system}.oshot + ]; + }; + }; }; }