roc/flake.nix

163 lines
5.5 KiB
Nix
Raw Normal View History

{
description = "Roc flake";
inputs = {
2023-12-26 21:08:40 +03:00
nixpkgs.url = "github:nixos/nixpkgs?rev=886c9aee6ca9324e127f9c2c4e6f68c2641c8256";
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
};
# for non flake backwards compatibility
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { self, nixpkgs, rust-overlay, flake-utils, nixgl, ... }@inputs:
let
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ];
templates = import ./nix/templates { };
in
{ inherit templates; } //
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; };
rocBuild = import ./nix { inherit pkgs; };
compile-deps = rocBuild.compile-deps;
inherit (compile-deps) zigPkg llvmPkgs llvmVersion
llvmMajorMinorStr glibcPath libGccSPath darwinInputs;
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
];
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
2023-11-15 05:22:03 +03:00
(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-06-03 17:51:54 +03:00
sharedInputs = (with pkgs; [
# build libraries
cmake
llvmPkgs.llvm.dev
llvmPkgs.clang
pkg-config
zigPkg # 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
rocBuild.rust-shell
2023-12-23 18:54:59 +03:00
perl # ./ci/update_basic_cli_url.sh
2023-09-11 17:40:52 +03:00
]);
sharedDevInputs = (with pkgs; [
git
python3
libiconv # for examples/gui
libxkbcommon # for examples/gui
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
2023-09-13 20:34:01 +03:00
cargo-nextest # used to give more info for segfaults for gen tests
2023-11-21 06:43:39 +03:00
zls # zig language server
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'
'';
2023-11-15 05:22:03 +03:00
in
{
2022-06-03 17:51:54 +03:00
devShell = pkgs.mkShell {
2023-11-15 05:22:03 +03:00
buildInputs = sharedInputs ++ sharedDevInputs ++ darwinInputs ++ darwinDevInputs ++ linuxDevInputs
++ (if system == "x86_64-linux" then
2023-11-15 05:22:03 +03:00
[ pkgs.nixgl.nixVulkanIntel ]
else
[ ]);
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
2023-11-15 05:22:03 +03:00
([ pkg-config stdenv.cc.cc.lib libffi ncurses zlib ]
++ linuxDevInputs);
NIXPKGS_ALLOW_UNFREE =
1; # to run the GUI examples with NVIDIA's closed source drivers
2023-11-15 05:22:03 +03:00
shellHook = ''
export LLVM_SYS_${llvmMajorMinorStr}_PREFIX="${llvmPkgs.llvm.dev}"
2023-08-08 21:03:21 +03:00
${aliases}
2023-12-26 21:08:40 +03:00
'' + pkgs.lib.optionalString (system == "aarch64-darwin") ''
export RUSTFLAGS="-C link-arg=-lc++abi"
''; # lc++abi as workaround for github.com/NixOS/nixpkgs/issues/166205, see also github.com/roc-lang/roc/issues/6303
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.
packages = {
2023-11-17 19:04:40 +03:00
default = rocBuild.roc-cli;
2023-11-21 04:44:58 +03:00
2023-11-17 19:04:40 +03:00
# all rust crates in workspace.members of Cargo.toml
2023-11-15 06:47:43 +03:00
full = rocBuild.roc-full;
2023-11-17 19:04:40 +03:00
# only the CLI crate = executable provided in nightly releases
cli = rocBuild.roc-cli;
lang-server = rocBuild.roc-lang-server;
};
2023-12-12 07:20:28 +03:00
apps = {
default = {
type = "app";
program = "${rocBuild.roc-cli}/bin/roc";
};
};
});
}