From 79227dd3e4d93f1ec10717d746e0a11e229cff3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 31 Dec 2024 10:34:45 +0100 Subject: [PATCH] feat: allow deploying tev via nix flake --- flake.nix | 89 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 22 deletions(-) diff --git a/flake.nix b/flake.nix index 41c0759..dabce41 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Nix tev dev env"; + description = "tev — The EXR Viewer"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; @@ -10,32 +10,77 @@ flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; - in - { - devShell = pkgs.mkShell { - buildInputs = with pkgs; [ - gcc - gdb - cmake - pkg-config - binutils - zlib - xorg.libX11.dev - xorg.libXi.dev - xorg.libXrandr.dev - xorg.libXinerama.dev - xorg.libXcursor.dev - xorg.libXext.dev - xorg.libXfixes.dev - xorg.libXrender.dev + # Extract version from CMakeLists.txt + version = with builtins; + let + cmakeContents = readFile ./CMakeLists.txt; + versionMatch = match ".*VERSION[[:space:]]+([^[:space:]]+).*" cmakeContents; + in + if versionMatch == null then throw "Could not find version in CMakeLists.txt" + else head versionMatch; + # Common dependencies shared between dev shell and build + commonDeps = with pkgs; + if stdenv.isDarwin then [ + darwin.apple_sdk.frameworks.Cocoa + darwin.apple_sdk.frameworks.OpenGL + ] else [ + xorg.libX11 + xorg.libXcursor + xorg.libXinerama + xorg.libXrandr + xorg.libXi libGL + zlib ]; - shellHook = '' - export CMAKE_PREFIX_PATH="${pkgs.xorg.libX11.dev}:${pkgs.xorg.libXi.dev}:${pkgs.libGL}:''${CMAKE_PREFIX_PATH:-}" - ''; + # Common build inputs shared between dev shell and build + commonBuildInputs = with pkgs; [ + cmake + ]; + + tev = pkgs.stdenv.mkDerivation { + pname = "tev"; + inherit version; + + src = ./.; + + nativeBuildInputs = commonBuildInputs; + buildInputs = commonDeps; + + cmakeFlags = [ + "-DCMAKE_BUILD_TYPE=Release" + "-DTEV_DEPLOY=ON" + ]; + + meta = with pkgs.lib; { + description = "High dynamic range (HDR) image comparison tool for graphics people"; + homepage = "https://github.com/Tom94/tev"; + license = licenses.bsd3; + platforms = platforms.unix; + maintainers = [ ]; + }; + }; + in + { + packages = { + default = tev; + tev = tev; + }; + + devShell = pkgs.mkShell { + buildInputs = commonDeps ++ commonBuildInputs ++ (with pkgs; + if stdenv.isDarwin then [ ] else [ + gcc + gdb + binutils + ] + ); + }; + + apps.default = flake-utils.lib.mkApp { + drv = tev; }; } );