> 本方法目前仅在 Ubuntu 2004LTS, 2204LTS 上进行过测试,macOS上运行部分依赖包(mase)被破坏目前尚未解决,同时roscore安装时间过长。如果不存在任何平台包损坏的情况下,理论上最高可以支持 Linux (i686, x86_64, aarch64). macOS (x86_64, aarch64)。 > 鉴于本安装方法依赖的镜像源大多位于国外,受网络因素影响严重,虽然主要耗时部分不需要观测,但是如果可能的话,还是相对来说更加建议选择别的安装方式。 ## 安装 Nix > 考虑到方便卸载的需求,没有采用官方文档中给出的[安装脚本](https://mirrors.help/nix/),而是采用了[nix-installer](https://github.com/DeterminateSystems/nix-installer)作为安装脚本. > *安装时间可能相对比较久,卡住属于正常现象。* ```bash= $ curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install ``` 按照提示逐步输入密码,安装 Nix 包管理工具 ## 运行 roscore > 采用现有的 [ros-nix-overlay](https://github.com/jackyliu16/nix-ros-overlay) 实现 roscore 包的运行,目前在 flakes 里面已经配置好了 substituters,但是可能在运行的时候还是得采用携带 substituters 参数会更好。 1. 下载对应仓库(本仓库在原始仓库上进行了简单的修正以及提交了新的环境,可以按照具体要求进行删减) ```bash= $ git clone https://github.com/jackyliu16/nix-ros-overlay.git ``` 2. 确认当前环境中存在 Nix 环境 ```nix $ nix nix-shell-env error: no subcommand specified Try 'nix --help' for more information. ``` 3. 运行环境生成指令 ```bash= $ cd nix-ros-overlay $ while ! nix develop .#ros1-core \ --option substituters https://mirror.iscas.ac.cn/nix-channels/store \ --extra-experimental-features nix-commands \ --extra-experimental-features flake\ ; do sleep 1 done ``` **建议在睡前在电脑上运行,目前我最快完成的速度大概在2h左右,但是具体取决于你的网络** > 这条指令中使用 `option subsitutuers` 指令默认使用了一个中国地区相对较快的镜像源,其他源可以在 [mirrors.help](https://mirrors.help/nix-channels/) 上进行查询。 > 这条指令中通过 `--extra-experimental-features` 许可了实验性功能 flakes 和 nix-commands 的使用,在实际操作中避免了手动将指令写入文件的操作,如果需要多次使用可以考虑使用 `Makefile` 或者将 `extra-experimental-features=nix-commands flake` 添加到 `/etc/nix/nix.conf` 文件中。*macOS操作未知* > 这条指令中通过 `nix develop .#ros1-comm` 调用了于 `example/ros1-comm.nix` 中被定义的软件包,其他可用软件包可以在 `distro/${ROS version}/` 中搜索并添加 > 这条指令考虑到在操作的时候受网络波动影响较为严重,采用了 `while` 循环以提升效率,自动化重新运行 > 如果还想更快的话,可以尝试通过 `cachix` 注册 `ros` 二进制镜像源 ## 运行环境删减说明 根据目前的测试结果来看,支持的最小运行 `ROS1 Master` 节点的最小运行环境如下: > 如果只准备使用这一组件,可以简单的通过这种方式进行构建,实测中会降低构建时间 ```nix= { pkgs ? import ../. {} }: with pkgs; with rosPackages.noetic; with pythonPackages; mkShell { buildInputs = [ glibcLocales (buildEnv { paths = [ ros-core ]; }) ]; ROS_HOSTNAME = "localhost"; ROS_MASTER_URI = "http://localhost:11311"; } ``` ## 进一步降低繁琐程度说明 1. 如果不想在第一次安装成功之后,每次进入环境都手动运行 `nix develop .#ros1-core` 或者 `nix develop .#ros1-comm` 可以按照[direnv::install](https://direnv.net/docs/installation.html),[direnv::hook](https://direnv.net/docs/hook.html),[nix-direnv::home](https://github.com/nix-community/nix-direnv)的规定完成设置,在你想要配置进入环境的文件夹下创建`.envrc`文件,文件内容为`use flake <nix-ros-overlay的相对位置>#ros1-comm` 退出文件之后运行 `direnv allow`。 理论上,在你退出这个文件夹再进入当前文件夹之后,就会自动加载一系列的内容 ```bash jacky@Dell:~$ cd ArceOS/ direnv: loading ~/ArceOS/.envrc direnv: using flake .#full warning: Git tree '/home/jacky/ArceOS' is dirty evaluating derivation 'git+file:///home/jacky/ArceOS#full'direnv: ([/nix/store/r73zr43xs0vfgfhii2gi0vwxmqagwzi5-direnv-2.32.3/bin/direnv export bash]) is taking a while to execute. Use CTRL-C to give up. direnv: export +AR +AR_FOR_TARGET +AS +AS_FOR_TARGET +CC +CC_FOR_TARGET +CONFIG_SHELL +CXX +CXX_FOR_TARGET +HOST_PATH +IN_NIX_SHELL +LD +LD_FOR_TARGET +LD_LIBRARY_PATH +LIBCLANG_PATH +NIX_BINTOOLS +NIX_BINTOOLS_FOR_TARGET +NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_BINTOOLS_WRAPPER_TARGET_TARGET_x86_64_unknown_linux_gnu +NIX_BUILD_CORES +NIX_BUILD_TOP +NIX_CC ...etc ``` 2. 如果想要持续性配置 substituters *(相对来说比较建议,但是考虑到降低复杂程度,没有放在正文)* 请参照[mirrors.help::nix-channels](https://mirrors.help/nix-channels/) 设置