Skip to content

Commit 7aa06cd

Browse files
committed
Add odin with system raylib and add nixpkgs-master
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)
1 parent c56e74f commit 7aa06cd

File tree

6 files changed

+249
-23
lines changed

6 files changed

+249
-23
lines changed

configuration.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# your system. Help is available in the configuration.nix(5) man page
33
# and in the NixOS manual (accessible by running ‘nixos-help’).
44

5-
{ config, pkgs, pkgs-test, inputs, lib, ... }:
5+
{ config, pkgs, pkgs-custom, inputs, lib, ... }:
66
{
77
# Allow unfree packages
88
nixpkgs.config.allowUnfree = lib.mkForce true;
@@ -26,7 +26,7 @@
2626
# Kernel Packages
2727
# Switch to zen kernel (latest from fork)
2828
# boot.kernelPackages = pkgs.linuxPackages_latest;
29-
boot.kernelPackages = pkgs-test.linuxPackages_zen;
29+
boot.kernelPackages = pkgs-custom.linuxPackages_zen;
3030

3131

3232
# Load amdgpu kernel module

flake.lock

+32-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+12-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
url = "github:nixos/nixpkgs/nixos-unstable";
88
};
99

10+
nixpkgs-master = {
11+
url = "github:nixos/nixpkgs/master";
12+
};
13+
1014
home-manager = {
1115
url = "github:nix-community/home-manager";
1216
inputs.nixpkgs.follows = "nixpkgs";
@@ -25,7 +29,7 @@
2529
inputs.nixpkgs.follows = "nixpkgs";
2630
};
2731

