diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index d2ddad8..e535602 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,10 @@ ## ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore +# Nix atrifacts +/.direnv +**/result + # User-specific files .idea/ *.rsuser diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..774c899 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1754214453, + "narHash": "sha256-Q/I2xJn/j1wpkGhWkQnm20nShYnG7TI99foDBpXm1SY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5b09dc45f24cf32316283e62aec81ffee3c3e376", + "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..cbcdc76 --- /dev/null +++ b/flake.nix @@ -0,0 +1,33 @@ +{ + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = { self, nixpkgs, ... }: let + systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin"]; + forAllSystems = nixpkgs.lib.genAttrs systems; + pkgsFor = system: import nixpkgs { + inherit system; + }; + in { + devShells = forAllSystems (system: let + pkgs = pkgsFor system; + dotnet = pkgs.dotnetCorePackages.dotnet_8; + in { + default = pkgs.mkShell rec { + buildInputs = with pkgs; [ + cmake opencv icu udev + dotnet.sdk dotnet.runtime + xorg.libX11 xorg.libSM xorg.libICE + libjpeg onnxruntime libGL fontconfig + (pkgs.callPackage ./nix/opencvsharp.nix {}) + ]; + + shellHook = '' + export DOTNET_ROOT="${dotnet.sdk}" + # Fuck knows why the runtime looks in PATH instead of LD_LIBRARY_PATH + export PATH="$PATH:${builtins.toString (pkgs.lib.makeLibraryPath buildInputs)}"; + export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${builtins.toString (pkgs.lib.makeLibraryPath buildInputs)}"; + ''; + }; + }); + }; +} diff --git a/nix/opencvsharp.nix b/nix/opencvsharp.nix new file mode 100644 index 0000000..211185f --- /dev/null +++ b/nix/opencvsharp.nix @@ -0,0 +1,20 @@ +{lib, stdenv, fetchFromGitHub, cmake, opencv}: +stdenv.mkDerivation rec { + name = "opencvsharp"; + src = fetchFromGitHub { + owner = "shimat"; + repo = "opencvsharp"; + tag = "4.11.0.20250507"; + hash = "sha256-CkG4Kx/AkZqyhtclMfS51a9a9R+hsqBRlM4fry32YJ0="; + }; + buildInputs = [ opencv ]; + nativeBuildInputs = [ cmake ]; + sourceRoot = "${src.name}/src"; + + meta = with lib; { + license = licenses.asl20; + platforms = platforms.unix; + description = "OpenCV wrapper for .NET"; + homepage = "https://github.com/shimat/opencvsharp"; + }; +}