From 44e4ec57de3b3e2fdfa6dfef91a3ca72b8cb2d94 Mon Sep 17 00:00:00 2001 From: seth Date: Fri, 20 Sep 2024 22:22:24 -0400 Subject: feat: update to zig 0.13.0 (#24) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: update flake.lock Flake lock file updates: • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/9bb1e7571aadf31ddb4af77fc64b2d59580f9a39' (2024-09-05) → 'github:NixOS/nixpkgs/268bb5090a3c6ac5e1615b38542a868b52ef8088' (2024-09-19) • Updated input 'zig-overlay': 'github:mitchellh/zig-overlay/9e2cc0e99621be1b765dc95a8ec80740a685b660' (2024-09-06) → 'github:mitchellh/zig-overlay/2419eb9f968f451e2c342a69ec44112de5aa36b9' (2024-09-21) * style: use nixfmt * style: format with nixfmt * refactor: use flake-utils * fix: only use `zig` in dev shell Pulling in `zig.hook` sets variables like `ZIG_GLOBAL_CACHE_DIR` that don't work too nicely outside of a Nix build process -- as in, Zig can't access files and fails * feat: update to zig 0.13.0 * chore: remove library output This isn't needed for this example --- flake.nix | 117 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 56 insertions(+), 61 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index 0733e33..e86a61d 100644 --- a/flake.nix +++ b/flake.nix @@ -3,76 +3,71 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + flake-utils.url = "github:numtide/flake-utils"; + zig-overlay = { url = "github:mitchellh/zig-overlay"; - inputs.nixpkgs.follows = "nixpkgs"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + # We don't use this + flake-compat.follows = ""; + }; }; }; - outputs = { - self, - nixpkgs, - zig-overlay, - ... - }: let - systems = [ - "x86_64-linux" - "aarch64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; + outputs = + { + self, + nixpkgs, + flake-utils, + zig-overlay, + }: + let + # https://github.com/mitchellh/zig-overlay?tab=readme-ov-file#usage + zigVersion = "0.13.0"; + in + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; - forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system}); + zig = zig-overlay.packages.${system}.${zigVersion}.overrideAttrs { + # FIXME: `zig.hook` requires `zig` to have it's `meta` attribute + # zig-overlay doesn't provide this...yay + inherit (pkgs.zig) meta; + }; + in + rec { + devShells.default = pkgs.mkShellNoCC { + packages = [ zig ]; + }; - # https://github.com/mitchellh/zig-overlay?tab=readme-ov-file#usage - zigVersion = "master-2024-05-08"; - zigFor = system: zig-overlay.packages.${system}.${zigVersion}; - in { - devShells = forAllSystems ({ - pkgs, - system, - ... - }: { - default = pkgs.mkShellNoCC { - inputsFrom = [self.packages.${system}.ziggy-with-it]; - }; - }); + formatter = pkgs.nixfmt-rfc-style; - packages = forAllSystems ({ - lib, - pkgs, - system, - ... - }: rec { - default = ziggy-with-it; - ziggy-with-it = pkgs.stdenvNoCC.mkDerivation { - pname = "ziggy-with-it"; - version = self.shortRev or self.dirtyShortRev or "waaaa"; + packages = { + default = packages.ziggy-with-it; - src = with lib.fileset; - toSource { - root = ./.; - fileset = unions [ - (gitTracked ./src) - ./build.zig - ./build.zig.zon - ]; - }; + # NOTE: We use `stdenvNoCC` here as `zig` is all we need + ziggy-with-it = pkgs.stdenvNoCC.mkDerivation { + pname = "ziggy-with-it"; + version = self.shortRev or self.dirtyShortRev or "waaaa"; - # `deps.nix` is generated with by running `zon2nix` - # https://github.com/nix-community/zon2nix - postPatch = '' - ln -s ${pkgs.callPackage ./deps.nix {}} $ZIG_GLOBAL_CACHE_DIR/p - ''; + src = self; - nativeBuildInputs = [ - (pkgs.zig.hook.override { - # FIXME: `zig.hook` requires `zig` to have it's `meta` attribute - # zig-overlay requires this `meta` attribute..yay - zig = zigFor system // {inherit (pkgs.zig) meta;}; - }) - ]; - }; - }); - }; + # `deps.nix` is generated with by running `zon2nix` + # https://github.com/nix-community/zon2nix + postPatch = '' + ln -s ${pkgs.callPackage ./deps.nix { }} $ZIG_GLOBAL_CACHE_DIR/p + ''; + + nativeBuildInputs = [ + # We can use nixpkgs' `zig.hook`, but with our own `zig` + (pkgs.zig.hook.override { inherit zig; }) + ]; + }; + }; + } + ); } -- cgit v1.2.3