diff --git a/default.nix b/default.nix index c76470841f..c2eb6c7b53 100644 --- a/default.nix +++ b/default.nix @@ -1,30 +1,28 @@ { rev ? "541a3ca27c9a8220b46f4feb7dd8e94336a77f42", # nixpkgs master - nixpkgsSource ? builtins.fetchTarball { - url = "https://github.com/nixos/nixpkgs/tarball/${rev}"; - sha256 = "sha256:1mxv0zigm98pawf05kd4s8ipvk1pvvdsn1yh978c5an97kz0ck5w"; - }, - pkgs ? import nixpkgsSource { }, - cargoSha256 ? "sha256-treL2sWPcZ1NBwdab3FOb2FI2wT/Vt9tD4XRfJ8rYWA=", -}: +nixpkgsSource ? builtins.fetchTarball { + url = "https://github.com/nixos/nixpkgs/tarball/${rev}"; + sha256 = "sha256:1mxv0zigm98pawf05kd4s8ipvk1pvvdsn1yh978c5an97kz0ck5w"; +}, pkgs ? import nixpkgsSource { } +, cargoSha256 ? "sha256-treL2sWPcZ1NBwdab3FOb2FI2wT/Vt9tD4XRfJ8rYWA=", }: # we only this file to release a nix package, use flake.nix for development let rustPlatform = pkgs.rustPlatform; llvmPkgs = pkgs.llvmPackages_13; # nix does not store libs in /usr/lib or /lib nixGlibcPath = if pkgs.stdenv.isLinux then "${pkgs.glibc.out}/lib" else ""; -in -rustPlatform.buildRustPackage { +in rustPlatform.buildRustPackage { pname = "roc"; version = "0.0.1"; - src = pkgs.nix-gitignore.gitignoreSource [] ./.; + src = pkgs.nix-gitignore.gitignoreSource [ ] ./.; inherit cargoSha256; LLVM_SYS_130_PREFIX = "${llvmPkgs.llvm.dev}"; # required for zig - XDG_CACHE_HOME = "xdg_cache"; # prevents zig AccessDenied error github.com/ziglang/zig/issues/6810 + XDG_CACHE_HOME = + "xdg_cache"; # prevents zig AccessDenied error github.com/ziglang/zig/issues/6810 # want to see backtrace in case of failure RUST_BACKTRACE = 1; @@ -45,17 +43,17 @@ rustPlatform.buildRustPackage { rust-bindgen ]); - buildInputs = (with pkgs; [ - libffi - libiconv - libxkbcommon - libxml2 - ncurses - zlib - cargo - makeWrapper # necessary for postBuild wrapProgram - ] - ++ lib.optionals pkgs.stdenv.isLinux [ + buildInputs = (with pkgs; + [ + libffi + libiconv + libxkbcommon + libxml2 + ncurses + zlib + cargo + makeWrapper # necessary for postBuild wrapProgram + ] ++ lib.optionals pkgs.stdenv.isLinux [ alsa-lib valgrind vulkan-headers @@ -67,8 +65,7 @@ rustPlatform.buildRustPackage { xorg.libXi xorg.libXrandr xorg.libxcb - ] - ++ lib.optionals pkgs.stdenv.isDarwin [ + ] ++ lib.optionals pkgs.stdenv.isDarwin [ pkgs.darwin.apple_sdk.frameworks.AppKit pkgs.darwin.apple_sdk.frameworks.CoreFoundation pkgs.darwin.apple_sdk.frameworks.CoreServices @@ -76,15 +73,19 @@ rustPlatform.buildRustPackage { pkgs.darwin.apple_sdk.frameworks.Foundation pkgs.darwin.apple_sdk.frameworks.Metal pkgs.darwin.apple_sdk.frameworks.Security - ]); + ]); # cp: to copy str.zig,list.zig... # wrapProgram pkgs.stdenv.cc: to make ld available for compiler/build/src/link.rs postInstall = if pkgs.stdenv.isLinux then '' cp -r target/x86_64-unknown-linux-gnu/release/lib/. $out/lib - wrapProgram $out/bin/roc --set NIX_GLIBC_PATH ${nixGlibcPath} --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.stdenv.cc ]} + wrapProgram $out/bin/roc --set NIX_GLIBC_PATH ${nixGlibcPath} --prefix PATH : ${ + pkgs.lib.makeBinPath [ pkgs.stdenv.cc ] + } '' else '' cp -r target/aarch64-apple-darwin/release/lib/. $out/lib - wrapProgram $out/bin/roc --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.stdenv.cc ]} + wrapProgram $out/bin/roc --prefix PATH : ${ + pkgs.lib.makeBinPath [ pkgs.stdenv.cc ] + } ''; } diff --git a/devtools/vscodeflake.nix b/devtools/vscodeflake.nix index d0c4422109..888371bd5c 100644 --- a/devtools/vscodeflake.nix +++ b/devtools/vscodeflake.nix @@ -8,10 +8,8 @@ flake-utils.url = "github:numtide/flake-utils"; }; outputs = { self, roc, flake-utils }: - let - supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ]; - in - flake-utils.lib.eachSystem supportedSystems (system: + let supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ]; + in flake-utils.lib.eachSystem supportedSystems (system: let pkgs = import roc.inputs.nixpkgs { inherit system; @@ -19,28 +17,19 @@ }; rocShell = roc.devShell.${system}; - in - { + in { devShell = pkgs.mkShell { - packages = - let - devInputs = (with pkgs; [ - less - gdb - ]); - vscodeWithExtensions = pkgs.vscode-with-extensions.override { - vscodeExtensions = with pkgs.vscode-extensions; [ - matklad.rust-analyzer - eamodio.gitlens - bbenoist.nix - vadimcn.vscode-lldb - ]; - }; - in - [ - vscodeWithExtensions - devInputs - ]; + packages = let + devInputs = (with pkgs; [ less gdb ]); + vscodeWithExtensions = pkgs.vscode-with-extensions.override { + vscodeExtensions = with pkgs.vscode-extensions; [ + matklad.rust-analyzer + eamodio.gitlens + bbenoist.nix + vadimcn.vscode-lldb + ]; + }; + in [ vscodeWithExtensions devInputs ]; inputsFrom = [ rocShell ]; diff --git a/flake.nix b/flake.nix index 628b8e3a1c..cd69ec0155 100644 --- a/flake.nix +++ b/flake.nix @@ -24,20 +24,18 @@ }; outputs = { self, nixpkgs, rust-overlay, zig, flake-utils, nixgl }: - let - supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ]; - in - flake-utils.lib.eachSystem supportedSystems (system: + let supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ]; + in flake-utils.lib.eachSystem supportedSystems (system: let - overlays = [ (import rust-overlay) ] ++ (if system == "x86_64-linux" then [ nixgl.overlay ] else []); - pkgs = import nixpkgs { - inherit system overlays; - }; + overlays = [ (import rust-overlay) ] + ++ (if system == "x86_64-linux" then [ nixgl.overlay ] else [ ]); + pkgs = import nixpkgs { inherit system overlays; }; llvmPkgs = pkgs.llvmPackages_13; # get current working directory cwd = builtins.toString ./.; - rust = pkgs.rust-bin.fromRustupToolchainFile "${cwd}/rust-toolchain.toml"; + rust = + pkgs.rust-bin.fromRustupToolchainFile "${cwd}/rust-toolchain.toml"; linuxInputs = with pkgs; lib.optionals stdenv.isLinux [ @@ -55,7 +53,8 @@ ]; darwinInputs = with pkgs; - lib.optionals stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [ + lib.optionals stdenv.isDarwin + (with pkgs.darwin.apple_sdk.frameworks; [ AppKit CoreFoundation CoreServices @@ -114,22 +113,27 @@ rust rust-bindgen ]); - in - { + in { devShell = pkgs.mkShell { - buildInputs = sharedInputs ++ darwinInputs ++ linuxInputs ++ (if system == "x86_64-linux" then [ pkgs.nixgl.nixVulkanIntel ] else []); + buildInputs = sharedInputs ++ darwinInputs ++ linuxInputs + ++ (if system == "x86_64-linux" then + [ pkgs.nixgl.nixVulkanIntel ] + else + [ ]); LLVM_SYS_130_PREFIX = "${llvmPkgs.llvm.dev}"; # nix does not store libs in /usr/lib or /lib - NIX_GLIBC_PATH = if pkgs.stdenv.isLinux then "${pkgs.glibc.out}/lib" else ""; + NIX_GLIBC_PATH = + if pkgs.stdenv.isLinux then "${pkgs.glibc.out}/lib" else ""; LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath - ([ pkg-config stdenv.cc.cc.lib libffi ncurses zlib] ++ linuxInputs); - NIXPKGS_ALLOW_UNFREE = 1; # to run the editor with NVIDIA's closed source drivers + ([ pkg-config stdenv.cc.cc.lib libffi ncurses zlib ] + ++ linuxInputs); + NIXPKGS_ALLOW_UNFREE = + 1; # to run the editor with NVIDIA's closed source drivers }; formatter = pkgs.nixpkgs-fmt; - } - ); + }); }