diff --git a/Toolchain/Nix/package.nix b/Toolchain/Nix/package.nix new file mode 100644 index 00000000000..97928108afe --- /dev/null +++ b/Toolchain/Nix/package.nix @@ -0,0 +1,26 @@ +# Override ladybird from nixpkgs with the source directory as the source +# and latest revision (or "dirty") as the version. Unless new dependencies +# are introduced, this should work just fine. If a new dependency is added +# and builds are broken, simply adding the missing dependencies in buildInputs +# inside of the attribute should do the trick. +{ + self, + lib, + ladybird, + ... +}: +ladybird.overrideAttrs { + # Reproducible source path + src = builtins.path { + path = ../../.; + name = "ladybird-source"; + filter = lib.cleanSourceFilter; + }; + + # Short rev will be missing in "dirty" source trees. In which case we fall + # back to "dirty" as the version. + version = self.shortRev or "dirty"; + + # Let's not bother nixpkgs maintainers with issues in the source. + meta.maintainers = with lib.maintainers; [ NotAShelf ]; +} diff --git a/Toolchain/Nix/shell.nix b/Toolchain/Nix/shell.nix new file mode 100644 index 00000000000..ef3e560a70f --- /dev/null +++ b/Toolchain/Nix/shell.nix @@ -0,0 +1,33 @@ +{ + mkShell, + kdePackages, + ccache, + clang-tools, + pre-commit, + prettier, + ladybird, + ... +}: +mkShell { + inputsFrom = [ + ladybird + ]; + + packages = [ + ccache + clang-tools + pre-commit + prettier + ]; + + # Fix for: https://github.com/LadybirdBrowser/ladybird/issues/371#issuecomment-2616415434 + # https://github.com/NixOS/nixpkgs/commit/049a854b4be087eaa3a09012b9c452fbc838dd41 + NIX_LDFLAGS = "-lGL"; + + shellHook = '' + # NOTE: This is required to make it find the wayland platform plugin installed + # above, but should probably be fixed upstream. + export QT_PLUGIN_PATH="$QT_PLUGIN_PATH:${kdePackages.qtwayland}/lib/qt-6/plugins" + export QT_QPA_PLATFORM="wayland;xcb" + ''; +} diff --git a/flake.nix b/flake.nix index 1853ccdb14d..742818d71aa 100644 --- a/flake.nix +++ b/flake.nix @@ -17,13 +17,32 @@ eachSystem = nixpkgs.lib.genAttrs (import systems); in { + packages = eachSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + # Default ladybird package built from source using current directory + # as the source. This is not cached. + ladybird = pkgs.callPackage ./Toolchain/Nix/package.nix { inherit self; }; + + # Alias for `nix run .` or `nix run github:LadybirdBrowser/ladybird` + default = self.packages.${system}.ladybird; + } + ); + devShells = eachSystem ( system: let pkgs = nixpkgs.legacyPackages.${system}; in { - default = pkgs.callPackage ./Nix/shell.nix { + # Override nixpkgs ladybird with the one provided + # by this flake. This will allow inputsFrom to + # remain in-sync with the package provided by the + # flake. + default = pkgs.callPackage ./Toolchain/Nix/shell.nix { inherit (self.packages.${system}) ladybird; }; }