2024-09-25 23:03:56 -04:00
|
|
|
{
|
|
|
|
description = "C/C++ environment";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs";
|
|
|
|
treefmt-nix.url = "github:numtide/treefmt-nix";
|
|
|
|
utils.url = "github:numtide/flake-utils";
|
|
|
|
};
|
|
|
|
|
|
|
|
outputs = {
|
|
|
|
self,
|
|
|
|
nixpkgs,
|
|
|
|
treefmt-nix,
|
|
|
|
utils,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
utils.lib.eachDefaultSystem (
|
|
|
|
system: let
|
|
|
|
pkgs = import nixpkgs {inherit system;};
|
|
|
|
|
|
|
|
stdenv =
|
|
|
|
if pkgs.hostPlatform.isLinux
|
|
|
|
then pkgs.stdenvAdapters.useMoldLinker pkgs.llvmPackages_18.stdenv
|
|
|
|
else pkgs.llvmPackages_18.stdenv;
|
|
|
|
|
|
|
|
sources = import ./_sources/generated.nix {
|
|
|
|
inherit (pkgs) fetchFromGitHub fetchgit fetchurl dockerTools;
|
|
|
|
};
|
|
|
|
|
|
|
|
mkPkg = name:
|
|
|
|
pkgs.pkgsStatic.${name}.overrideAttrs {
|
|
|
|
inherit (sources.${name}) pname version src;
|
|
|
|
};
|
|
|
|
|
|
|
|
fmt = mkPkg "fmt";
|
|
|
|
|
|
|
|
deps = with pkgs;
|
|
|
|
[
|
|
|
|
fmt
|
|
|
|
glfw
|
|
|
|
glm
|
2024-09-26 17:18:45 -04:00
|
|
|
vulkan-tools
|
2024-09-25 23:03:56 -04:00
|
|
|
]
|
|
|
|
++ lib.optionals stdenv.isDarwin [
|
|
|
|
darwin.apple_sdk.frameworks.AppKit
|
|
|
|
darwin.apple_sdk.frameworks.Cocoa
|
|
|
|
darwin.apple_sdk.frameworks.Metal
|
|
|
|
darwin.apple_sdk.frameworks.QuartzCore
|
|
|
|
];
|
|
|
|
in
|
2024-09-26 17:18:45 -04:00
|
|
|
with pkgs; rec {
|
2024-09-25 23:03:56 -04:00
|
|
|
packages = rec {
|
|
|
|
graphics-test = stdenv.mkDerivation {
|
|
|
|
name = "graphics-test";
|
|
|
|
version = "0.1.0";
|
|
|
|
src = self;
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
meson
|
|
|
|
ninja
|
|
|
|
pkg-config
|
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = deps;
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
meson setup build
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
meson compile -C build
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
mv build/graphics-test $out/bin/graphics-test
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
default = graphics-test;
|
|
|
|
};
|
|
|
|
|
|
|
|
formatter = treefmt-nix.lib.mkWrapper pkgs {
|
|
|
|
projectRootFile = "flake.nix";
|
|
|
|
programs = {
|
|
|
|
alejandra.enable = true;
|
|
|
|
deadnix.enable = true;
|
|
|
|
|
|
|
|
clang-format = {
|
|
|
|
enable = true;
|
|
|
|
package = pkgs.clang-tools_18;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
devShell = mkShell.override {inherit stdenv;} {
|
|
|
|
packages =
|
|
|
|
[
|
|
|
|
alejandra
|
|
|
|
bear
|
|
|
|
llvmPackages_18.clang-tools
|
|
|
|
lldb
|
|
|
|
meson
|
|
|
|
ninja
|
|
|
|
nvfetcher
|
|
|
|
pkg-config
|
|
|
|
unzip
|
|
|
|
|
|
|
|
(writeScriptBin "build" "meson compile -C build")
|
|
|
|
(writeScriptBin "clean" "meson setup build --wipe")
|
|
|
|
(writeScriptBin "reconfigure" "meson setup build --reconfigure")
|
2024-09-26 17:18:45 -04:00
|
|
|
(writeScriptBin "run" "meson compile -C build && build/${packages.default.name}")
|
2024-09-25 23:03:56 -04:00
|
|
|
]
|
|
|
|
++ deps;
|
|
|
|
|
|
|
|
shellHook = lib.optionals stdenv.isDarwin ''
|
2024-09-26 17:18:45 -04:00
|
|
|
export MOLTENVK_LIBRARY_PATH="${darwin.moltenvk}/lib"
|
2024-09-25 23:03:56 -04:00
|
|
|
export PATH="${llvmPackages_18.clang-tools}/bin:$PATH"
|
|
|
|
export VK_ICD_FILENAMES="${darwin.moltenvk}/share/vulkan/icd.d/MoltenVK_icd.json"
|
2024-09-26 17:18:45 -04:00
|
|
|
export VK_LAYER_PATH="${vulkan-validation-layers}/share/vulkan/explicit_layer.d"
|
|
|
|
export VULKAN_INCLUDE_DIRS="${darwin.moltenvk.dev}/include:${vulkan-headers}/include"
|
|
|
|
export VK_LOADER_DEBUG=all
|
2024-09-25 23:03:56 -04:00
|
|
|
'';
|
|
|
|
|
|
|
|
name = "C++";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|