diff --git a/flake.lock b/flake.lock index ca8c578080..cf736beb1b 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,35 @@ { "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1649676176, + "narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1629481132, + "narHash": "sha256-JHgasjPR0/J1J3DRm4KxM4zTyAj4IOJY8vIl75v/kPI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "997f7efcb746a9c140ce1f13c72263189225f482", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1647282937, @@ -32,10 +62,47 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1631288242, + "narHash": "sha256-sXm4KiKs7qSIf5oTAmrlsEvBW193sFj+tKYVirBaXz0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0e24c87754430cb6ad2f8c8c8021b29834a8845e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", - "nixpkgs-unstable": "nixpkgs-unstable" + "nixpkgs-unstable": "nixpkgs-unstable", + "zig": "zig" + } + }, + "zig": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1650415318, + "narHash": "sha256-HZDhiEELVjhZf9pR0Y3cYVFI7SZVCiSc1g3yqvMYdFk=", + "owner": "roarkanize", + "repo": "zig-overlay", + "rev": "da3b287c1d29761e576ad81ac94aed260744d20d", + "type": "github" + }, + "original": { + "owner": "roarkanize", + "repo": "zig-overlay", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index e660b3656c..527c677247 100644 --- a/flake.nix +++ b/flake.nix @@ -4,67 +4,83 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; nixpkgs-unstable = { url = "github:NixOS/nixpkgs/nixpkgs-unstable"; }; - # zig = { url = "github:roarkanize/zig-overlay"; }; + zig = { url = "github:roarkanize/zig-overlay"; }; + flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, nixpkgs-unstable }: - let - pkgs = nixpkgs.legacyPackages.x86_64-linux; - unstable-pkgs = nixpkgs-unstable.legacyPackages.x86_64-linux; - llvmPkgs = pkgs.llvmPackages_12; + outputs = { self, nixpkgs, nixpkgs-unstable, zig, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + unstable-pkgs = nixpkgs-unstable.legacyPackages.${system}; + llvmPkgs = pkgs.llvmPackages_12; - linuxInputs = with pkgs; [ - valgrind # used in cli tests, see cli/tests/cli_run.rs - vulkan-headers - vulkan-loader - vulkan-tools - vulkan-validation-layers - xorg.libX11 - xorg.libXcursor - xorg.libXrandr - xorg.libXi - xorg.libxcb - alsa-lib - ]; + linuxInputs = with pkgs; + lib.optionals stdenv.isLinux [ + valgrind # used in cli tests, see cli/tests/cli_run.rs + vulkan-headers + vulkan-loader + vulkan-tools + vulkan-validation-layers + xorg.libX11 + xorg.libXcursor + xorg.libXrandr + xorg.libXi + xorg.libxcb + alsa-lib + ]; - sharedInputs = (with pkgs; [ - # build libraries - cmake - git - python3 - llvmPkgs.llvm.dev - llvmPkgs.clang - libxkbcommon - pkg-config - zig # roc builtins are implemented in zig, see compiler/builtins/bitcode/ - - # lib deps - libffi - libxml2 - ncurses - zlib - libiconv - - # faster builds - see https://github.com/rtfeldman/roc/blob/trunk/BUILDING_FROM_SOURCE.md#use-lld-for-the-linker - llvmPkgs.lld - # debugir - ]) ++ (with unstable-pkgs; [ - rustc - cargo - clippy - rustfmt + darwinInputs = with pkgs; + lib.optionals stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [ + AppKit + CoreFoundation + CoreServices + CoreVideo + Foundation + Metal + Security ]); - in { - devShell.x86_64-linux = pkgs.mkShell { - buildInputs = sharedInputs ++ linuxInputs; + # zig 0.8.1 from pkgs is broken on aarch64-darwin, hence the workaround + zig-toolchain = zig.packages.${system}."0.8.1"; - LLVM_SYS_120_PREFIX = "${llvmPkgs.llvm.dev}"; - NIX_GLIBC_PATH = if pkgs.stdenv.isLinux then "${pkgs.glibc_multi.out}/lib" else ""; - LD_LIBRARY_PATH = with pkgs; - lib.makeLibraryPath - ([ pkg-config stdenv.cc.cc.lib libffi ncurses zlib ] ++ linuxInputs); - }; + sharedInputs = (with pkgs; [ + # build libraries + cmake + git + python3 + llvmPkgs.llvm.dev + llvmPkgs.clang + libxkbcommon + pkg-config + zig-toolchain # roc builtins are implemented in zig, see compiler/builtins/bitcode/ - }; + # lib deps + libffi + libxml2 + ncurses + zlib + libiconv + + # faster builds - see https://github.com/rtfeldman/roc/blob/trunk/BUILDING_FROM_SOURCE.md#use-lld-for-the-linker + llvmPkgs.lld + # debugir + ]) ++ (with unstable-pkgs; [ + rustc + cargo + clippy + rustfmt + ]); + in { + devShell = pkgs.mkShell { + buildInputs = sharedInputs ++ darwinInputs ++ linuxInputs; + + LLVM_SYS_120_PREFIX = "${llvmPkgs.llvm.dev}"; + NIX_GLIBC_PATH = if pkgs.stdenv.isLinux then "${pkgs.glibc_multi.out}/lib" else ""; + LD_LIBRARY_PATH = with pkgs; + lib.makeLibraryPath + ([ pkg-config stdenv.cc.cc.lib libffi ncurses zlib ]); + }; + } + ); }