3 ms·
> But I believe libc is fundamentally a “hole” in the sandboxing of Nix, at least on OS X. Nix doesn't sandbox builds on macOS at all by default, and turning s
by pxc 4y ago
> But I believe libc is fundamentally a “hole” in the sandboxing of Nix, at least on OS X.
Nix doesn't sandbox builds on macOS at all by default, and turning sandboxing on breaks some builds: https://github.com/NixOS/nix/pull/1821 https://github.com/NixOS/nix/pull/1821
But the libc issue goes deeper. This blog post has some explanation: https://matthewbauer.us/blog/darwin-stdenv-update.html https://matthewbauer.us/blog/darwin-stdenv-update.html
> Linux is unique among operating systems due to the fact that the Kernel and Libc are developed independently. Linux is maintained by creator Linus Torvalds and a community of contributors. Glibc, the most popular Libc for Linux, is maintained by the GNU project. As a result, Linux has a strong separation between Syscalls and Libc.
> [ ... ]
> To accomplish this, Linux provides a stable list of syscalls that it has maintained across many versions. This is specified for i386 at arch/x86/entry/syscalls/syscall_32.tbl in the kernel tree. The syscalls specified here are the interface through which the Libc communicates with the kernel. As a result, applications built in 1992 can run on a modern kernel, provided it comes with copies of all its libraries.
> The macOS Libc is called libSystem. It is available on all macOS systems at /usr/lib/libSystem.B.dylib. This library is the main interface that binary compatibility is maintained in macOS. Unlike Linux, macOS maintains a stable interface in libSystem that all executables are expected to link to. This interface is guaranteed by Apple to be stable between versions.
> In Nixpkgs, we maintain this compatibility through a list of symbols that are exported by libSystem. This is a simple text list and is available for viewing at NixOS/nixpkgs/pkgs/os-specific/darwin/apple-source-releases/Libsystem/system_c_symbols. The symbol list is created by listing symbols (nm) on the minimum macOS version that we support (for my PR, 10.12). We do some linking tricks to ensure that everything that we build in Nixpkgs only contains those symbols. This means that we can reproducibly build on newer versions of macOS, while maintaining compatibility with older macOS versions. Unfortunately, newer symbols introduced in later versions cannot be used even on systems that have those symbols.
> A side effect of macOS design, is that fully static executables are not supported in macOS as they are on Linux. Without a stable syscall interface, there is nothing to provide compatibility between versions. As a result, Apple does not support this type of linking.
So Nixpkgs does do some things to try to let you peg builds only to what's available in older versions of the macOS libc, but it doesn't try to let you bring your own libc.
There's at least one libc that does claim this kind of portability of course, and is the subject of lots of good posts here on HN. Maybe the author of Cosmopolitan libc ( https://justine.lol/cosmopolitan/index.html https://justine.lol/cosmopolitan/index.html ) might have something insightful to say here.
- chubot 4y agoYes I agree it's an Apple-specific issue, and not relevant for what I care about in Guix / Nix (Although Oil will obviously run on OS X because it uses plain libc from source, as is officially supported) Cosmopolitan libc does seem interesting, because a shell basically only depends on libc. It would be interesting to get Oil to run like that, on platforms where fork() is supported (not bare metal I assume). Would it work on Windows? How do they do fork() emulation? I think that's very hard on Windows Oh yeah it looks like it's slow on Windows (and OpenBSD) https://justine.lol/cosmopolitan/functions.html https://justine.lol/cosmopolitan/functions.html So I don't think it would make sense as a path for portability for a "production" shell
- pxc 4y agoI think performance expectations for shells on Windows are pretty different. The first time I open PowerShell in a given session on my work computer, it takes ~9 seconds on average, without a particularly complex config. That said, I think it can also makes sense to aim higher in terms of performance at the cost of a more bespoke Windows implementation. lol