diff --git a/flake.lock b/flake.lock index 6f39b8d..f4c6489 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,20 @@ { "nodes": { + "crane": { + "locked": { + "lastModified": 1770419512, + "narHash": "sha256-o8Vcdz6B6bkiGUYkZqFwH3Pv1JwZyXht3dMtS7RchIo=", + "owner": "ipetkov", + "repo": "crane", + "rev": "2510f2cbc3ccd237f700bb213756a8f35c32d8d7", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, "fenix": { "inputs": { "nixpkgs": "nixpkgs", @@ -128,6 +143,7 @@ }, "root": { "inputs": { + "crane": "crane", "fenix": "fenix", "flake-utils": "flake-utils", "naersk": "naersk", diff --git a/flake.nix b/flake.nix index 0c69358..0f022c9 100644 --- a/flake.nix +++ b/flake.nix @@ -6,6 +6,7 @@ naersk.url = "github:nix-community/naersk"; flake-utils.url = "github:numtide/flake-utils"; fenix.url = "github:nix-community/fenix"; + crane.url = "github:ipetkov/crane"; }; outputs = @@ -19,7 +20,21 @@ overlays = [ fenix.overlays.default ]; # overlays = [cargo2nix.overlays.default]; }; + inherit (pkgs) lib; + craneLib = (crane.mkLib pkgs).overrideToolchain fenix.packages.${system}.stable.toolchain; naersk' = pkgs.callPackage naersk { }; + + unfilteredRoot = ./.; # The original, unfiltered source + src = lib.fileset.toSource { + root = unfilteredRoot; + fileset = lib.fileset.unions [ + # Default files from crane (Rust and cargo files) + (craneLib.fileset.commonCargoSources unfilteredRoot) + # Include all the .sql migrations as well + ./migrations + ]; + }; + nbi = with pkgs; [ # Rust tools alejandra @@ -35,7 +50,6 @@ vulkan-loader wayland wayland-protocols - libxkbcommon pkg-config sccache ]; @@ -49,13 +63,12 @@ cmake clang libclang + libxkbcommon makeWrapper vulkan-headers vulkan-loader vulkan-tools libGL - cargo-flamegraph - bacon fontconfig glib @@ -72,53 +85,78 @@ mupdf # yt-dlp - just - sqlx-cli - cargo-watch + ] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ + # Additional darwin specific inputs can be set here + pkgs.libiconv ]; + + ldLibPaths = "$LD_LIBRARY_PATH:${ + with pkgs; + lib.makeLibraryPath [ + alsa-lib + gst_all_1.gst-libav + gst_all_1.gstreamer + gst_all_1.gst-plugins-bad + gst_all_1.gst-plugins-good + gst_all_1.gst-plugins-ugly + gst_all_1.gst-plugins-base + gst_all_1.gst-plugins-rs + gst_all_1.gst-vaapi + glib + fontconfig + vulkan-loader + wayland + wayland-protocols + libxkbcommon + mupdf + libclang + ] + }"; + + commonArgs = { + inherit src; + strictDeps = true; + nativeBuildInputs = nbi; + buildInputs = bi; + LD_LIBRARY_PATH = ldLibPaths; + }; + + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + lumina = craneLib.buildPackage ( + commonArgs + // { + inherit cargoArtifacts; + + nativeBuildInputs = (commonArgs.nativeBuildInputs or [ ]) ++ [ + pkgs.sqlx-cli + ]; + + preBuild = '' + export DATABASE_URL=sqlite:./db.sqlite3 + sqlx database create + sqlx migrate run + ''; + } + ); + in rec { - devShell = - pkgs.mkShell.override - { - # stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.clangStdenv; - } - { - nativeBuildInputs = nbi; - buildInputs = bi; - LD_LIBRARY_PATH = "$LD_LIBRARY_PATH:${ - with pkgs; - pkgs.lib.makeLibraryPath [ - pkgs.alsa-lib - pkgs.gst_all_1.gst-libav - pkgs.gst_all_1.gstreamer - pkgs.gst_all_1.gst-plugins-bad - pkgs.gst_all_1.gst-plugins-good - pkgs.gst_all_1.gst-plugins-ugly - pkgs.gst_all_1.gst-plugins-base - pkgs.gst_all_1.gst-plugins-rs - pkgs.gst_all_1.gst-vaapi - pkgs.glib - pkgs.fontconfig - pkgs.vulkan-loader - pkgs.wayland - pkgs.wayland-protocols - pkgs.libxkbcommon - pkgs.mupdf - pkgs.libclang - ] - }"; - # LIBCLANG_PATH = "${pkgs.clang}"; - DATABASE_URL = "sqlite:///home/chris/.local/share/lumina/library-db.sqlite3"; - }; - defaultPackage = naersk'.buildPackage { - src = ./.; + checks = { + inherit lumina; }; - packages = { - default = naersk'.buildPackage { - src = ./.; - }; + devShells.default = craneLib.devShell { + checks = self.checks.${system}; + inputsFrom = [ lumina ]; + packages = with pkgs; [ + sqlx-cli + cargo-flamegraph + bacon + just + cargo-watch + ]; }; + packages.default = lumina; } ); }