Skip to content

Commit

Permalink
Merge pull request #7391 from nxy7/main
Browse files Browse the repository at this point in the history
add: buildRocPackage lib output to nix flake
  • Loading branch information
lukewilliamboswell authored Jan 9, 2025
2 parents dab3f9b + bb79964 commit 158691f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 15 deletions.
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ];

templates = import ./nix/templates { };
in
{ inherit templates; } //
lib = { buildRocPackage = import ./nix/buildRocPackage.nix; };
in {
inherit templates lib;
} //
flake-utils.lib.eachSystem supportedSystems (system:
let

Expand All @@ -47,7 +49,7 @@

# DevInputs are not necessary to build roc as a user
linuxDevInputs = with pkgs;
lib.optionals stdenv.isLinux [
pkgs.lib.optionals stdenv.isLinux [
valgrind # used in cli tests, see cli/tests/cli_tests.rs
vulkan-headers # here and below is all graphics stuff for examples/gui
vulkan-loader
Expand All @@ -59,12 +61,12 @@
xorg.libXi
xorg.libxcb
cargo-llvm-cov # to visualize code coverage

];

# DevInputs are not necessary to build roc as a user
darwinDevInputs = with pkgs;
lib.optionals stdenv.isDarwin
pkgs.lib.optionals stdenv.isDarwin
(with pkgs.darwin.apple_sdk.frameworks; [
CoreVideo # for examples/gui
Metal # for examples/gui
Expand Down Expand Up @@ -135,10 +137,10 @@
NIX_GLIBC_PATH =
if pkgs.stdenv.isLinux then "${pkgs.glibc.out}/lib" else "";

LD_LIBRARY_PATH = with pkgs;
lib.makeLibraryPath
([ pkg-config stdenv.cc.cc.lib libffi ncurses zlib ]
++ linuxDevInputs);
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath
([ pkgs.pkg-config pkgs.stdenv.cc.cc.lib pkgs.libffi pkgs.ncurses pkgs.zlib ]
++ linuxDevInputs);

NIXPKGS_ALLOW_UNFREE =
1; # to run the GUI examples with NVIDIA's closed source drivers

Expand Down
41 changes: 41 additions & 0 deletions nix/buildRocPackage.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{ pkgs, roc-cli, name, entryPoint, src, outputHash, linker ? "", ... }:
let
packageDependencies = pkgs.stdenv.mkDerivation {
inherit src;
name = "roc-dependencies";
nativeBuildInputs = with pkgs; [ gnutar brotli ripgrep wget cacert ];

buildPhase = ''
list=$(rg -o 'https://github.com[^"]*' ${entryPoint})
for url in $list; do
path=$(echo $url | awk -F'github.com/|/[^/]*$' '{print $2}')
packagePath=$out/roc/packages/github.com/$path
mkdir -p $packagePath
wget -P $packagePath $url
cd $packagePath
brotli -d *.tar.br
tar -xf *.tar --one-top-level
rm *.tar.br
rm *.tar
done
'';

outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = outputHash;
};
in pkgs.stdenv.mkDerivation {
inherit name src;
nativeBuildInputs = [ roc-cli ];
XDG_CACHE_HOME = packageDependencies;

buildPhase = ''
roc build ${entryPoint} --output ${name} --optimize ${
if linker != "" then "--linker=${linker}" else ""
}
mkdir -p $out/bin
mv ${name} $out/bin/${name}
'';
}

0 comments on commit 158691f

Please sign in to comment.