| 26 Mar 2025 |
rosssmyth | Is there an example somewhere of where multilib + crosspkgs is broken? From #380325
What would it take to fix it?
| 18:57:13 |
| n3tcat joined the room. | 18:57:22 |
| n3tcat | 19:00:25 |
| n3tcat | 19:01:16 |
n3tcat | Hello! I'm new to cross-compiling on NixOS. I want to compile C code for my custom M68k computer.
This is what my flake.nix file currently looks like:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils?ref=main";
};
outputs =
inputs:
inputs.flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = inputs.nixpkgs.legacyPackages.${system};
in
{
devShells.default = pkgs.mkShell {
packages = (
with pkgs; [
minipro
gnumake
pkgsCross.m68k.buildPackages.gcc
xxd
]
);
};
}
);
}
I think I want to remove the pkgsCross.m68k line and add in crossSystem pointing at this patch from K900: https://github.com/K900/nixpkgs/commit/e8d4e76093cd396805e76c908734a351cc6d1f39
But I'm not really clear on what I'm actually doing (plus I want my other packages to not be cross-compiled as I want to run them on my x86 box) | 19:04:42 |
K900 | Easiest is probably to just cherry-pick that patch into your own nixpkgs fork | 19:06:20 |
K900 | And then it should work | 19:06:25 |
K900 | I think | 19:06:26 |
n3tcat | I guess I don't really know what needs to go in the flake.nix file to start, even if I point it at my custom nixpkgs repo | 19:06:49 |
K900 | Oh | 19:07:00 |
n3tcat | Like so that I have access to an m68k cross compiler for my C code | 19:07:02 |
K900 | We don't have an m68k-unknown-elf platform do we | 19:07:08 |
K900 | Then something like
let pkgsCrossM68k = import inputs.nixpkgs { system = "x86_64-linux"; cross-system = "m68k-unknown-none-elf"; }; in pkgs.mkShell { ... packages = [ pkgsCrossM68k.stdenv.cc ]; }
| 19:08:12 |
n3tcat | ahh I see | 19:08:38 |
n3tcat | thank you this is super helpful | 19:08:43 |
n3tcat | Should that override cc? cc -march=68000 mandelbrot.c says the arch isn't supported. I'm not seeing anything under m68k-* either | 19:13:57 |
K900 | Uhh | 19:19:46 |
K900 | Can you post the whole thing | 19:19:48 |
K900 | It should be prefixed | 19:19:56 |
n3tcat | {
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils?ref=main";
};
outputs =
inputs:
inputs.flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = inputs.nixpkgs.legacyPackages.${system};
pkgsCrossM68k = import "/home/stephen/src/k900/nixpkgs" {
system = "x86_64-linux"; cross-system = "m68k-unknown-none-elf";
};
in
{
devShells.default = pkgs.mkShell {
packages = (
with pkgs; [
minipro
gnumake
xxd
pkgsCrossM68k.stdenv.cc
]
);
};
}
);
}
I'm doing nix develop --impure for now. I'll fix the path once things are good | 19:20:59 |
K900 | It's crossSystem | 19:22:02 |
K900 | And yes it takes arbitrary args don't ask | 19:22:09 |
n3tcat | well it's hanging and my cpu is at 100% so it's probably building | 19:26:57 |
n3tcat | yippee this is cool | 19:27:05 |
n3tcat | Okay so it seems to be installed! Ty again!
I am unable to use it though. This may not be related to NixOS but I am pretty sure I used this build command on Arch (w/ a custom cross compiler) without issue
m68k-unknown-none-elf-gcc -T Linker.ld -o os.bin -O2 -m68000 -Wall -Wextra -nostdlib start.o main.o -fno-PIE drivers/screen.o drivers/serial.o cpu/interrupt.o cpu/interrupts.o libc/stdlib.o libc/string.o prog/mandelbrot.o prog/memtest.o prog/tty.o -ffreestanding `m68k-unknown-none-elf-gcc -m68000 -print-libgcc-file-name -ffreestanding`
/nix/store/fmdkz68rg2al0ds776246wkzc12kva5q-m68k-unknown-none-elf-binutils-2.40/bin/m68k-unknown-none-elf-ld: main.o: in function `kmain':
main.c:(.text+0x6): undefined reference to `_GLOBAL_OFFSET_TABLE_'
/nix/store/fmdkz68rg2al0ds776246wkzc12kva5q-m68k-unknown-none-elf-binutils-2.40/bin/m68k-unknown-none-elf-ld: cpu/interrupt.o: in function `error_handler':
interrupt.c:(.text+0x2e): undefined reference to `__stack_chk_guard'
| 19:57:54 |
n3tcat | The assembler does work though FYI (: | 19:58:05 |
K900 | In reply to @stephen:crabsin.space The assembler does work though FYI (: Oof it's probably cc-wrapper | 20:06:25 |
K900 | Try -fno-stack-protector | 20:07:39 |
K900 | Or maybe disabling some or most of these | 20:08:12 |
K900 | https://github.com/NixOS/nixpkgs/blob/4f61fd53997f76c8d33b01e24dc56c9e9796d811/pkgs/build-support/cc-wrapper/add-hardening.sh#L54 | 20:08:13 |