diff --git a/Cargo.lock b/Cargo.lock index 074866b7..d882673f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "arrayvec" version = "0.7.6" @@ -29,6 +38,29 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "aws-lc-rs" +version = "1.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dabb68eb3a7aa08b46fddfd59a3d55c978243557a90ab804769f7e20e67d2b01" +dependencies = [ + "aws-lc-sys", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bbe221bbf523b625a4dd8585c7f38166e31167ec2ca98051dbcb4c3b6e825d2" +dependencies = [ + "bindgen", + "cc", + "cmake", + "dunce", + "fs_extra", +] + [[package]] name = "backtrace" version = "0.3.69" @@ -50,6 +82,29 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "bindgen" +version = "0.69.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools", + "lazy_static", + "lazycell", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", + "which", +] + [[package]] name = "bitflags" version = "2.6.0" @@ -68,15 +123,46 @@ version = "1.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a012a0df96dd6d06ba9a1b29d6402d1a5d77c6befd2566afdc26e10603dc93d7" dependencies = [ + "jobserver", + "libc", "shlex", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "cmake" +version = "0.1.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7caa3f9de89ddbe2c607f4101924c5abec803763ae9534e4f4d7d8f84aa81f0" +dependencies = [ + "cc", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -118,12 +204,40 @@ dependencies = [ "winapi", ] +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "errno" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "futures-channel" version = "0.3.31" @@ -174,6 +288,21 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "glob" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" + +[[package]] +name = "home" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "host" version = "0.0.1" @@ -249,24 +378,64 @@ dependencies = [ "futures-util", "http", "hyper", - "rustls", + "rustls 0.21.12", "rustls-native-certs", "tokio", "tokio-rustls", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "libc" version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "libloading" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" +dependencies = [ + "cfg-if", + "windows-targets 0.52.6", +] + [[package]] name = "libsqlite3-sys" version = "0.30.1" @@ -278,6 +447,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + [[package]] name = "lock_api" version = "0.4.12" @@ -309,6 +484,12 @@ dependencies = [ "libc", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.4" @@ -330,6 +511,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "object" version = "0.32.2" @@ -392,6 +583,34 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" +[[package]] +name = "prettyplease" +version = "0.2.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1ccf34da56fc294e7d4ccf69a85992b7dfb826b7cf57bac6a70bba3494cc08a" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + [[package]] name = "redox_syscall" version = "0.5.8" @@ -401,6 +620,35 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + [[package]] name = "ring" version = "0.17.8" @@ -488,7 +736,9 @@ dependencies = [ "roc_io_error", "roc_std", "roc_std_heap", + "rustls 0.23.23", "tokio", + "webpki-roots", ] [[package]] @@ -541,6 +791,25 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "rustls" version = "0.21.12" @@ -548,10 +817,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "ring", - "rustls-webpki", + "rustls-webpki 0.101.7", "sct", ] +[[package]] +name = "rustls" +version = "0.23.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47796c98c480fce5406ef69d1c76378375492c3b0a0de587be0c1d9feb12f395" +dependencies = [ + "aws-lc-rs", + "log", + "once_cell", + "rustls-pki-types", + "rustls-webpki 0.102.8", + "subtle", + "zeroize", +] + [[package]] name = "rustls-native-certs" version = "0.6.3" @@ -573,6 +857,12 @@ dependencies = [ "base64", ] +[[package]] +name = "rustls-pki-types" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" + [[package]] name = "rustls-webpki" version = "0.101.7" @@ -583,6 +873,18 @@ dependencies = [ "untrusted", ] +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "aws-lc-rs", + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "schannel" version = "0.1.27" @@ -705,6 +1007,23 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "sys-locale" version = "0.3.2" @@ -744,7 +1063,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls", + "rustls 0.21.12", "tokio", ] @@ -779,6 +1098,12 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + [[package]] name = "untrusted" version = "0.9.0" @@ -806,6 +1131,27 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "webpki-roots" +version = "0.26.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2210b291f7ea53617fbafcc4939f10914214ec15aace5ba62293a668f322c5c9" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + [[package]] name = "winapi" version = "0.3.9" @@ -975,3 +1321,9 @@ name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/crates/roc_http/Cargo.toml b/crates/roc_http/Cargo.toml index 84ae952c..72daa6a2 100644 --- a/crates/roc_http/Cargo.toml +++ b/crates/roc_http/Cargo.toml @@ -17,3 +17,5 @@ hyper.workspace = true hyper-rustls.workspace = true tokio.workspace = true bytes.workspace = true +rustls = "0.23.23" +webpki-roots = "0.26.8" diff --git a/crates/roc_http/src/lib.rs b/crates/roc_http/src/lib.rs index fe4e0415..5180fabe 100644 --- a/crates/roc_http/src/lib.rs +++ b/crates/roc_http/src/lib.rs @@ -1,21 +1,23 @@ //! This crate provides common functionality for Roc to interface with `std::net::tcp` use roc_std::{RocBox, RocList, RocRefcounted, RocResult, RocStr}; use roc_std_heap::ThreadSafeRefcountedResourceHeap; +use rustls::pki_types::ServerName; +use rustls::{ClientConfig, ClientConnection, RootCertStore, StreamOwned}; use std::env; use std::io::{BufRead, BufReader, ErrorKind, Read, Write}; use std::net::TcpStream; -use std::sync::OnceLock; +use std::sync::{Arc, OnceLock}; pub const REQUEST_TIMEOUT_BODY: &[u8] = "RequestTimeout".as_bytes(); pub const REQUEST_NETWORK_ERR: &[u8] = "Network Error".as_bytes(); pub const REQUEST_BAD_BODY: &[u8] = "Bad Body".as_bytes(); +type TlsStream = BufReader>; -pub fn heap() -> &'static ThreadSafeRefcountedResourceHeap> { +pub fn heap() -> &'static ThreadSafeRefcountedResourceHeap { // TODO: Should this be a BufReader and BufWriter of the tcp stream? // like this: https://stackoverflow.com/questions/58467659/how-to-store-tcpstream-with-bufreader-and-bufwriter-in-a-data-structure/58491889#58491889 - static TCP_HEAP: OnceLock>> = - OnceLock::new(); + static TCP_HEAP: OnceLock> = OnceLock::new(); TCP_HEAP.get_or_init(|| { let default_max = 65536; let max_tcp_streams = env::var("ROC_BASIC_CLI_MAX_TCP_STREAMS") @@ -248,9 +250,22 @@ impl roc_std::RocRefcounted for Header { } pub fn tcp_connect(host: &RocStr, port: u16) -> RocResult, RocStr> { + let root_store = RootCertStore { + roots: webpki_roots::TLS_SERVER_ROOTS.into(), + }; + let config = ClientConfig::builder() + .with_root_certificates(root_store) + .with_no_client_auth(); + match TcpStream::connect((host.as_str(), port)) { Ok(stream) => { - let buf_reader = BufReader::new(stream); + let conn = ClientConnection::new( + Arc::new(config), + ServerName::try_from(host.as_str().to_owned()).unwrap(), + ) + .unwrap(); + let tls = rustls::StreamOwned::new(conn, stream); + let buf_reader = BufReader::new(tls); let heap = heap(); let alloc_result = heap.alloc_for(buf_reader); @@ -264,8 +279,7 @@ pub fn tcp_connect(host: &RocStr, port: u16) -> RocResult, RocStr> { } pub fn tcp_read_up_to(stream: RocBox<()>, bytes_to_read: u64) -> RocResult, RocStr> { - let stream: &mut BufReader = - ThreadSafeRefcountedResourceHeap::box_to_resource(stream); + let stream: &mut TlsStream = ThreadSafeRefcountedResourceHeap::box_to_resource(stream); let mut chunk = stream.take(bytes_to_read); @@ -282,8 +296,7 @@ pub fn tcp_read_up_to(stream: RocBox<()>, bytes_to_read: u64) -> RocResult, bytes_to_read: u64) -> RocResult, RocStr> { - let stream: &mut BufReader = - ThreadSafeRefcountedResourceHeap::box_to_resource(stream); + let stream: &mut TlsStream = ThreadSafeRefcountedResourceHeap::box_to_resource(stream); let mut buffer = Vec::with_capacity(bytes_to_read as usize); let mut chunk = stream.take(bytes_to_read); @@ -302,8 +315,7 @@ pub fn tcp_read_exactly(stream: RocBox<()>, bytes_to_read: u64) -> RocResult, byte: u8) -> RocResult, RocStr> { - let stream: &mut BufReader = - ThreadSafeRefcountedResourceHeap::box_to_resource(stream); + let stream: &mut TlsStream = ThreadSafeRefcountedResourceHeap::box_to_resource(stream); let mut buffer = RocList::empty(); match roc_file::read_until(stream, byte, &mut buffer) { @@ -313,8 +325,7 @@ pub fn tcp_read_until(stream: RocBox<()>, byte: u8) -> RocResult, Ro } pub fn tcp_write(stream: RocBox<()>, msg: &RocList) -> RocResult<(), RocStr> { - let stream: &mut BufReader = - ThreadSafeRefcountedResourceHeap::box_to_resource(stream); + let stream: &mut TlsStream = ThreadSafeRefcountedResourceHeap::box_to_resource(stream); match stream.get_mut().write_all(msg.as_slice()) { Ok(()) => RocResult::ok(()), diff --git a/examples/bfg.roc b/examples/bfg.roc new file mode 100644 index 00000000..bafabd65 --- /dev/null +++ b/examples/bfg.roc @@ -0,0 +1,80 @@ +app [main!] { + pf: platform "../platform/main.roc", + json: "https://github.com/lukewilliamboswell/roc-json/releases/download/0.12.0/1trwx8sltQ-e9Y2rOB4LWUWLS_sFVyETK8Twl0i9qpw.tar.gz", +} + +import pf.Stdout +import pf.Http +import pf.Env +import json.Json +import pf.Tcp + +url = "https://identitysso.betfair.se/api/login" + +main! = |_args| + app_key = Env.var!("BFG_APP_KEY")? + username = Env.var!("BFG_USERNAME")? + password = Env.var!("BFG_PASSWORD")? + dbg (app_key, username, password) + response = Http.send!( + { + method: POST, + headers: [ + { name: "Accept", value: "application/json" }, + { name: "X-Application", value: app_key }, + { name: "Content-Type", value: "application/x-www-form-urlencoded" }, + ], + uri: url, + body: Str.to_utf8("username=${username}&password=${password}"), + timeout_ms: TimeoutMilliseconds(5000), + }, + )? + + Login : { + token : Str, + product : Str, + status : Str, + error : Str, + } + + body : Result Login _ + body = + response.body + |> Decode.from_bytes(Json.utf8) + + stream_url = "stream-api-integration.betfair.com" + port = 443 + AuthMessage : { + op : Str, + appKey : Str, + session : Str, + } + + authMessage : AuthMessage + authMessage = { + op: "authentication", + appKey: app_key, + session: body?.token, + } + + stream = Tcp.connect!(stream_url, port)? + + msg = + authMessage + |> Encode.to_bytes(Json.utf8) + |> List.concat_utf8("\r\n") + Tcp.write!(stream, msg)? + + ConnResp : { op : Str, connectionId : Str } + + resp : ConnResp + resp = + stream + |> Tcp.read_line!()? + |> Str.to_utf8 + |> Decode.from_bytes(Json.utf8)? + + dbg resp + + Stdout.line!("DONE") + diff --git a/flake.nix b/flake.nix index f9dd5e4e..5ab630d3 100644 --- a/flake.nix +++ b/flake.nix @@ -16,9 +16,23 @@ flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, roc, rust-overlay, flake-utils }: - let supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ]; - in flake-utils.lib.eachSystem supportedSystems (system: + outputs = + { + self, + nixpkgs, + roc, + rust-overlay, + flake-utils, + }: + let + supportedSystems = [ + "x86_64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + in + flake-utils.lib.eachSystem supportedSystems ( + system: let overlays = [ (import rust-overlay) ]; pkgs = import nixpkgs { inherit system overlays; }; @@ -28,44 +42,50 @@ # get current working directory cwd = builtins.toString ./.; - rust = - pkgs.rust-bin.fromRustupToolchainFile "${toString ./rust-toolchain.toml}"; + rust = pkgs.rust-bin.fromRustupToolchainFile "${toString ./rust-toolchain.toml}"; - linuxInputs = with pkgs; + linuxInputs = + with pkgs; lib.optionals stdenv.isLinux [ valgrind ]; - darwinInputs = with pkgs; - lib.optionals stdenv.isDarwin - (with pkgs.darwin.apple_sdk.frameworks; [ - Security - ]); + darwinInputs = + with pkgs; + lib.optionals stdenv.isDarwin ( + with pkgs.darwin.apple_sdk.frameworks; + [ + Security + ] + ); - sharedInputs = (with pkgs; [ - jq - rust - llvmPkgs.clang - llvmPkgs.lldb # for debugging - expect - nmap - simple-http-server - rocPkgs.cli - ]); - in { + sharedInputs = ( + with pkgs; + [ + jq + rust + llvmPkgs.clang + llvmPkgs.lldb # for debugging + expect + nmap + simple-http-server + rocPkgs.full + ] + ); + in + { devShell = pkgs.mkShell { buildInputs = sharedInputs ++ darwinInputs ++ linuxInputs; # nix does not store libs in /usr/lib or /lib # for libgcc_s.so.1 - NIX_LIBGCC_S_PATH = - if pkgs.stdenv.isLinux then "${pkgs.stdenv.cc.cc.lib}/lib" else ""; + 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 ""; + NIX_GLIBC_PATH = if pkgs.stdenv.isLinux then "${pkgs.glibc.out}/lib" else ""; }; formatter = pkgs.nixpkgs-fmt; - }); + } + ); }