diff --git a/crates/pile-value/build.rs b/crates/pile-value/build.rs index c15a285..06351f9 100644 --- a/crates/pile-value/build.rs +++ b/crates/pile-value/build.rs @@ -23,6 +23,13 @@ fn main() { .expect("unexpected OUT_DIR structure") .to_path_buf(); + // If PDFIUM_LIB_DIR is set (e.g. by Nix), use the pre-installed library directly. + if let Ok(lib_dir) = env::var("PDFIUM_LIB_DIR") { + println!("cargo:rustc-link-search=native={lib_dir}"); + println!("cargo:rustc-link-lib=dylib=pdfium"); + return; + } + let lib_path = profile_dir.join("libpdfium.so"); if !lib_path.exists() { diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..c524003 --- /dev/null +++ b/default.nix @@ -0,0 +1,52 @@ +let + rustOverlay = import ( + builtins.fetchTarball { + url = "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"; + sha256 = "0qgrkgc695a7gja83dngxrcx4gdg9056gvg5325i5yyjxg0ni6c9"; + } + ); + pkgsDefault = import { overlays = [ rustOverlay ]; }; + rustToolchain = pkgsDefault.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + rustPlatformDefault = pkgsDefault.makeRustPlatform { + cargo = rustToolchain; + rustc = rustToolchain; + }; +in +{ + pkgs ? pkgsDefault, + pileRustPlatform ? rustPlatformDefault, +}: + +pileRustPlatform.buildRustPackage { + pname = "pile"; + version = "0.0.1"; + src = ./.; + + cargoLock.lockFile = ./Cargo.lock; + + PDFIUM_LIB_DIR = "${pkgs.pdfium-binaries}/lib"; + + buildInputs = [ + pkgs.pdfium-binaries + pkgs.openssl + ] + ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ + pkgs.darwin.apple_sdk.frameworks.Security + pkgs.darwin.apple_sdk.frameworks.SystemConfiguration + ]; + + nativeBuildInputs = [ + pkgs.pkg-config + pkgs.makeWrapper + ]; + + postInstall = '' + wrapProgram $out/bin/pile \ + --prefix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath [ pkgs.pdfium-binaries ]} + ''; + + meta = { + description = "pile - flexible file indexing"; + mainProgram = "pile"; + }; +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..da3d7cc --- /dev/null +++ b/flake.nix @@ -0,0 +1,40 @@ +{ + description = "pile - personal data indexer"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, rust-overlay, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + + rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + + rustPlatform = pkgs.makeRustPlatform { + cargo = rustToolchain; + rustc = rustToolchain; + }; + + in { + packages.default = import ./default.nix { inherit pkgs; pileRustPlatform = rustPlatform; }; + + devShells.default = pkgs.mkShell { + buildInputs = [ + rustToolchain + pkgs.pdfium-binaries + pkgs.openssl + pkgs.pkg-config + ]; + + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ pkgs.pdfium-binaries ]; + }; + }); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..b648214 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.94.0" \ No newline at end of file