diff --git a/flake.lock b/flake.lock index 83db597..842cd79 100644 --- a/flake.lock +++ b/flake.lock @@ -16,25 +16,25 @@ "type": "github" } }, - "flake-parts": { + "flake-utils": { "inputs": { - "nixpkgs-lib": "nixpkgs-lib" + "systems": "systems" }, "locked": { - "lastModified": 1696343447, - "narHash": "sha256-B2xAZKLkkeRFG5XcHHSXXcP7To9Xzr59KXeZiRf4vdQ=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4", + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "type": "github" }, "original": { - "owner": "hercules-ci", - "repo": "flake-parts", + "owner": "numtide", + "repo": "flake-utils", "type": "github" } }, - "flake-utils": { + "flake-utils_2": { "locked": { "lastModified": 1659877975, "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", @@ -51,52 +51,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1696983906, - "narHash": "sha256-L7GyeErguS7Pg4h8nK0wGlcUTbfUMDu+HMf1UcyP72k=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "bd1cde45c77891214131cbbea5b1203e485a9d51", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-23.05", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-lib": { - "locked": { - "dir": "lib", - "lastModified": 1696019113, - "narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=", + "lastModified": 1696725822, + "narHash": "sha256-B7uAOS7TkLlOg1aX01rQlYbydcyB6ZnLJSfaYbKVww8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a", + "rev": "5aabb5780a11c500981993d49ee93cfa6df9307b", "type": "github" }, "original": { - "dir": "lib", - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-unstable": { - "locked": { - "lastModified": 1697009197, - "narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" + "id": "nixpkgs", + "type": "indirect" } }, "nixpkgs_2": { @@ -117,24 +81,38 @@ }, "root": { "inputs": { - "flake-parts": "flake-parts", + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", - "nixpkgs-unstable": "nixpkgs-unstable", - "zig-overlay": "zig-overlay" + "zig": "zig" } }, - "zig-overlay": { + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "zig": { "inputs": { "flake-compat": "flake-compat", - "flake-utils": "flake-utils", + "flake-utils": "flake-utils_2", "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1697198920, - "narHash": "sha256-dtaoksNoOMC3H+FDF3cK+bP+jYvJokYBAFvzCALLDYk=", + "lastModified": 1696810944, + "narHash": "sha256-yvt223HLZlAJa/u4uzT5aw3ph2bifto/KfU2k+eX+jg=", "owner": "mitchellh", "repo": "zig-overlay", - "rev": "2d779a7657e346323ab048b218994dbdc42655d7", + "rev": "6dc03885321cc8aad6356c847148eb40e167f9fb", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 823a8df..f1f53ba 100644 --- a/flake.nix +++ b/flake.nix @@ -1,59 +1,47 @@ { description = "FabApp"; + # Inspired by https://github.com/mitchellh/zig-objc/blob/main/flake.nix inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; - nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable"; - zig-overlay.url = "github:mitchellh/zig-overlay"; - flake-parts.url = "github:hercules-ci/flake-parts"; + # take unstable if not specified + # nixpkgs.url = "github:nixos/nixpkgs/release-23.05"; + # nixpkgs.url = "github:NixOS/nixpkgs/unstable"; + flake-utils.url = "github:numtide/flake-utils"; + zig.url = "github:mitchellh/zig-overlay"; }; - outputs = inputs@{ flake-parts, nixpkgs, ... }: - flake-parts.lib.mkFlake { inherit inputs; } { - flake = { - # Put your original flake attributes here. - }; - - systems = [ "x86_64-linux" ]; - - # https://flake.parts/module-arguments.html#persystem-module-parameters - perSystem = { pkgs, system, ... }: { - # We need unstable for Zig - _module.args.pkgs = import inputs.nixpkgs-unstable { - inherit system; - # https://flake.parts/overlays - overlays = [ - inputs.zig-overlay.overlays.default + outputs = { + self, + nixpkgs, + flake-utils, + ... + } @ inputs: let + overlays = [ + (final: prev: { + zigpkgs = inputs.zig.packages.${prev.system}; + }) + ]; + systems = ["x86_64-linux"]; + in + flake-utils.lib.eachSystem systems ( + system: let + pkgs = import nixpkgs {inherit overlays system;}; + in rec { + devShells.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + zigpkgs.master + zls + emscripten + ]; + buildInputs = with pkgs; [ + sqlite + + # Linux graphical deps + xorg.libX11 + libGL ]; - config = { }; }; - - formatter = pkgs.nixfmt; - - devShells.default = with pkgs; - mkShell { - buildInputs = [ - sqlite - - # Zig / webAssembly impl. - zig - # zigpkgs."master" # Issue with X11/GL libraries - zls - emscripten - - # Linux graphical deps - xorg.libX11 - libGL - # xorg.libXcursor - # xorg.libXi - # xorg.libXext - # xorg.libXrandr - # xorg.libXinerama - # libGLU - ]; - - }; - - }; - }; + formatter = pkgs.alejandra; + } + ); } diff --git a/src/main.zig b/src/main.zig index 253a226..d7091b6 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,5 +1,11 @@ const std = @import("std"); -const raylib = @import("raylib.zig"); +const raylib = @cImport({ + @cInclude("raylib.h"); +}); +const raygui = @cImport({ + @cDefine("RAYGUI_IMPLEMENTATION", "1"); + @cInclude("raygui.h"); +}); const sqlite = @cImport({ @cInclude("sqlite3.h"); }); @@ -15,7 +21,7 @@ pub fn main() !void { raylib.ClearBackground(raylib.RAYWHITE); raylib.DrawText("Congrats! You created your first window!", 190, 200, 20, raylib.LIGHTGRAY); - if (raylib.GuiButton(.{ .x = 0, .y = 0, .width = 100, .height = 100 }, "MyButton") == 1) {} + if (raygui.GuiButton(.{ .x = 0, .y = 0, .width = 100, .height = 100 }, "MyButton") == 1) {} } raylib.CloseWindow(); } diff --git a/src/raylib.zig b/src/raylib.zig deleted file mode 100644 index e58a659..0000000 --- a/src/raylib.zig +++ /dev/null @@ -1,5 +0,0 @@ -pub usingnamespace @cImport({ - @cInclude("raylib.h"); - @cDefine("RAYGUI_IMPLEMENTATION", "1"); - @cInclude("raygui.h"); -});