Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flake module #523

Merged
merged 5 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions flake-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
top @ {
config,
flake-parts-lib,
lib,
...
}: let
inherit (lib) mkOption types;
in {
# User options defined in perSystem below.
options.jupyenv.flake = mkOption {
internal = true;
description = "The jupyenv flake";
};

options.perSystem = flake-parts-lib.mkPerSystemOption (
{
config,
pkgs,
system,
...
}: let
jupyenv = top.config.jupyenv.flake;
cfg = config.jupyenv;
inherit (jupyenv.lib.${system}) mkJupyterlabNew;

jupyterlab = mkJupyterlabNew ({...}: {
nixpkgs = pkgs;
imports = [cfg.kernels];
});
in {
options.jupyenv = {
kernels = mkOption {
type = types.deferredModule;
description = ''
A module that defines all the kernels to be installed.

You may reference a file, or multiple files using `imports`.
'';
};
pkgs = mkOption {
type = types.pkgs;
description = ''
Nixpkgs instance to use.
'';
default = pkgs;
defaultText = lib.literalMD "`pkgs` module argument";
};
packageName = mkOption {
description = ''
Attribute name to use for the generated `package` and `apps` definitions.

You will be able to run `nix run .#<packageName>` to start jupyterlab.

The default value, `"default"` also allows `nix run` without argument, but may compete with other modules' packages.
'';
default = "default";
};
};

config = {
packages.${cfg.packageName} = jupyterlab;
apps.${cfg.packageName} = {
program = "${jupyterlab}/bin/jupyter-lab";
type = "app";
};
};
}
);
}
38 changes: 27 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@
"aarch64-darwin"
];

welcomeText = ''
You have created a jupyenv template.

Run `nix run` to immediately try it out.

See the jupyenv documentation for more information.

https://jupyenv.io/documentation/getting-started/
'';

kernelLib = import ./lib/kernels.nix {inherit self lib;};
in
(flake-utils.lib.eachSystem SYSTEMS (
Expand Down Expand Up @@ -174,18 +184,24 @@
}
))
// {
templates.default = {
path = ./template;
# https://flake.parts/options/jupyenv
flakeModule = {
_file = "${toString ./.}/flake.nix#flakeModule";
imports = [
./flake-module.nix
{jupyenv.flake = self;}
];
};
templates.default = self.templates.flake-utils;
templates.flake-utils = {
path = ./template/flake-utils;
description = "Boilerplate for your jupyenv project";
welcomeText = ''
You have created a jupyenv template.

Run `nix run` to immediately try it out.

See the jupyenv documentation for more information.

https://jupyenv.io/documentation/getting-started/
'';
inherit welcomeText;
};
templates.flake-parts = {
path = ./template/flake-parts;
description = "Boilerplate for your jupyenv project";
inherit welcomeText;
};
};
}
29 changes: 29 additions & 0 deletions template/flake-parts/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
description = "Your jupyenv project";

nixConfig.extra-substituters = [
"https://tweag-jupyter.cachix.org"
];
nixConfig.extra-trusted-public-keys = [
"tweag-jupyter.cachix.org-1:UtNH4Zs6hVUFpFBTLaA4ejYavPo5EFFqgd7G7FxGW9g="
];

inputs.flake-parts.url = "github:hercules-ci/flake-parts";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs.jupyenv.url = "github:tweag/jupyenv";

outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
inputs.jupyenv.flakeModule
];
systems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
perSystem = {
lib,
pkgs,
...
}: {
jupyenv.kernels = ./kernels.nix;
};
};
}
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions template/flake-utils/kernels.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{pkgs, ...}: {
kernel.python.minimal = {
enable = true;
};
}
Loading