28-
nixpkgs-test = {
32+
nixpkgs-custom = {
2933
url = "github:Arsalan2356/nixpkgs/custom";
3034
};
3135

@@ -53,21 +57,25 @@
5357
"dotnet-sdk-6.0.428"
5458
];
5559
};
56-
pkgs-test = import inputs.nixpkgs-test {
60+
pkgs-custom = import inputs.nixpkgs-custom {
61+
inherit system;
62+
config.allowUnfree = true;
63+
};
64+
pkgs-master = import inputs.nixpkgs-master {
5765
inherit system;
5866
config.allowUnfree = true;
5967
};
6068
in {
6169
nixosConfigurations = {
6270
rc = nixpkgs.lib.nixosSystem {
6371
inherit system;
64-
specialArgs = { inherit pkgs inputs pkgs-test; };
72+
specialArgs = { inherit pkgs inputs pkgs-custom; };
6573
modules = [
6674
./configuration.nix
6775
home-manager.nixosModules.home-manager {
6876
home-manager.useGlobalPkgs = true;
6977
home-manager.useUserPackages = true;
70-
home-manager.extraSpecialArgs = { inherit pkgs inputs pkgs-test; };
78+
home-manager.extraSpecialArgs = { inherit pkgs pkgs-custom pkgs-master inputs; };
7179
home-manager.users.rc = import ./home.nix;
7280
}
7381
# inputs.stylix.nixosModules.stylix

home.nix

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ config, pkgs, pkgs-test, inputs, ... }:
1+
{ config, pkgs, pkgs-custom, pkgs-master, inputs, ... }:
22
let
33
tokyonight = pkgs.tokyonight-gtk-theme.overrideAttrs (old : {
44
src = pkgs.fetchFromGitHub {
@@ -68,7 +68,8 @@ in
6868
playerctl
6969
nvd
7070
eza
71-
odin
71+
(pkgs.callPackage ./odin/odin.nix {})
72+
pkgs-master.raylib
7273

7374

7475
# General

odin/odin-system-raylib.patch

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
diff --git a/vendor/raylib/raygui.odin b/vendor/raylib/raygui.odin
2+
index a15467ae8..89c1483a0 100644
3+
--- a/vendor/raylib/raygui.odin
4+
+++ b/vendor/raylib/raygui.odin
5+
@@ -2,28 +2,8 @@ package raylib
6+
7+
import "core:c"
8+
9+
-RAYGUI_SHARED :: #config(RAYGUI_SHARED, false)
10+
-
11+
-when ODIN_OS == .Windows {
12+
- foreign import lib {
13+
- "windows/rayguidll.lib" when RAYGUI_SHARED else "windows/raygui.lib",
14+
- }
15+
-} else when ODIN_OS == .Linux {
16+
- foreign import lib {
17+
- "linux/libraygui.so" when RAYGUI_SHARED else "linux/libraygui.a",
18+
- }
19+
-} else when ODIN_OS == .Darwin {
20+
- when ODIN_ARCH == .arm64 {
21+
- foreign import lib {
22+
- "macos-arm64/libraygui.dylib" when RAYGUI_SHARED else "macos-arm64/libraygui.a",
23+
- }
24+
- } else {
25+
- foreign import lib {
26+
- "macos/libraygui.dylib" when RAYGUI_SHARED else "macos/libraygui.a",
27+
- }
28+
- }
29+
-} else {
30+
- foreign import lib "system:raygui"
31+
+foreign import lib {
32+
+ "system:raygui",
33+
}
34+
35+
RAYGUI_VERSION :: "4.0"
36+
diff --git a/vendor/raylib/raylib.odin b/vendor/raylib/raylib.odin
37+
index a5be660c6..6d1f4d0d9 100644
38+
--- a/vendor/raylib/raylib.odin
39+
+++ b/vendor/raylib/raylib.odin
40+
@@ -99,36 +99,10 @@ MAX_TEXT_BUFFER_LENGTH :: #config(RAYLIB_MAX_TEXT_BUFFER_LENGTH, 1024)
41+
42+
#assert(size_of(rune) == size_of(c.int))
43+
44+
-RAYLIB_SHARED :: #config(RAYLIB_SHARED, false)
45+
-
46+
-when ODIN_OS == .Windows {
47+
- @(extra_linker_flags="/NODEFAULTLIB:" + ("msvcrt" when RAYLIB_SHARED else "libcmt"))
48+
- foreign import lib {
49+
- "windows/raylibdll.lib" when RAYLIB_SHARED else "windows/raylib.lib" ,
50+
- "system:Winmm.lib",
51+
- "system:Gdi32.lib",
52+
- "system:User32.lib",
53+
- "system:Shell32.lib",
54+
- }
55+
-} else when ODIN_OS == .Linux {
56+
- foreign import lib {
57+
- // Note(bumbread): I'm not sure why in `linux/` folder there are
58+
- // multiple copies of raylib.so, but since these bindings are for
59+
- // particular version of the library, I better specify it. Ideally,
60+
- // though, it's best specified in terms of major (.so.4)
61+
- "linux/libraylib.so.550" when RAYLIB_SHARED else "linux/libraylib.a",
62+
- "system:dl",
63+
- "system:pthread",
64+
- }
65+
-} else when ODIN_OS == .Darwin {
66+
- foreign import lib {
67+
- "macos/libraylib.550.dylib" when RAYLIB_SHARED else "macos/libraylib.a",
68+
- "system:Cocoa.framework",
69+
- "system:OpenGL.framework",
70+
- "system:IOKit.framework",
71+
- }
72+
-} else {
73+
- foreign import lib "system:raylib"
74+
+foreign import lib {
75+
+ "system:raylib",
76+
+ "system:dl",
77+
+ "system:pthread",
78+
}
79+
80+
VERSION_MAJOR :: 5
81+
diff --git a/vendor/raylib/rlgl/rlgl.odin b/vendor/raylib/rlgl/rlgl.odin
82+
index 9d4682294..f39ea2035 100644
83+
--- a/vendor/raylib/rlgl/rlgl.odin
84+
+++ b/vendor/raylib/rlgl/rlgl.odin
85+
@@ -112,43 +112,10 @@ import rl "../."
86+
87+
VERSION :: "5.0"
88+
89+
-RAYLIB_SHARED :: #config(RAYLIB_SHARED, false)
90+
-
91+
-// Note: We pull in the full raylib library. If you want a truly stand-alone rlgl, then:
92+
-// - Compile a separate rlgl library and use that in the foreign import blocks below.
93+
-// - Remove the `import rl "../."` line
94+
-// - Copy the code from raylib.odin for any types we alias from that package (see PixelFormat etc)
95+
-
96+
-when ODIN_OS == .Windows {
97+
- @(extra_linker_flags="/NODEFAULTLIB:" + ("msvcrt" when RAYLIB_SHARED else "libcmt"))
98+
- foreign import lib {
99+
- "../windows/raylibdll.lib" when RAYLIB_SHARED else "../windows/raylib.lib" ,
100+
- "system:Winmm.lib",
101+
- "system:Gdi32.lib",
102+
- "system:User32.lib",
103+
- "system:Shell32.lib",
104+
- }
105+
-} else when ODIN_OS == .Linux {
106+
- foreign import lib {
107+
- // Note(bumbread): I'm not sure why in `linux/` folder there are
108+
- // multiple copies of raylib.so, but since these bindings are for
109+
- // particular version of the library, I better specify it. Ideally,
110+
- // though, it's best specified in terms of major (.so.4)
111+
- "../linux/libraylib.so.500" when RAYLIB_SHARED else "../linux/libraylib.a",
112+
- "system:dl",
113+
- "system:pthread",
114+
- }
115+
-} else when ODIN_OS == .Darwin {
116+
- foreign import lib {
117+
- "../macos" +
118+
- ("-arm64" when ODIN_ARCH == .arm64 else "") +
119+
- "/libraylib" + (".500.dylib" when RAYLIB_SHARED else ".a"),
120+
- "system:Cocoa.framework",
121+
- "system:OpenGL.framework",
122+
- "system:IOKit.framework",
123+
- }
124+
-} else {
125+
- foreign import lib "system:raylib"
126+
+foreign import lib {
127+
+ "system:raygui",
128+
+ "system:dl",
129+
+ "system:pthread",
130+
}
131+
132+
GRAPHICS_API_OPENGL_11 :: false

odin/odin.nix

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
fetchFromGitHub,
3+
lib,
4+
llvmPackages,
5+
makeBinaryWrapper,
6+
which,
7+
}: let
8+
inherit (llvmPackages) stdenv;
9+
in
10+
stdenv.mkDerivation {
11+
pname = "odin";
12+
version = "2024-12-06";
13+
14+
src = fetchFromGitHub {
15+
owner = "odin-lang";
16+
repo = "Odin";
17+
rev = "dev-2024-12";
18+
hash = "sha256-BkPdVzgbEc3S4eSi5TbFKPzkRGkaJTILN/g9o8hfdEw=";
19+
};
20+
21+
patches = [./odin-system-raylib.patch];
22+
23+
dontConfigure = true;
24+
LLVM_CONFIG = "${llvmPackages.llvm.dev}/bin/llvm-config";
25+
26+
buildFlags = ["release"];
27+
28+
nativeBuildInputs = [
29+
makeBinaryWrapper
30+
which
31+
];
32+
33+
postPatch = ''
34+
patchShebangs build_odin.sh
35+
'';
36+
37+
installPhase = ''
38+
runHook preInstall
39+
40+
mkdir -p $out/bin
41+
cp odin $out/bin/odin
42+
43+
mkdir -p $out/share
44+
cp -r {base,core,shared} $out/share
45+
46+
mkdir -p $out/share/vendor/raylib
47+
cp -r vendor/raylib/{rlgl,*.odin} $out/share/vendor/raylib
48+
49+
# make -C "$out/share/vendor/cgltf/src/"
50+
# make -C "$out/share/vendor/stb/src/"
51+
# make -C "$out/share/vendor/miniaudio/src/"
52+
53+
wrapProgram $out/bin/odin \
54+
--set-default ODIN_ROOT $out/share \
55+
--prefix PATH : ${
56+
lib.makeBinPath (
57+
with llvmPackages; [
58+
bintools
59+
llvm
60+
clang
61+
lld
62+
]
63+
)
64+
}
65+
66+
runHook postInstall
67+
'';
68+
}

0 commit comments

Comments
 (0)