Skip to content

Commit

Permalink
Refactor: import nixpkgs via module's config.nixpkgs (#425)
Browse files Browse the repository at this point in the history
* imp: add passthru kernels

it allows us to link the kernelPaths, for solving some tools getting the
kernelInfo only from ~/.local/jupyter/kernles or another place

* refactor: import nixpkgs via module's config.nixpkgs

* chore: move options.poetry to types dir

---------

Co-authored-by: Dan Baker <[email protected]>
  • Loading branch information
GTrunSec and djacu authored Feb 9, 2023
1 parent c42c207 commit 9fc7d31
Show file tree
Hide file tree
Showing 19 changed files with 195 additions and 169 deletions.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@
*/
mkJupyterlabEval = customModule:
pkgs.lib.evalModules {
specialArgs = {inherit self system pkgs mkJupyterlab;};
specialArgs = {inherit self system mkJupyterlab;};
modules = lib.flatten (
[./modules]
++ lib.optional (customModule != null) customModule
Expand Down
4 changes: 2 additions & 2 deletions kernels/available/bash/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import ./../../../modules/poetry.nix {
kernelName = "bash";
requiredRuntimePackages = [
config.nixpkgs.legacyPackages.${system}.bashInteractive
config.nixpkgs.legacyPackages.${system}.coreutils
config.nixpkgs.bashInteractive
config.nixpkgs.coreutils
];
}
args
2 changes: 1 addition & 1 deletion kernels/available/c/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
} @ args:
import ./../../../modules/poetry.nix {
requiredRuntimePackages = [
config.nixpkgs.legacyPackages.${system}.stdenv.cc
config.nixpkgs.stdenv.cc
];
kernelName = "c";
}
Expand Down
2 changes: 1 addition & 1 deletion kernels/available/elm/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
} @ args:
import ./../../../modules/poetry.nix {
requiredRuntimePackages = [
config.nixpkgs.legacyPackages.${system}.elmPackages.elm
config.nixpkgs.elmPackages.elm
];
kernelName = "elm";
}
Expand Down
2 changes: 1 addition & 1 deletion kernels/available/go/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
name,
...
}: let
requiredRuntimePackages = [config.nixpkgs.legacyPackages.${system}.go];
requiredRuntimePackages = [config.nixpkgs.go];
args = {inherit self system lib config name kernelName requiredRuntimePackages;};
kernelModule = import ./../../../modules/kernel.nix args;
in {
Expand Down
2 changes: 1 addition & 1 deletion kernels/available/haskell/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
...
}: let
requiredRuntimePackages = [
config.nixpkgs.legacyPackages.${system}.haskell.compiler.${config.haskellCompiler}
config.nixpkgs.haskell.compiler.${config.haskellCompiler}
];
args = {inherit self system lib config name kernelName requiredRuntimePackages;};
kernelModule = import ./../../../modules/kernel.nix args;
Expand Down
2 changes: 1 addition & 1 deletion kernels/available/javascript/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
config = lib.mkIf config.enable {
kernelArgs =
{
ijavascript = config.nixpkgs.legacyPackages.${system}.nodePackages.ijavascript;
ijavascript = config.nixpkgs.nodePackages.ijavascript;
}
// kernelModule.kernelArgs;
};
Expand Down
2 changes: 1 addition & 1 deletion kernels/available/julia/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
};
julia = lib.mkOption {
type = types.package;
default = config.nixpkgs.legacyPackages.${system}.julia;
default = config.nixpkgs.julia;
description = lib.mdDoc ''
Julia Version
'';
Expand Down
2 changes: 1 addition & 1 deletion kernels/available/nix/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
} @ args:
import ./../../../modules/poetry.nix {
requiredRuntimePackages = [
config.nixpkgs.legacyPackages.${system}.nix
config.nixpkgs.nix
];
kernelName = "nix";
}
Expand Down
4 changes: 2 additions & 2 deletions kernels/available/r/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{
rWrapper = lib.mkOption {
type = types.package;
default = config.nixpkgs.legacyPackages.${system}.rWrapper;
default = config.nixpkgs.rWrapper;
defaultText = lib.literalExpression "pkgs.rWrapper";
description = lib.mdDoc ''
R version from nixpkgs.
Expand All @@ -29,7 +29,7 @@

rPackages = lib.mkOption {
type = types.attrs;
default = config.nixpkgs.legacyPackages.${system}.rPackages;
default = config.nixpkgs.rPackages;
defaultText = lib.literalExpression "pkgs.rPackages";
description = lib.mdDoc ''
A set of R packages.
Expand Down
10 changes: 5 additions & 5 deletions kernels/available/rust/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
...
}: let
requiredRuntimePackages = [
config.nixpkgs.legacyPackages.${system}.cargo
config.nixpkgs.legacyPackages.${system}.gcc
config.nixpkgs.legacyPackages.${system}.binutils-unwrapped
config.nixpkgs.cargo
config.nixpkgs.gcc
config.nixpkgs.binutils-unwrapped
];
args = {inherit self system lib config name kernelName requiredRuntimePackages;};
kernelModule = import ./../../../modules/kernel.nix args;
Expand All @@ -25,7 +25,7 @@
{
evcxr = lib.mkOption {
type = types.package;
default = config.nixpkgs.legacyPackages.${system}.evcxr;
default = config.nixpkgs.evcxr;
example = lib.literalExpression "pkgs.evcxr";
description = lib.mdDoc ''
An evaluation context for Rust.
Expand All @@ -48,7 +48,7 @@
kernelModule.kernelArgs
// {
inherit (config) evcxr rust-overlay;
pkgs = import config.nixpkgs {
pkgs = import config.nixpkgs.path {
inherit system;
overlays = [config.rust-overlay.overlays.default];
};
Expand Down
8 changes: 4 additions & 4 deletions kernels/available/scala/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{
scala = lib.mkOption {
type = types.package;
default = config.nixpkgs.legacyPackages.${system}.scala;
default = config.nixpkgs.scala;
example = lib.literalExpression "pkgs.scala";
description = lib.mdDoc ''
Scala package to use with almond.
Expand All @@ -29,7 +29,7 @@

coursier = lib.mkOption {
type = types.package;
default = config.nixpkgs.legacyPackages.${system}.coursier;
default = config.nixpkgs.coursier;
example = lib.literalExpression "pkgs.coursier";
description = lib.mdDoc ''
Coursier package to use with almond.
Expand All @@ -38,7 +38,7 @@

jdk = lib.mkOption {
type = types.package;
default = config.nixpkgs.legacyPackages.${system}.jdk;
default = config.nixpkgs.jdk;
example = lib.literalExpression "pkgs.jdk";
description = lib.mdDoc ''
JDK package to use with almond.
Expand All @@ -47,7 +47,7 @@

jre = lib.mkOption {
type = types.package;
default = config.nixpkgs.legacyPackages.${system}.jre;
default = config.nixpkgs.jre;
example = lib.literalExpression "pkgs.jre";
description = lib.mdDoc ''
JRE package to use with almond.
Expand Down
4 changes: 2 additions & 2 deletions kernels/available/zsh/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
} @ args:
import ./../../../modules/poetry.nix {
requiredRuntimePackages = [
config.nixpkgs.legacyPackages.${system}.zsh
config.nixpkgs.legacyPackages.${system}.coreutils
config.nixpkgs.zsh
config.nixpkgs.coreutils
];
kernelName = "zsh";
}
Expand Down
8 changes: 3 additions & 5 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
config,
lib,
mkJupyterlab,
system,
...
}: let
types = lib.types;
Expand All @@ -27,11 +28,7 @@ in {
internal = true;
};

nixpkgs = lib.mkOption {
type = types.path;
default = self.inputs.nixpkgs;
internal = true;
};
nixpkgs = import ./types/nixpkgs.nix {inherit lib self system;};
};

imports = [
Expand Down Expand Up @@ -77,5 +74,6 @@ in {
runtimePackages = config.jupyterlab.runtimePackages;
#flakes = config.flakes;
};
_module.args.pkgs = config.nixpkgs;
};
}
12 changes: 2 additions & 10 deletions modules/kernel.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,7 @@ in {
'';
};

nixpkgs = lib.mkOption {
type = types.path;
default = self.inputs.nixpkgs;
defaultText = lib.literalExpression "self.inputs.nixpkgs";
example = lib.literalExpression "self.inputs.nixpkgs";
description = lib.mdDoc ''
nixpkgs flake input to be used for this ${kernelName} kernel.
'';
};
nixpkgs = import ./types/nixpkgs.nix {inherit lib self system;};

kernelArgs = lib.mkOption {
type = types.lazyAttrsOf types.raw;
Expand All @@ -80,6 +72,6 @@ in {
requiredRuntimePackages
runtimePackages
;
pkgs = config.nixpkgs.legacyPackages.${system};
pkgs = config.nixpkgs;
};
}
131 changes: 2 additions & 129 deletions modules/poetry.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,134 +19,7 @@
kernelModule = import ./kernel.nix args;
in {
options =
{
projectDir = lib.mkOption {
type = types.path;
default = self + "/kernels/available/${kernelName}";
defaultText = lib.literalExpression "self + \"/kernels/available/${kernelName}\"";
example = lib.literalExpression "self + \"/kernels/${kernelName}\"";
description = lib.mdDoc ''
Path to the root of the poetry project that provides this ${kernelName}
kernel.
'';
};

pyproject = lib.mkOption {
type = types.path;
default = config.projectDir + "/pyproject.toml";
defaultText = lib.literalExpression "kernel.${kernelName}.<name>.projectDir + \"/pyproject.toml\"";
example = lib.literalExpression "self + \"/kernels/${kernelName}/pyproject.toml\"";
description = ''
Path to `pyproject.toml` of the poetry project that provides this
${kernelName} kernel.
'';
};

poetrylock = lib.mkOption {
type = types.path;
default = config.projectDir + "/poetry.lock";
defaultText = lib.literalExpression "kernel.${kernelName}.<name>.projectDir + \"/poetry.lock\"";
example = lib.literalExpression "self + \"/kernels/${kernelName}/poetry.lock\"";
description = ''
Path to `poetry.lock` of the poetry project that provides this
${kernelName} kernel.
'';
};

overrides = lib.mkOption {
type = types.path;
default = self + "/kernels/available/${kernelName}/overrides.nix";
defaultText = lib.literalExpression "self + \"/kernels/available/${kernelName}/overrides.nix\"";
example = lib.literalExpression "self + \"/kernels/${kernelName}/overrides.nix\"";
description = ''
Path to `overrides.nix` file which provides python package overrides
for this ${kernelName} kernel.
'';
};

withDefaultOverrides = lib.mkOption {
type = types.bool;
default = true;
example = lib.literalExpression "false";
description = ''
Should we use default overrides provided by `poetry2nix`.
'';
};

python = lib.mkOption {
type = types.str;
default = "python3";
example = "python310";
description = lib.mdDoc ''
Name of the python interpreter (from nixpkgs) to be used for this
${kernelName} kernel.
'';
};

editablePackageSources = lib.mkOption {
type = types.attrsOf (types.nullOr types.path);
default = {};
example = lib.literalExpression "{}";
description = ''
A mapping from package name to source directory, these will be
installed in editable mode. Note that path dependencies with `develop
= true` will be installed in editable mode unless explicitly passed
to `editablePackageSources` as `null`.
'';
};

extraPackages = lib.mkOption {
type = types.functionTo (types.listOf types.package);
default = ps: [];
defaultText = lib.literalExpression "ps: []";
example = lib.literalExpression "ps: [ps.numpy]";
description = ''
A function taking a Python package set and returning a list of extra
packages to include in the environment. This is intended for
packages deliberately not added to `pyproject.toml` that you still
want to include. An example of such a package may be `pip`.
'';
};

preferWheels = lib.mkOption {
type = types.bool;
default = false;
example = lib.literalExpression "true";
description = lib.mdDoc ''
Use wheels rather than sdist as much as possible.
'';
};

groups = lib.mkOption {
type = types.listOf types.str;
default = ["dev"];
defaultText = lib.literalExpression "[\"dev\"]";
example = lib.literalExpression ''["dev" "doc"]'';
description = lib.mdDoc ''
Which Poetry 1.2.0+ dependency groups to install for this ${kernelName}
kernel.
'';
};

poetry2nix = lib.mkOption {
type = types.path;
default = self.inputs.poetry2nix;
defaultText = lib.literalExpression "self.inputs.poetry2nix";
example = lib.literalExpression "self.inputs.poetry2nix";
description = lib.mdDoc ''
poetry2nix flake input to be used for this ${kernelName} kernel.
'';
};

ignoreCollisions = lib.mkOption {
type = types.bool;
default = false;
example = lib.literalExpression "true";
description = lib.mdDoc ''
Ignore file collisions inside the environment.
'';
};
}
import ./types/poetry.nix {inherit lib self config kernelName;}
// kernelModule.options;

config = lib.mkIf config.enable {
Expand All @@ -163,7 +36,7 @@
groups
ignoreCollisions
;
pkgs = config.nixpkgs.legacyPackages.${system};
pkgs = config.nixpkgs;
python = pkgs.${config.python};
poetry = pkgs.callPackage "${config.poetry2nix}/pkgs/poetry" {inherit python;};
poetry2nix = import "${config.poetry2nix}/default.nix" {inherit pkgs poetry;};
Expand Down
Loading

0 comments on commit 9fc7d31

Please sign in to comment.