-
-
Save techieAgnostic/02c1db811d1b02073c27371ce5f8c331 to your computer and use it in GitHub Desktop.
Julia in Nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
description = "a nix flake for compiling julia programs"; | |
inputs = { | |
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | |
flake-utils.url = "github:numtide/flake-utils"; | |
}; | |
outputs = { self, nixpkgs, flake-utils, ... }: | |
flake-utils.lib.eachDefaultSystem (system: | |
let pkgs = nixpkgs.legacyPackages.${system}; | |
in rec { | |
packages = { | |
juliaSkele = (import ./juliaDeri.nix) { pkgs = pkgs; pname = "myjulia"; }; | |
}; | |
defaultPackage = packages.juliaSkele; | |
} | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs, | |
pname, | |
exampleFile ? "src/Example.jl", | |
mainFile ? "src/Main.jl", | |
... }: | |
pkgs.stdenv.mkDerivation rec { | |
name = pname; | |
src = ./.; | |
buildInputs = with pkgs; [ julia curl ]; | |
phases = [ "configurePhase" "buildPhase" "installPhase" ]; | |
configurePhase = '' | |
julia --project --trace-compile=precompile.jl -q ${src}/${exampleFile}; | |
''; | |
buildPhase = '' | |
unset packageList; | |
unset finalList; | |
unset prepedColon; | |
packageList=$(julia --project -E 'using Pkg; Pkg.status(mode=PKGMODE_MANIFEST)' | sed 1,2d | head -n -1 | sed 's/.*\]\ //g' | sed 's/\ .*//g') | |
prependColon=$(for p in $packageList; do echo ":"''${p}", "; done) | |
finalList="["''${prependColon::-2}"]" | |
julia --project -q -E \ | |
using Pkg \ | |
Pkg.add("https://github.com/JuliaLang/PackageCompiler.jl" rev="v1.2.3") \ | |
Pkg.instantiate \ | |
Pkg.activate \ | |
using PackageCompiler \ | |
create_sysimage(''${finalList}, sysimage_path="generatedSysImage.so", precompile_execution_file="$out/precompile.jl") | |
''; | |
installPhase = '' | |
rm $out/precompile.jl | |
mkdir -p $out/bin | |
cp -r * $out | |
echo "JULIA_LOAD_PATH=$out julia --project --sysimage ../generatedSysImage.so $out/${mainFile}" >> $out/bin/${pname} | |
chmod +x $out/bin/${pname} | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment