使用 Nix 的自定义交叉编译器
Custom Cross Compiler with Nix

原始链接: https://www.hobson.space/posts/nixcross/

## Nix 与 Risc OS 交叉编译:通往简易的漫长道路 本文详细介绍了为 Risc OS 设置 Nix 环境以进行交叉编译的挑战性过程,Risc OS 是一种古老的操作系统,现在可以在 Raspberry Pi 上运行。 尽管已经有了交叉编译器,但将其与 Nix 集成却出乎意料地复杂且缺乏文档。 核心问题在于需要一个非常特定的旧 GCC 版本(4.7.4),最初是为 x86_64 Ubuntu 构建的,而作者使用的是 ARM Mac。 Nix 提供了一个解决方案,但仅仅构建工具链是不够的。 Nix 的 `wrapCCWith` 函数旨在简化交叉编译,但需要仔细处理 Nix 的 `buildPlatform`、`targetPlatform` 和 `hostPlatform` 变量。 作者最终创建了一个自定义构建系统,模仿 Nix 的内部交叉编译逻辑,覆盖了标准的 stdenv 以正确识别编译器前缀。 这涉及定义一个 `crossSystem` 并策略性地覆盖配置,以欺骗 Nix 识别 Risc OS 目标。 结果? 一个功能性的 Nix flake,能够构建 Risc OS 可执行文件,展示了 Nix 在即使是最不寻常的开发环境中的强大功能。 作者希望这份详细的记录能为其他人节省大量时间和精力。

黑客新闻 新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 使用 Nix 的自定义交叉编译器 (hobson.space) 41 分,by todsacerdoti 1 天前 | 隐藏 | 过去 | 收藏 | 2 条评论 OneDeuxTriSeiGo 1 天前 | 下一个 [–] 很高兴看到这样的帖子。我喜欢 NixOS 和 Nix,但交叉编译要“直接可用”变得越来越不简单,尤其是在 flake 之后,而且我感觉每次需要做的时候都需要重新学习整个过程。 像这样清晰的指南可以作为方便的参考,这非常有帮助。回复 ilioscio 1 天前 | 上一个 [–] 这真是太棒的信息了,感谢您花时间记录和解释您的流程,我们需要更多这样的 Nix 内容。回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

This post is about trying to do something seemingly simple. You have an unusual system that you want to write code for. You even have a cross compiler! But how can you get this working with nix? Although the answer turned out to be simple, the journey to getting there was super long and undocumented. I hope this post saves you a lot of time!

I have a deep love for an operating system called Risc Os. It is a really old operating system made by Acorn Computers Ltd. for their Archimedes range of computers and you can still run it on Raspberry Pi! I love it for a few reasons:

  1. It’s so simple
  2. It was one of the first things I nerded out over after seeing at the national computing museum in Bletchley Park
  3. Programming it in C helped is where pretty much all of my C knowledge comes from

But programming it is not easy. It predates every programming convention we have. There are no good text editors on it, and compiling is a pain!

But there is a cross compiler! The only issue is that when you try to build it, it becomes obvious that you need a seriously old version of ubuntu on X86_64 linux (it’s a patched GCC 4.7.4) and these days, I sport an Arm Mac which won’t even build a compiler that old!

Can we nix it?