Skip to content

Commit

Permalink
refactor: use juliaWithPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Oct 2, 2023
1 parent dce36f6 commit c09a9cb
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 39 deletions.
3 changes: 3 additions & 0 deletions examples/julia/minimal/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{pkgs, ...}: {
kernel.julia.minimal-example = {
enable = true;
extraJuliaPackages = [
"Plots"
];
};
}
2 changes: 0 additions & 2 deletions examples/julia/minimal/installDeps.jl

This file was deleted.

2 changes: 1 addition & 1 deletion examples/python/native/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{pkgs, ...}: {
kernel.python.science-example = {
kernel.python.native-example = {
enable = true;
env = pkgs.python3.withPackages (ps:
with ps; [
Expand Down
2 changes: 1 addition & 1 deletion examples/python/native/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

current_dir = os.path.dirname(os.path.abspath(__file__))

@testbook(f'{current_dir}/test.ipynb', execute=True, kernel_name="python-science-example")
@testbook(f'{current_dir}/test.ipynb', execute=True, kernel_name="python-native-example")
def test_nb(tb):
np_result = tb.cell_output_text(1)
assert np_result == "[0 1 2 3 4]"
Expand Down
17 changes: 17 additions & 0 deletions flake.lock

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

4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

inputs.nixpkgs.url = "github:nixos/nixpkgs/2de8efefb6ce7f5e4e75bdf57376a96555986841";
inputs.nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-23.05";
inputs.nixpkgs-julia.url = "github:NixOS/nixpkgs/?ref=refs/pull/225513/head";
inputs.flake-compat.url = "github:edolstra/flake-compat";
inputs.flake-compat.flake = false;
inputs.flake-utils.url = "github:numtide/flake-utils";
Expand Down Expand Up @@ -49,7 +50,8 @@
pre-commit-hooks,
poetry2nix,
rust-overlay,
}: let
...
} @ inputs: let
inherit (nixpkgs) lib;

SYSTEMS = [
Expand Down
60 changes: 26 additions & 34 deletions modules/kernels/julia/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,25 @@
self,
system,
# custom arguments
pkgs ? self.inputs.nixpkgs.legacyPackages.${system},
pkgs,
name ? "julia",
displayName ? "Julia",
requiredRuntimePackages ? [],
runtimePackages ? [],
julia ? pkgs.julia,
julia_depot_path ? "~/.julia",
activateDir ? "",
ijuliaRev ? "6TIq1",
ijuliaRev ? "Vo51o",
extraJuliaPackages ? [],
override ? {},
}: let
inherit (pkgs) writeText;
inherit (pkgs.lib) optionalString;

startupFile = writeText "startup.jl" ''
import Pkg
Pkg.activate("${activateDir}")
Pkg.instantiate()
'';

allRuntimePackages = requiredRuntimePackages ++ runtimePackages;

env = julia;
env = (self.inputs.nixpkgs-julia.legacyPackages.${system}.julia_19.withPackages.override override) ([
"IJulia"
]
++ extraJuliaPackages);

wrappedEnv =
pkgs.runCommand "wrapper-${env.name}"
Expand All @@ -52,7 +49,7 @@
filename=$(basename $i)
ln -s ${env}/bin/$filename $out/bin/$filename
wrapProgram $out/bin/$filename \
--set PATH "${pkgs.lib.makeSearchPath "bin" allRuntimePackages}" ${optionalString (activateDir != "") ''--add-flags "-L ${startupFile}"''}
--set PATH "${pkgs.lib.makeSearchPath "bin" allRuntimePackages}"
done
'';
in {
Expand All @@ -63,7 +60,7 @@
"-i"
"--startup-file=yes"
"--color=yes"
"${julia_depot_path}/packages/IJulia/${ijuliaRev}/src/kernel.jl"
"${env.projectAndDepot}/depot/packages/IJulia/${ijuliaRev}/src/kernel.jl"
"{connection_file}"
];
codemirrorMode = "julia";
Expand All @@ -72,37 +69,32 @@
in {
options =
{
julia_depot_path = lib.mkOption {
ijuliaRev = lib.mkOption {
type = types.str;
default = "~/.julia";
example = "~/.julia";
default = "Vo51o";
description = lib.mdDoc ''
Julia path
IJulia revision
'';
};

activateDir = lib.mkOption {
type = types.str;
default = "";
example = "";
julia = lib.mkOption {
type = types.package;
default = config.nixpkgs.julia;
description = lib.mdDoc ''
Julia activate directory
Julia Version
'';
};

ijuliaRev = lib.mkOption {
type = types.str;
default = "6TIq1";
example = "6TIq1";
extraJuliaPackages = lib.mkOption {
type = types.listOf types.str;
default = [];
description = lib.mdDoc ''
iJulia revision
Extra Julia packages to install
'';
};
julia = lib.mkOption {
type = types.package;
default = config.nixpkgs.julia;
override = lib.mkOption {
type = types.attrs;
default = {};
description = lib.mdDoc ''
Julia Version
Override JuliaWithPackages
'';
};
}
Expand All @@ -112,7 +104,7 @@
build = mkKernel (kernelFunc config.kernelArgs);
kernelArgs =
{
inherit (config) julia_depot_path activateDir ijuliaRev julia;
inherit (config) override extraJuliaPackages ijuliaRev julia;
}
// kernelModule.kernelArgs;
};
Expand Down

0 comments on commit c09a9cb

Please sign in to comment.