roc/flake.nix

166 lines
5.5 KiB
Nix
Raw Normal View History

{
description = "Roc flake";
inputs = {
2023-07-25 18:44:46 +03:00
nixpkgs.url = "github:nixos/nixpkgs?rev=821c72743ceae44bdd09718d47cab98fd5fd90af";
2022-07-14 16:04:11 +03:00
# rust from nixpkgs has some libc problems, this is patched in the rust-overlay
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
2022-07-14 16:04:11 +03:00
};
# to easily make configs for multiple architectures
flake-utils.url = "github:numtide/flake-utils";
2023-09-11 17:40:52 +03:00
# to be able to use vulkan system libs for graphics in examples/gui
2022-07-14 16:04:11 +03:00
nixgl = {
url = "github:guibou/nixGL";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
2022-07-14 16:04:11 +03:00
};
};
2022-08-22 18:55:15 +03:00
outputs = { self, nixpkgs, rust-overlay, flake-utils, nixgl }:
let supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ];
in flake-utils.lib.eachSystem supportedSystems (system:
2022-06-03 17:51:54 +03:00
let
overlays = [ (import rust-overlay) ]
++ (if system == "x86_64-linux" then [ nixgl.overlay ] else [ ]);
pkgs = import nixpkgs { inherit system overlays; };
2022-06-03 17:51:54 +03:00
llvmPkgs = pkgs.llvmPackages_13;
2022-06-03 17:51:54 +03:00
# get current working directory
cwd = builtins.toString ./.;
rust =
pkgs.rust-bin.fromRustupToolchainFile "${cwd}/rust-toolchain.toml";
2023-09-11 17:40:52 +03:00
# DevInputs are not necessary to build roc as a user
linuxDevInputs = with pkgs;
2022-06-03 17:51:54 +03:00
lib.optionals stdenv.isLinux [
valgrind # used in cli tests, see cli/tests/cli_run.rs
2023-09-11 17:40:52 +03:00
vulkan-headers # here and below is all graphics stuff for examples/gui
2022-06-03 17:51:54 +03:00
vulkan-loader
vulkan-tools
vulkan-validation-layers
xorg.libX11
xorg.libXcursor
xorg.libXrandr
xorg.libXi
xorg.libxcb
];
2022-06-03 17:51:54 +03:00
darwinInputs = with pkgs;
lib.optionals stdenv.isDarwin
(with pkgs.darwin.apple_sdk.frameworks; [
2022-06-03 17:51:54 +03:00
AppKit
CoreFoundation
CoreServices
Foundation
Security
2023-09-11 17:40:52 +03:00
]);
# DevInputs are not necessary to build roc as a user
darwinDevInputs = with pkgs;
lib.optionals stdenv.isDarwin
(with pkgs.darwin.apple_sdk.frameworks; [
CoreVideo # for examples/gui
Metal # for examples/gui
curl # for wasm-bindgen-cli libcurl (see ./ci/www-repl.sh)
2022-05-30 20:34:04 +03:00
]);
2022-06-03 17:51:54 +03:00
# For debugging LLVM IR
debugir = pkgs.stdenv.mkDerivation {
name = "debugir";
src = pkgs.fetchFromGitHub {
owner = "vaivaswatha";
repo = "debugir";
rev = "b981e0b74872d9896ba447dd6391dfeb63332b80";
sha256 = "Gzey0SF0NZkpiObk5e29nbc41dn4Olv1dx+6YixaZH0=";
2022-05-30 20:34:04 +03:00
};
2022-06-03 17:51:54 +03:00
buildInputs = with pkgs; [ cmake libxml2 llvmPackages_13.llvm.dev ];
buildPhase = ''
mkdir build
cd build
cmake -DLLVM_DIR=${pkgs.llvmPackages_13.llvm.dev} -DCMAKE_BUILD_TYPE=Release ../
cmake --build ../
cp ../debugir .
'';
installPhase = ''
mkdir -p $out/bin
cp debugir $out/bin
'';
};
2022-06-03 17:51:54 +03:00
sharedInputs = (with pkgs; [
# build libraries
cmake
llvmPkgs.llvm.dev
llvmPkgs.clang
pkg-config
2023-07-10 19:46:41 +03:00
zig_0_9 # roc builtins are implemented in zig, see compiler/builtins/bitcode/
2022-06-03 17:51:54 +03:00
# lib deps
libffi
libxml2
ncurses
zlib
2022-08-12 22:23:05 +03:00
# faster builds - see https://github.com/roc-lang/roc/blob/main/BUILDING_FROM_SOURCE.md#use-lld-for-the-linker
2022-06-03 17:51:54 +03:00
llvmPkgs.lld
rust
2023-09-11 17:40:52 +03:00
]);
sharedDevInputs = (with pkgs; [
git
python3
libiconv # for examples/gui
libxkbcommon # for examples/gui
debugir # used in crates/compiler/build/src/program.rs
2022-12-14 21:37:07 +03:00
cargo-criterion # for benchmarks
simple-http-server # to view roc website when trying out edits
wasm-pack # for repl_wasm
2023-09-11 17:40:52 +03:00
jq # used in several bash scripts
2022-06-03 17:51:54 +03:00
]);
aliases = ''
alias clippy='cargo clippy --workspace --tests --release -- --deny warnings'
alias fmt='cargo fmt --all'
2023-07-25 18:44:46 +03:00
alias fmtc='cargo fmt --all -- --check'
'';
in {
2022-06-03 17:51:54 +03:00
devShell = pkgs.mkShell {
2023-09-11 17:40:52 +03:00
buildInputs = sharedInputs ++ sharedDevInputs ++ darwinInputs ++ darwinDevInputs++ linuxDevInputs
++ (if system == "x86_64-linux" then
[ pkgs.nixgl.nixVulkanIntel ]
else
[ ]);
2022-06-03 17:51:54 +03:00
LLVM_SYS_130_PREFIX = "${llvmPkgs.llvm.dev}";
2023-08-08 20:55:38 +03:00
2022-07-26 18:21:51 +03:00
# nix does not store libs in /usr/lib or /lib
2023-08-08 20:55:38 +03:00
# for libgcc_s.so.1
NIX_LIBGCC_S_PATH =
if pkgs.stdenv.isLinux then "${pkgs.stdenv.cc.cc.lib}/lib" else "";
# for crti.o, crtn.o, and Scrt1.o
NIX_GLIBC_PATH =
if pkgs.stdenv.isLinux then "${pkgs.glibc.out}/lib" else "";
2023-08-08 20:55:38 +03:00
2022-06-03 17:51:54 +03:00
LD_LIBRARY_PATH = with pkgs;
lib.makeLibraryPath
([ pkg-config stdenv.cc.cc.lib libffi ncurses zlib ]
2023-09-11 17:40:52 +03:00
++ linuxDevInputs);
NIXPKGS_ALLOW_UNFREE =
1; # to run the editor with NVIDIA's closed source drivers
shellHook = ''
2023-08-08 21:03:21 +03:00
${aliases}
'';
2022-06-03 17:51:54 +03:00
};
2022-05-30 20:34:04 +03:00
2022-06-03 17:51:54 +03:00
formatter = pkgs.nixpkgs-fmt;
2022-09-16 04:57:12 +03:00
# You can build this package (the roc CLI) with the `nix build` command.
2022-09-16 04:57:12 +03:00
packages.default = import ./. { inherit pkgs; };
});
}