voxel-zone/flake.nix

100 lines
3.8 KiB
Nix

{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
nixGL.url = "github:guibou/nixGL";
nixpkgs-mozilla = { url = "github:mozilla/nixpkgs-mozilla"; };
};
outputs = { self, nixpkgs, utils, nixpkgs-mozilla, nixGL }:
utils.lib.eachDefaultSystem (system:
let
pkgs = (import nixpkgs) {
inherit system;
overlays = [ (import nixpkgs-mozilla) nixGL.overlay ];
};
toolchain = (pkgs.rustChannelOf {
# sadly, https://github.com/mozilla/nixpkgs-mozilla/issues/287
date = "2022-08-07";
channel = "nightly";
sha256 = "sha256-cXABXvQuh4dXNLtFMvRuB7YBi9LXRerA0u/u/TUm4rQ=";
}).rust.override {
extensions = [
"rust-src"
"rust-analyzer-preview"
"clippy-preview"
"rustfmt-preview"
];
targets = [ "x86_64-unknown-linux-gnu" "wasm32-unknown-unknown" ];
};
nixGlWrappedMgbaQt = pkgs.writeShellScriptBin "mgba-qt" ''
# call mgba-qt with nixGL
exec ${pkgs.nixgl.nixGLIntel}/bin/nixGLIntel ${pkgs.mgba}/bin/mgba-qt $@
'';
# this doesn't seem to work
softwareVulkan = pkgs.writeShellScriptBin "hell" ''
export LIBGL_ALWAYS_SOFTWARE=1
export __GLX_VENDOR_LIBRARY_NAME=mesa
export VK_ICD_FILENAMES=${pkgs.mesa.drivers}/share/vulkan/icd.d/lvp_icd.x86_64.json
exec ${pkgs.nixgl.nixVulkanIntel}/bin/nixVulkanIntel $@
'';
baseBuildInputs = [ toolchain pkgs.gcc-arm-embedded ];
levelEditorDeps = with pkgs; {
# thanks, https://github.com/bevyengine/bevy/blob/main/docs/linux_dependencies.md#nixos !
nativeBuildInputs = [ pkgconfig llvmPackages.bintools vulkan-loader nixgl.nixVulkanIntel vulkan-tools
openssl # deps for building wasm. we have to cargo install -f wasm-bindgen-cli, the nixpkg is out of sync
];
buildInputs = [ # wip and not minimal. was trying to get stuff working on my desktop and didn't finish
udev alsaLib
xlibsWrapper xorg.libXcursor xorg.libXrandr xorg.libXi # To use x11 feature
libxkbcommon wayland # To use wayland feature
gdk-pixbuf atk pango cairo gtk3-x11 # additional dependencies for voxel-level-editor
];
hook = ''
export PATH=$PATH:$HOME/.cargo/bin
'';
};
ensureSubmodules = ''
# quick check of whether submodules are initialized, if the working directory is the root of the repo
if [[ -f "flake.nix" && -f "Cargo.toml" && ! -f "external/agb/README.md" ]]; then
echo "fetching submodules"
git submodule init
git submodule update
fi
'';
in {
devShell = with pkgs;
mkShell {
nativeBuildInputs = baseBuildInputs ++ [ nixGlWrappedMgbaQt ];
shellHook = ''
'' + ensureSubmodules;
};
devShells.level-editor = with pkgs; # wip use at your own peril
mkShell rec {
nativeBuildInputs = baseBuildInputs ++ levelEditorDeps.nativeBuildInputs ++ [ nixGlWrappedMgbaQt softwareVulkan ];
buildInputs = levelEditorDeps.buildInputs;
shellHook = ''
'' + ensureSubmodules;
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
};
devShells.wsl-vcxsrv = with pkgs;
mkShell {
nativeBuildInputs = baseBuildInputs ++ [ nixGlWrappedMgbaQt ];
shellHook = ''
export HOST_IP="$(ip route |awk '/^default/{print $3}')"
export DISPLAY=$HOST_IP:0 # use vcxsrv
export PULSE_SERVER="tcp:$HOST_IP"
'' + ensureSubmodules;
};
});
}