Stream: contributing

Topic: Request for Assistance - nixOS roc-ray


view this post on Zulip Luke Boswell (Jan 20 2025 at 08:48):

Is anyone able to help me fix roc-ray so it can be used with nixOS?

https://github.com/lukewilliamboswell/roc-ray

This isn't urgent or anything, but I'm a complete nix noob, and usually just stumble through things with the help of a (just as confused) LLM.

I know of at least one person who has been trying to use the platform for making games and are having issues using nixOS. I figured just providing a flake that works on linux would be enough... but turns out nix may not like the way I've set things up.

Basically roc-ray currently uses the rust toolchain to drive the final linking which sidesteps some issues and is simpler. The dream is to one day cut a release so the surgical linkers can do their thing, enabling people to make graphics apps using roc build.

I have a "sys" crate that wraps the raylib binaries (static libraries). This is a nice experience for most people as everything is included, but for someone using nix I think it expects to find dependencies in a special nix path. So I'm guessing raylib will be easier to use if it's dynamically linked.

I've also setup the build.rs so it can link with raylib as a dynamic library. But I'm not sure it's working etc, without a nixOS installation myself to test things on.

Anyway... if you have nixOS and a passion for nix, rust , roc, or games dev and would like to help please let me know.

view this post on Zulip Anton (Jan 20 2025 at 10:21):

I've got some other issues to deal with first, but I can look at this after :)

view this post on Zulip Anton (Feb 26 2025 at 16:28):

I finally got to this @Luke Boswell, this flake.nix makes just dev examples/pong.roc work :)

{
  description = "Roc Ray platform flake";

  inputs = {
    roc.url = "github:roc-lang/roc";

    nixpkgs.follows = "roc/nixpkgs";

    # rust from nixpkgs has some libc problems, this is patched in the rust-overlay
    rust-overlay = {
        url = "github:oxalica/rust-overlay";
        inputs.nixpkgs.follows = "nixpkgs";
    };

    # to easily make configs for multiple architectures
    flake-utils.url = "github:numtide/flake-utils";

    # to make graphics work with nix
    nixgl = {
      url = "github:guibou/nixGL";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.flake-utils.follows = "flake-utils";
    };

  };

  outputs = { self, roc, nixpkgs, rust-overlay, flake-utils, nixgl  }:
    let supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
    in flake-utils.lib.eachSystem supportedSystems (system:
        let
            overlays = [ (import rust-overlay) ]
              ++ (if system == "x86_64-linux" then [ nixgl.overlay ] else [ ]);

            pkgs = import nixpkgs { inherit system overlays; };

            rocPkgs = roc.packages.${system};
            # llvmPkgs = pkgs.llvmPackages_16;

            rust = pkgs.rust-bin.fromRustupToolchainFile "${toString ./rust-toolchain.toml}";

            linuxDeps = with pkgs;
                lib.optionals stdenv.isLinux [
                    libglvnd
                    xorg.libX11
                    xorg.libXcursor
                    xorg.libXrandr
                    xorg.libXi
                    xorg.libxcb
                    xorg.libXinerama
                ];

            macosDeps = if pkgs.stdenv.isDarwin then [
                pkgs.libiconv
                pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
                pkgs.darwin.apple_sdk.frameworks.CoreGraphics
                pkgs.darwin.apple_sdk.frameworks.AppKit
            ] else [];

        in {

            devShell = if pkgs.stdenv.isDarwin then
                throw ''
                    HELP WANTED FOR ROC RAY NIX CONFIGURATION

                    Darwin/macOS is not currently supported due to framework linking issues.
                    If you'd like to help fix this, please check:
                    https://github.com/your-repo/roc-ray/issues

                    The main issue is with linking Objective-C runtime and macOS frameworks
                    correctly within the Nix environment. I can't find the right incantation
                    to make it work. If you have experience with this, please help! :smile:
                ''
                else pkgs.mkShell {

                packages = [
                        rocPkgs.cli
                        rust
                        pkgs.zig # For Web support, used to build roc wasm static library
                        pkgs.emscripten
                        pkgs.simple-http-server
                        pkgs.just # For dev command
                    ] ++ linuxDeps ++ macosDeps;

                shellHook = ''
                    if [ "$(uname)" = "Darwin" ]; then
                        export SDKROOT=$(xcrun --show-sdk-path)
                        export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath macosDeps}:$LD_LIBRARY_PATH
                    fi

                    if [ "$(uname)" = "Linux" ]; then
                        export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath linuxDeps}:$LD_LIBRARY_PATH
                    fi
                '';
            };

            formatter = pkgs.nixpkgs-fmt;

        });
}

view this post on Zulip Anton (Feb 26 2025 at 16:36):

I also tried with claude 3.7 but it could not handle it, nix experts are still safe :p

view this post on Zulip Luke Boswell (Feb 26 2025 at 19:36):

That's awesome


Last updated: Jul 06 2025 at 12:14 UTC