Skip to content

Commit

Permalink
refactor: fix nix-kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Oct 2, 2023
1 parent c1e0601 commit e3aed5b
Showing 1 changed file with 93 additions and 12 deletions.
105 changes: 93 additions & 12 deletions modules/kernels/nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,100 @@
{
config,
self,
system,
config,
lib,
mkKernel,
...
} @ args:
import ./../../poetry.nix {
inherit mkKernel;

argvKernelName = "nix-kernel";
codemirrorMode = "";
language = "nix";
}: let
inherit (lib) types;

requiredRuntimePackages = [
config.nixpkgs.nix
];
kernelName = "nix";
kernelOptions = {
config,
name,
...
}: let
args = {inherit self system lib config name kernelName;};
kernelModule = import ./../../kernel.nix args;
kernelFunc = {
self,
system,
# custom arguments
pkgs ? self.inputs.nixpkgs.legacyPackages.${system},
name ? "nix",
displayName ? "Nix",
requiredRuntimePackages ? [],
runtimePackages ? [],
nix ? pkgs.nix,
}: let
allRuntimePackages =
requiredRuntimePackages
++ runtimePackages
++ [
nix
];

env = pkgs.python3.withPackages (ps: with ps; [nix-kernel]);

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=${pkgs.path}"
done
'';
in {
inherit name displayName;
language = "nix";
argv = [
"${wrappedEnv}/bin/python"
"-m"
"nix-kernel"
"-f"
"{connection_file}"
];
codemirrorMode = "nix";
logo64 = ./logo64.png;
};
in {
options =
{
nix = lib.mkOption {
type = types.package;
default = config.nixpkgs.nix;
description = lib.mdDoc ''
Nix Version
'';
};
}
// kernelModule.options;

config = lib.mkIf config.enable {
build = mkKernel (kernelFunc config.kernelArgs);
kernelArgs =
{
inherit (config) nix;
}
// kernelModule.kernelArgs;
};
};
in {
options.kernel.${kernelName} = lib.mkOption {
type = types.attrsOf (types.submodule kernelOptions);
default = {};
example = lib.literalExpression ''
{
kernel.${kernelName}."example".enable = true;
}
'';
description = lib.mdDoc ''
A ${kernelName} kernel for IPython.
'';
};
}
args

0 comments on commit e3aed5b

Please sign in to comment.