!ayCRiZriCVtuCUpeLp:nixos.org

Nix Cross Compiling

581 Members
126 Servers

Load older messages


SenderMessageTime
26 Mar 2025
@rosssmyth:matrix.orgrosssmyth

Is there an example somewhere of where multilib + crosspkgs is broken? From #380325

What would it take to fix it?

18:57:13
@stephen:crabsin.spacen3tcat joined the room.18:57:22
@stephen:crabsin.spacen3tcat 19:00:25
@stephen:crabsin.spacen3tcat 19:01:16
@stephen:crabsin.spacen3tcat

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:0upti.meK900Easiest is probably to just cherry-pick that patch into your own nixpkgs fork19:06:20
@k900:0upti.meK900And then it should work19:06:25
@k900:0upti.meK900I think19:06:26
@stephen:crabsin.spacen3tcatI 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 repo19:06:49
@k900:0upti.meK900Oh19:07:00
@stephen:crabsin.spacen3tcatLike so that I have access to an m68k cross compiler for my C code19:07:02
@k900:0upti.meK900We don't have an m68k-unknown-elf platform do we19:07:08
@k900:0upti.meK900 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
@stephen:crabsin.spacen3tcatahh I see19:08:38
@stephen:crabsin.spacen3tcatthank you this is super helpful19:08:43
@stephen:crabsin.spacen3tcat 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:0upti.meK900Uhh19:19:46
@k900:0upti.meK900Can you post the whole thing19:19:48
@k900:0upti.meK900It should be prefixed19:19:56
@stephen:crabsin.spacen3tcat
{
  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:0upti.meK900 It's crossSystem 19:22:02
@k900:0upti.meK900And yes it takes arbitrary args don't ask19:22:09
@stephen:crabsin.spacen3tcatwell it's hanging and my cpu is at 100% so it's probably building19:26:57
@stephen:crabsin.spacen3tcatyippee this is cool19:27:05
@stephen:crabsin.spacen3tcat

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
@stephen:crabsin.spacen3tcatThe assembler does work though FYI (:19:58:05
@k900:0upti.meK900
In reply to @stephen:crabsin.space
The assembler does work though FYI (:
Oof it's probably cc-wrapper
20:06:25
@k900:0upti.meK900 Try -fno-stack-protector 20:07:39
@k900:0upti.meK900Or maybe disabling some or most of these 20:08:12
@k900:0upti.meK900 https://github.com/NixOS/nixpkgs/blob/4f61fd53997f76c8d33b01e24dc56c9e9796d811/pkgs/build-support/cc-wrapper/add-hardening.sh#L54 20:08:13

Show newer messages


Back to Room ListRoom Version: 6