Skip to content

Commit

Permalink
Add odin with system raylib and add nixpkgs-master
Browse files Browse the repository at this point in the history
Add nixpkgs-master to flake inputs
Rename test branch to custom
Add odin with a patch to use raylib from the system
(can remove patch if odin pr closes
(odin-lang/Odin#4619)
  • Loading branch information
Arsalan2356 committed Jan 3, 2025
1 parent c56e74f commit 7aa06cd
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 23 deletions.
4 changes: 2 additions & 2 deletions configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).

{ config, pkgs, pkgs-test, inputs, lib, ... }:
{ config, pkgs, pkgs-custom, inputs, lib, ... }:
{
# Allow unfree packages
nixpkgs.config.allowUnfree = lib.mkForce true;
Expand All @@ -26,7 +26,7 @@
# Kernel Packages
# Switch to zen kernel (latest from fork)
# boot.kernelPackages = pkgs.linuxPackages_latest;
boot.kernelPackages = pkgs-test.linuxPackages_zen;
boot.kernelPackages = pkgs-custom.linuxPackages_zen;


# Load amdgpu kernel module
Expand Down
47 changes: 32 additions & 15 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
url = "github:nixos/nixpkgs/nixos-unstable";
};

nixpkgs-master = {
url = "github:nixos/nixpkgs/master";
};

home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
Expand All @@ -25,7 +29,7 @@
inputs.nixpkgs.follows = "nixpkgs";
};

