Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

envs: add buildroot shell.nix #75

Merged
merged 3 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ What environments should **not** include:
| [Xilinx vitis](envs/xilinx-vitis) | `xilinx-vitis` |
| [InfiniSim](envs/infinisim) | `infinisim` |
| [InfiniTime](envs/infinitime) | `infinitime` |
| [buildroot](envs/buildroot) | `buildroot` |

## How to use

Expand Down
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
, pkgsUnfree ? import <nixpkgs> { config = { allowUnfree = true; }; }
}: {
arduino = import ./envs/arduino/shell.nix { inherit pkgs; };
buildroot = import ./envs/buildroot/shell.nix { inherit pkgs; };
cc2538-bsl = import ./envs/cc2538-bsl/shell.nix { inherit pkgs; };
firefox = import ./envs/firefox/shell.nix { inherit pkgs; };
infinitime = import ./envs/infinitime/shell.nix { pkgs = pkgsUnfree; };
Expand Down
15 changes: 15 additions & 0 deletions envs/buildroot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# buildroot

Buildroot, making embedded Linux easy.

For more info checkout [buildroot over on GitLab](https://gitlab.com/buildroot.org/buildroot) or on their [website](https://buildroot.org).

## Remarks

- works on unstable, but not on 23.11. 24.05 has not been tested.
- For reasons explained in comments this adds two scripts to the shell needed for gcc backwards compatibility
- This adds ccache, which is an optional dependency but one that speeds up consecutive builds tremendously
- Some dependencies are not mentioned in the docs (yet) - they were found by trial and error
- At the time of writing buildroot under nixos suffers from incompatibility between their systemd version and nixos's kernel headers
A patch from the mailing list has to be applied: https://lore.kernel.org/all/[email protected]/T/
- buildFHSUserEnv is required as buildroot tooling has some hardcoded paths expecting a "usual" linux FS
83 changes: 83 additions & 0 deletions envs/buildroot/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
# Unstable is required as stable does not contain required glib
pkgs ? import (fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/refs/heads/nixpkgs-unstable.tar.gz"; # TODO: Remove unstable override, when we have 24.11
}) { }
, extraPkgs ? []
}:
let
# POSIX compliant gcc wrappers for backwards compatiblity
# https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/commit/cacf18c7cd79fb00645a4bf367392b05ad2dc290
# Small change: last line was '${1+"$@"}' which throws causes nix
# to throw an error: add not allowed for integer and string
c98 = pkgs.writeShellScriptBin "c98" ''
set -eu -o pipefail
fl="-std=c89"
for opt; do
case "$opt" in
-ansi|-std=c89|-std=iso9899:1990) fl="";;
-std=*) echo "`basename $0` called with non ANSI/ISO C option $opt" >&2
exit 1;;
esac
done
exec gcc $fl "$@"
'';
c99 = pkgs.writeShellScriptBin "c99" ''
set -eu -o pipefail
fl="-std=c99"
for opt; do
case "$opt" in
-std=c99|-std=iso9899:1999) fl="";;
-std=*) echo "`basename $0` called with non ISO C99 option $opt" >&2
exit 1;;
esac
done
exec gcc $fl "$@"
'';
in
# Unfortunately the more versatile and nix-nativ mkShell does not work
# for buildroot as some of the paths are hardcoded and expect a usual
# linux posix-compliant file system structure
(pkgs.buildFHSUserEnv {
name = "buildroot";
targetPkgs = pkgs: (with pkgs; [
(lib.hiPrio gcc)
bashInteractive
bc
binutils
bzip2
c98
c99
ccache # optional, speeds up consecutive builds
cmake
cpio
diffutils
expat # not mentioned in buildroot deps; dep of host-libxml-parser-perl
expect # not mentioned in buildroot deps
file
findutils
gcc
glib # not mentioned; not sure if necessary
glibc # transitively mentioned: debian build-essential
gnumake
gnused
gnutar
gzip
libxcrypt # not mentioned in buildroot deps; required for host-mkpasswd
ncurses # optional
patch
perl
pkg-config # not mentioned, unsure if necessary
rsync
unzip
wget
which
] ++ pkgs.linux.nativeBuildInputs ++ extraPkgs);
runScript = ''
# The host-uboot-tools package uses objcopy from the shells OBJCOPY var
# Since the var is set to OBJCOPY=objcopy the buildroot provided
# CROSS_COMPILE path is ignored hence the script is using the wrong objcopy
unset $OBJCOPY
exec bash
'';
}).env