From 7aa06cd4b65b97bdf5e3877df8b74ea691561b25 Mon Sep 17 00:00:00 2001 From: Arsalan Date: Fri, 3 Jan 2025 14:06:19 +0400 Subject: [PATCH] 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 (https://github.com/odin-lang/Odin/pull/4619) --- configuration.nix | 4 +- flake.lock | 47 ++++++++---- flake.nix | 16 +++-- home.nix | 5 +- odin/odin-system-raylib.patch | 132 ++++++++++++++++++++++++++++++++++ odin/odin.nix | 68 ++++++++++++++++++ 6 files changed, 249 insertions(+), 23 deletions(-) create mode 100644 odin/odin-system-raylib.patch create mode 100644 odin/odin.nix diff --git a/configuration.nix b/configuration.nix index 4b428df..7e89a7b 100644 --- a/configuration.nix +++ b/configuration.nix @@ -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; @@ -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 diff --git a/flake.lock b/flake.lock index 42f883b..a561776 100644 --- a/flake.lock +++ b/flake.lock @@ -447,34 +447,50 @@ "type": "github" } }, - "nixpkgs-stable": { + "nixpkgs-custom": { "locked": { - "lastModified": 1730741070, - "narHash": "sha256-edm8WG19kWozJ/GqyYx2VjW99EdhjKwbY3ZwdlPAAlo=", - "owner": "NixOS", + "lastModified": 1735391491, + "narHash": "sha256-NaKIJZxQFsvdPbI50atycR1hXhCYyc6d4Is6X2KHLGY=", + "owner": "Arsalan2356", "repo": "nixpkgs", - "rev": "d063c1dd113c91ab27959ba540c0d9753409edf3", + "rev": "25b794817ea71a355bd9669ecc43c3b6af2ae475", "type": "github" }, "original": { - "owner": "NixOS", - "ref": "nixos-24.05", + "owner": "Arsalan2356", + "ref": "custom", "repo": "nixpkgs", "type": "github" } }, - "nixpkgs-test": { + "nixpkgs-master": { "locked": { - "lastModified": 1735391491, - "narHash": "sha256-NaKIJZxQFsvdPbI50atycR1hXhCYyc6d4Is6X2KHLGY=", - "owner": "Arsalan2356", + "lastModified": 1735897677, + "narHash": "sha256-rXGKcuK0r/EU7aDx0AC/GVixgg/U/dIxJkJtAW/j/No=", + "owner": "nixos", "repo": "nixpkgs", - "rev": "25b794817ea71a355bd9669ecc43c3b6af2ae475", + "rev": "b4e1c1f013a24039b6a9e9e80655e3bab96c90a5", "type": "github" }, "original": { - "owner": "Arsalan2356", - "ref": "custom", + "owner": "nixos", + "ref": "master", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1730741070, + "narHash": "sha256-edm8WG19kWozJ/GqyYx2VjW99EdhjKwbY3ZwdlPAAlo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d063c1dd113c91ab27959ba540c0d9753409edf3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", "repo": "nixpkgs", "type": "github" } @@ -545,7 +561,8 @@ "hyprland-contrib": "hyprland-contrib", "hyprspace": "hyprspace", "nixpkgs": "nixpkgs_3", - "nixpkgs-test": "nixpkgs-test" + "nixpkgs-custom": "nixpkgs-custom", + "nixpkgs-master": "nixpkgs-master" } }, "systems": { diff --git a/flake.nix b/flake.nix index 3431f0b..a154def 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; @@ -25,7 +29,7 @@ inputs.nixpkgs.follows = "nixpkgs"; }; - nixpkgs-test = { + nixpkgs-custom = { url = "github:Arsalan2356/nixpkgs/custom"; }; @@ -53,7 +57,11 @@ "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; }; @@ -61,13 +69,13 @@ 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 diff --git a/home.nix b/home.nix index 592ceeb..e16b71f 100644 --- a/home.nix +++ b/home.nix @@ -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 { @@ -68,7 +68,8 @@ in playerctl nvd eza - odin + (pkgs.callPackage ./odin/odin.nix {}) + pkgs-master.raylib # General diff --git a/odin/odin-system-raylib.patch b/odin/odin-system-raylib.patch new file mode 100644 index 0000000..ecb6af9 --- /dev/null +++ b/odin/odin-system-raylib.patch @@ -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 diff --git a/odin/odin.nix b/odin/odin.nix new file mode 100644 index 0000000..0047c78 --- /dev/null +++ b/odin/odin.nix @@ -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 + ''; + }