nixpkgs-test = {
nixpkgs-custom = {
url = "github:Arsalan2356/nixpkgs/custom";
};

Expand Down Expand Up @@ -53,21 +57,25 @@
"dotnet-sdk-6.0.428"
];
};
pkgs-test = import inputs.nixpkgs-test {
pkgs-custom = import inputs.nixpkgs-custom {
inherit system;
config.allowUnfree = true;
};
pkgs-master = import inputs.nixpkgs-master {
inherit system;
config.allowUnfree = true;
};
in {
nixosConfigurations = {
rc = nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = { inherit pkgs inputs pkgs-test; };
specialArgs = { inherit pkgs inputs pkgs-custom; };
modules = [
./configuration.nix
home-manager.nixosModules.home-manager {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.extraSpecialArgs = { inherit pkgs inputs pkgs-test; };
home-manager.extraSpecialArgs = { inherit pkgs pkgs-custom pkgs-master inputs; };
home-manager.users.rc = import ./home.nix;
}
# inputs.stylix.nixosModules.stylix
Expand Down
5 changes: 3 additions & 2 deletions home.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, pkgs, pkgs-test, inputs, ... }:
{ config, pkgs, pkgs-custom, pkgs-master, inputs, ... }:
let
tokyonight = pkgs.tokyonight-gtk-theme.overrideAttrs (old : {
src = pkgs.fetchFromGitHub {
Expand Down Expand Up @@ -68,7 +68,8 @@ in
playerctl
nvd
eza
odin
(pkgs.callPackage ./odin/odin.nix {})
pkgs-master.raylib


# General
Expand Down
132 changes: 132 additions & 0 deletions odin/odin-system-raylib.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
diff --git a/vendor/raylib/raygui.odin b/vendor/raylib/raygui.odin
index a15467ae8..89c1483a0 100644
--- a/vendor/raylib/raygui.odin
+++ b/vendor/raylib/raygui.odin
@@ -2,28 +2,8 @@ package raylib

import "core:c"

-RAYGUI_SHARED :: #config(RAYGUI_SHARED, false)
-
-when ODIN_OS == .Windows {
- foreign import lib {
- "windows/rayguidll.lib" when RAYGUI_SHARED else "windows/raygui.lib",
- }
-} else when ODIN_OS == .Linux {
- foreign import lib {
- "linux/libraygui.so" when RAYGUI_SHARED else "linux/libraygui.a",
- }
-} else when ODIN_OS == .Darwin {
- when ODIN_ARCH == .arm64 {
- foreign import lib {
- "macos-arm64/libraygui.dylib" when RAYGUI_SHARED else "macos-arm64/libraygui.a",
- }
- } else {
- foreign import lib {
- "macos/libraygui.dylib" when RAYGUI_SHARED else "macos/libraygui.a",
- }
- }
-} else {
- foreign import lib "system:raygui"
+foreign import lib {
+ "system:raygui",
}

RAYGUI_VERSION :: "4.0"
diff --git a/vendor/raylib/raylib.odin b/vendor/raylib/raylib.odin
index a5be660c6..6d1f4d0d9 100644
--- a/vendor/raylib/raylib.odin
+++ b/vendor/raylib/raylib.odin
@@ -99,36 +99,10 @@ MAX_TEXT_BUFFER_LENGTH :: #config(RAYLIB_MAX_TEXT_BUFFER_LENGTH, 1024)

#assert(size_of(rune) == size_of(c.int))

-RAYLIB_SHARED :: #config(RAYLIB_SHARED, false)
-
-when ODIN_OS == .Windows {
- @(extra_linker_flags="/NODEFAULTLIB:" + ("msvcrt" when RAYLIB_SHARED else "libcmt"))
- foreign import lib {
- "windows/raylibdll.lib" when RAYLIB_SHARED else "windows/raylib.lib" ,
- "system:Winmm.lib",
- "system:Gdi32.lib",
- "system:User32.lib",
- "system:Shell32.lib",
- }
-} else when ODIN_OS == .Linux {
- foreign import lib {
- // Note(bumbread): I'm not sure why in `linux/` folder there are
- // multiple copies of raylib.so, but since these bindings are for
- // particular version of the library, I better specify it. Ideally,
- // though, it's best specified in terms of major (.so.4)
- "linux/libraylib.so.550" when RAYLIB_SHARED else "linux/libraylib.a",
- "system:dl",
- "system:pthread",
- }
-} else when ODIN_OS == .Darwin {
- foreign import lib {
- "macos/libraylib.550.dylib" when RAYLIB_SHARED else "macos/libraylib.a",
- "system:Cocoa.framework",
- "system:OpenGL.framework",
- "system:IOKit.framework",
- }
-} else {
- foreign import lib "system:raylib"
+foreign import lib {
+ "system:raylib",
+ "system:dl",
+ "system:pthread",
}

VERSION_MAJOR :: 5
diff --git a/vendor/raylib/rlgl/rlgl.odin b/vendor/raylib/rlgl/rlgl.odin
index 9d4682294..f39ea2035 100644
--- a/vendor/raylib/rlgl/rlgl.odin
+++ b/vendor/raylib/rlgl/rlgl.odin
@@ -112,43 +112,10 @@ import rl "../."

VERSION :: "5.0"

-RAYLIB_SHARED :: #config(RAYLIB_SHARED, false)
-
-// Note: We pull in the full raylib library. If you want a truly stand-alone rlgl, then:
-// - Compile a separate rlgl library and use that in the foreign import blocks below.
-// - Remove the `import rl "../."` line
-// - Copy the code from raylib.odin for any types we alias from that package (see PixelFormat etc)
-
-when ODIN_OS == .Windows {
- @(extra_linker_flags="/NODEFAULTLIB:" + ("msvcrt" when RAYLIB_SHARED else "libcmt"))
- foreign import lib {
- "../windows/raylibdll.lib" when RAYLIB_SHARED else "../windows/raylib.lib" ,
- "system:Winmm.lib",
- "system:Gdi32.lib",
- "system:User32.lib",
- "system:Shell32.lib",
- }
-} else when ODIN_OS == .Linux {
- foreign import lib {
- // Note(bumbread): I'm not sure why in `linux/` folder there are
- // multiple copies of raylib.so, but since these bindings are for
- // particular version of the library, I better specify it. Ideally,
- // though, it's best specified in terms of major (.so.4)
- "../linux/libraylib.so.500" when RAYLIB_SHARED else "../linux/libraylib.a",
- "system:dl",
- "system:pthread",
- }
-} else when ODIN_OS == .Darwin {
- foreign import lib {
- "../macos" +
- ("-arm64" when ODIN_ARCH == .arm64 else "") +
- "/libraylib" + (".500.dylib" when RAYLIB_SHARED else ".a"),
- "system:Cocoa.framework",
- "system:OpenGL.framework",
- "system:IOKit.framework",
- }
-} else {
- foreign import lib "system:raylib"
+foreign import lib {
+ "system:raygui",
+ "system:dl",
+ "system:pthread",
}

GRAPHICS_API_OPENGL_11 :: false
68 changes: 68 additions & 0 deletions odin/odin.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
fetchFromGitHub,
lib,
llvmPackages,
makeBinaryWrapper,
which,
}: let
inherit (llvmPackages) stdenv;
in
stdenv.mkDerivation {
pname = "odin";
version = "2024-12-06";

src = fetchFromGitHub {
owner = "odin-lang";
repo = "Odin";
rev = "dev-2024-12";
hash = "sha256-BkPdVzgbEc3S4eSi5TbFKPzkRGkaJTILN/g9o8hfdEw=";
};

patches = [./odin-system-raylib.patch];

dontConfigure = true;
LLVM_CONFIG = "${llvmPackages.llvm.dev}/bin/llvm-config";

buildFlags = ["release"];

nativeBuildInputs = [
makeBinaryWrapper
which
];

postPatch = ''
patchShebangs build_odin.sh
'';

installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp odin $out/bin/odin
mkdir -p $out/share
cp -r {base,core,shared} $out/share
mkdir -p $out/share/vendor/raylib
cp -r vendor/raylib/{rlgl,*.odin} $out/share/vendor/raylib
# make -C "$out/share/vendor/cgltf/src/"
# make -C "$out/share/vendor/stb/src/"
# make -C "$out/share/vendor/miniaudio/src/"
wrapProgram $out/bin/odin \
--set-default ODIN_ROOT $out/share \
--prefix PATH : ${
lib.makeBinPath (
with llvmPackages; [
bintools
llvm
clang
lld
]
)
}
runHook postInstall
'';
}

0 comments on commit 7aa06cd

Please sign in to comment.