diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..51376c93 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1743550720, + "narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "c621e8422220273271f52058f618c94e405bb0f5", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1747744144, + "narHash": "sha256-W7lqHp0qZiENCDwUZ5EX/lNhxjMdNapFnbErcbnP11Q=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "2795c506fe8fb7b03c36ccb51f75b6df0ab2553f", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1743296961, + "narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..5c33ce92 --- /dev/null +++ b/flake.nix @@ -0,0 +1,57 @@ +{ + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + inputs.flake-parts.url = "github:hercules-ci/flake-parts"; + + outputs = inputs@{ nixpkgs, flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ "x86_64-linux" ]; + perSystem = { pkgs, ... }: let + # Tools used for development work (clangd, clang-format) + devTools = with pkgs; [ + clang-tools + ]; + # Extra build inputs not yet in the nixpkgs recipe. + # Should be submitted to nixpkgs on release + extraBuildInputs = with pkgs; [ + # XRT_FEATURE_DEBUG_GUI requires SDL2 + sdl2-compat + ]; + + package = pkgs.wivrn.overrideAttrs (finalAttrs: oldAttrs: { + src = ./.; + version = "next"; + + # Because src is just a folder path and not a set from a fetcher, it doesn't need to be unpacked, so having a postUnpack throws an error. + postUnpack = null; + prePatch = '' + ourMonadoRev="${finalAttrs.monado.src.rev}" + theirMonadoRev=$(sed -n '/FetchContent_Declare(monado/,/)/p' CMakeLists.txt | grep "GIT_TAG" | awk '{print $2}') + if [ ! "$theirMonadoRev" == "$ourMonadoRev" ]; then + echo "Our Monado source revision doesn't match CMakeLists.txt." >&2 + echo " theirs: $theirMonadoRev" >&2 + echo " ours: $ourMonadoRev" >&2 + return 1 + fi + ''; + + monado = pkgs.applyPatches { + inherit (oldAttrs.monado) patches postPatch; + src = pkgs.fetchFromGitLab { + inherit (oldAttrs.monado.src) owner repo; + domain = "gitlab.freedesktop.org"; + # Keep in sync with CMakeLists.txt monado rev + rev = "2a6932d46dad9aa957205e8a47ec2baa33041076"; + hash = "sha256-Bus9GTNC4+nOSwN8pUsMaFsiXjlpHYioQfBLxbQEF+0="; + }; + }; + + buildInputs = oldAttrs.buildInputs ++ extraBuildInputs; + }); + in { + packages.default = package; + devShells.default = package.overrideAttrs (oldAttrs: { + nativeBuildInputs = oldAttrs.nativeBuildInputs ++ devTools; + }); + }; + }; +} \ No newline at end of file