codedownio / julia2nix

Generate Nix expressions for building a Julia depot with a set of packages
53 stars 6 forks source link

Proof of Concept #15

Closed idontgetoutmuch closed 3 years ago

idontgetoutmuch commented 3 years ago

I have this as my shell.nix and am using lorri / direnv in emacs to get my environment as I want it. I am not sufficiently expert in nix / julia to make it a more robust solution

{ pkgs ? import <nixpkgs> { config.allowBroken = true; } }:

let

  # The base Julia version
  baseJulia = pkgs.julia_15;

  # Extra libraries for Julia's LD_LIBRARY_PATH.
  # Recent Julia packages that use Artifacts.toml to specify their dependencies
  # shouldn't need this.
  # But if a package implicitly depends on some library being present, you can
  # add it here.
  extraLibs = [];

  # Wrapped Julia with libraries and environment variables.
  # Note: setting The PYTHON environment variable is recommended to prevent packages
  # from trying to obtain their own with Conda.
  julia = pkgs.runCommand "julia-wrapped" { buildInputs = [pkgs.makeWrapper]; } ''
    mkdir -p $out/bin
    makeWrapper ${baseJulia}/bin/julia $out/bin/julia \
                --suffix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath extraLibs}" \
                --set PYTHON ${pkgs.python3}/bin/python
  '';

myJulia = pkgs.callPackage ./common.nix {
  inherit julia;

  # Run Pkg.precompile() to precompile all packages?
  precompile = true;

  # Extra arguments to makeWrapper when creating the final Julia wrapper.
  # By default, it will just put the new depot at the end of JULIA_DEPOT_PATH.
  # You can add additional flags here.
  makeWrapperArgs = "";
};

in

pkgs.mkShell {
  buildInputs = [
    myJulia
    pkgs.python3
    pkgs.python3Packages.numpy

  ];

  JULIA_DEPOT_PATH="/Users/dom/.julia";
  MYVARIABLE = "hello";
}
thomasjm commented 3 years ago

Hi @idontgetoutmuch. What is this a proof of concept of exactly? If you're just trying to run pkgs.mkShell with the derivation, I'd recommend doing that in a different file. Something like this (not tested):

{ pkgs ? import <nixpkgs> { config.allowBroken = true; } }:

let

  myJulia = callPackage /path/to/your/julia2nix/generated/folder {};

in

pkgs.mkShell {
  buildInputs = [
    myJulia
    pkgs.python3
    pkgs.python3Packages.numpy
  ];

  JULIA_DEPOT_PATH="/Users/dom/.julia";
}
idontgetoutmuch commented 3 years ago

Thanks :) The PoC was to be able to use lorri / direnv and now I can - btw is there a better way we can communicate? I feel a bit uncomfortable opening tickets just to have a discussion.

thomasjm commented 3 years ago

I'd be happy to set something up for users of this lib to chat. I'm open to suggestions about the best platform... For now I made a Gitter community, maybe we can try that: https://gitter.im/julia2nix/community?utm_source=share-link&utm_medium=link&utm_campaign=share-link

thomasjm commented 3 years ago

There's also this new GitHub feature called Discussions. I just enabled it for this repo. Might be worth trying out https://github.com/thomasjm/julia2nix/discussions