Skip to content

Commit

Permalink
refactor/move-kernelfunc (#462)
Browse files Browse the repository at this point in the history
extract kernelFunc to modules/poetry.nix.
  • Loading branch information
djacu authored Sep 11, 2023
1 parent 3ad2c95 commit 97f76f9
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 483 deletions.
72 changes: 4 additions & 68 deletions modules/kernels/bash/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,78 +7,14 @@
import ./../../poetry.nix {
inherit mkKernel;

argvKernelName = "bash_kernel";
codemirrorMode = "shell";
language = "bash";

kernelName = "bash";
requiredRuntimePackages = [
config.nixpkgs.bashInteractive
config.nixpkgs.coreutils
];

kernelFunc = {
self,
system,
# custom arguments
pkgs ? self.inputs.nixpkgs.legacyPackages.${system},
name ? "bash",
displayName ? "Bash",
requiredRuntimePackages ? with pkgs; [bashInteractive coreutils],
runtimePackages ? [],
# https://github.com/nix-community/poetry2nix
poetry2nix ? import "${self.inputs.poetry2nix}/default.nix" {inherit pkgs poetry;},
poetry ? pkgs.callPackage "${self.inputs.poetry2nix}/pkgs/poetry" {inherit python;},
# https://github.com/nix-community/poetry2nix#mkPoetryPackages
projectDir ? self + "/modules/kernels/bash",
pyproject ? projectDir + "/pyproject.toml",
poetrylock ? projectDir + "/poetry.lock",
overrides ? poetry2nix.overrides.withDefaults (import ./overrides.nix),
python ? pkgs.python3,
editablePackageSources ? {},
extraPackages ? ps: [],
preferWheels ? false,
groups ? ["dev"],
ignoreCollisions ? false,
}: let
env =
(poetry2nix.mkPoetryEnv {
inherit
projectDir
pyproject
poetrylock
overrides
python
editablePackageSources
extraPackages
preferWheels
groups
;
})
.override (args: {inherit ignoreCollisions;});

allRuntimePackages = requiredRuntimePackages ++ runtimePackages;

wrappedEnv =
pkgs.runCommand "wrapper-${env.name}"
{nativeBuildInputs = [pkgs.makeWrapper];}
''
mkdir -p $out/bin
for i in ${env}/bin/*; do
filename=$(basename $i)
ln -s ${env}/bin/$filename $out/bin/$filename
wrapProgram $out/bin/$filename \
--set PATH "${pkgs.lib.makeSearchPath "bin" allRuntimePackages}"
done
'';
in {
inherit name displayName;
language = "bash";
argv = [
"${wrappedEnv}/bin/python"
"-m"
"bash_kernel"
"-f"
"{connection_file}"
];
codemirrorMode = "shell";
logo64 = ./logo64.png;
};
}
args
72 changes: 4 additions & 68 deletions modules/kernels/c/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,13 @@
import ./../../poetry.nix {
inherit mkKernel;

argvKernelName = "jupyter_c_kernel";
codemirrorMode = "clike";
language = "c";

requiredRuntimePackages = [
config.nixpkgs.stdenv.cc
];
kernelName = "c";

kernelFunc = {
self,
system,
# custom arguments
pkgs ? self.inputs.nixpkgs.legacyPackages.${system},
name ? "c",
displayName ? "C",
requiredRuntimePackages ? [pkgs.stdenv.cc],
runtimePackages ? [],
# https://github.com/nix-community/poetry2nix
poetry2nix ? import "${self.inputs.poetry2nix}/default.nix" {inherit pkgs poetry;},
poetry ? pkgs.callPackage "${self.inputs.poetry2nix}/pkgs/poetry" {inherit python;},
# https://github.com/nix-community/poetry2nix#mkPoetryEnv
projectDir ? self + "/modules/kernels/c",
pyproject ? projectDir + "/pyproject.toml",
poetrylock ? projectDir + "/poetry.lock",
overrides ? poetry2nix.overrides.withDefaults (import ./overrides.nix),
python ? pkgs.python3,
editablePackageSources ? {},
extraPackages ? ps: [],
preferWheels ? false,
groups ? ["dev"],
ignoreCollisions ? false,
}: let
env =
(poetry2nix.mkPoetryEnv {
inherit
projectDir
pyproject
poetrylock
overrides
python
editablePackageSources
extraPackages
preferWheels
groups
;
})
.override (args: {inherit ignoreCollisions;});

allRuntimePackages = requiredRuntimePackages ++ runtimePackages;

wrappedEnv =
pkgs.runCommand "wrapper-${env.name}"
{nativeBuildInputs = [pkgs.makeWrapper];}
''
mkdir -p $out/bin
for i in ${env}/bin/*; do
filename=$(basename $i)
ln -s ${env}/bin/$filename $out/bin/$filename
wrapProgram $out/bin/$filename \
--set PATH "${pkgs.lib.makeSearchPath "bin" allRuntimePackages}"
done
'';
in {
inherit name displayName;
language = "c";
argv = [
"${wrappedEnv}/bin/python"
"-m"
"jupyter_c_kernel"
"-f"
"{connection_file}"
];
codemirrorMode = "clike";
logo64 = ./logo64.png;
};
}
args
72 changes: 4 additions & 68 deletions modules/kernels/elm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,13 @@
import ./../../poetry.nix {
inherit mkKernel;

argvKernelName = "elm_kernel";
codemirrorMode = "elm";
language = "elm";

requiredRuntimePackages = [
config.nixpkgs.elmPackages.elm
];
kernelName = "elm";

kernelFunc = {
self,
system,
# custom arguments
pkgs ? self.inputs.nixpkgs.legacyPackages.${system},
name ? "elm",
displayName ? "Elm",
requiredRuntimePackages ? with pkgs.elmPackages; [elm],
runtimePackages ? [],
# https://github.com/nix-community/poetry2nix
poetry2nix ? import "${self.inputs.poetry2nix}/default.nix" {inherit pkgs poetry;},
poetry ? pkgs.callPackage "${self.inputs.poetry2nix}/pkgs/poetry" {inherit python;},
# https://github.com/nix-community/poetry2nix#mkPoetryEnv
projectDir ? self + "/modules/kernels/elm",
pyproject ? projectDir + "/pyproject.toml",
poetrylock ? projectDir + "/poetry.lock",
overrides ? poetry2nix.overrides.withDefaults (import ./overrides.nix),
python ? pkgs.python3,
editablePackageSources ? {},
extraPackages ? ps: [],
preferWheels ? false,
groups ? ["dev"],
ignoreCollisions ? false,
}: let
env =
(poetry2nix.mkPoetryEnv {
inherit
projectDir
pyproject
poetrylock
overrides
python
editablePackageSources
extraPackages
preferWheels
groups
;
})
.override (args: {inherit ignoreCollisions;});

allRuntimePackages = requiredRuntimePackages ++ runtimePackages;

wrappedEnv =
pkgs.runCommand "wrapper-${env.name}"
{nativeBuildInputs = [pkgs.makeWrapper];}
''
mkdir -p $out/bin
for i in ${env}/bin/*; do
filename=$(basename $i)
ln -s ${env}/bin/$filename $out/bin/$filename
wrapProgram $out/bin/$filename \
--set PATH "${pkgs.lib.makeSearchPath "bin" allRuntimePackages}"
done
'';
in {
inherit name displayName;
language = "elm";
argv = [
"${wrappedEnv}/bin/python"
"-m"
"elm_kernel"
"-f"
"{connection_file}"
];
codemirrorMode = "elm";
logo64 = ./logo64.png;
};
}
args
74 changes: 4 additions & 70 deletions modules/kernels/nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,79 +7,13 @@
import ./../../poetry.nix {
inherit mkKernel;

argvKernelName = "nix-kernel";
codemirrorMode = "";
language = "nix";

requiredRuntimePackages = [
config.nixpkgs.nix
];
kernelName = "nix";

kernelFunc = {
self,
system,
# custom arguments
pkgs ? self.inputs.nixpkgs.legacyPackages.${system},
name ? "nix",
displayName ? "Nix",
nix ? pkgs.nixVersions.stable,
requiredRuntimePackages ? [nix],
runtimePackages ? [],
nixpkgsPath ? pkgs.path,
# https://github.com/nix-community/poetry2nix
poetry2nix ? import "${self.inputs.poetry2nix}/default.nix" {inherit pkgs poetry;},
poetry ? pkgs.callPackage "${self.inputs.poetry2nix}/pkgs/poetry" {inherit python;},
# https://github.com/nix-community/poetry2nix#mkPoetryPackages
projectDir ? self + "/modules/kernels/nix",
pyproject ? projectDir + "/pyproject.toml",
poetrylock ? projectDir + "/poetry.lock",
overrides ? poetry2nix.overrides.withDefaults (import ./overrides.nix),
python ? pkgs.python3,
editablePackageSources ? {},
extraPackages ? ps: [],
preferWheels ? false,
groups ? ["dev"],
ignoreCollisions ? false,
}: let
env =
(poetry2nix.mkPoetryEnv {
inherit
projectDir
pyproject
poetrylock
overrides
python
editablePackageSources
extraPackages
preferWheels
groups
;
})
.override (args: {inherit ignoreCollisions;});

allRuntimePackages = requiredRuntimePackages ++ runtimePackages;

wrappedEnv =
pkgs.runCommand "wrapper-${env.name}"
{nativeBuildInputs = [pkgs.makeWrapper];}
''
mkdir -p $out/bin
for i in ${env}/bin/*; do
filename=$(basename $i)
ln -s ${env}/bin/$filename $out/bin/$filename
wrapProgram $out/bin/$filename \
--set PATH "${pkgs.lib.makeSearchPath "bin" allRuntimePackages}"\
--set NIX_PATH "nixpkgs=${nixpkgsPath}"
done
'';
in {
inherit name displayName;
language = "Nix";
argv = [
"${wrappedEnv}/bin/python"
"-m"
"nix-kernel"
"-f"
"{connection_file}"
];
logo64 = ./logo64.png;
};
}
args
Loading

0 comments on commit 97f76f9

Please sign in to comment.