Skip to content

Commit

Permalink
feat(units/std/blockTypes): add jupyenv support
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Nov 7, 2023
1 parent 5c3909e commit 841606b
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 3 deletions.
2 changes: 2 additions & 0 deletions local/cells/repo/configs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ in
"homeModules"
"darwinModules"
"darwinProfiles"
"units"
"units/*"
".*."
];
};
Expand Down
2 changes: 1 addition & 1 deletion src/flakeOutputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ in
;

units = {
inherit (outputs) configs;
inherit (outputs) configs std;
nixos = {
inherit (outputs) nixosProfiles nixosModules;
};
Expand Down
4 changes: 3 additions & 1 deletion src/ops/readYAML.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{ inputs, root }: # source from std
let
inherit (root.errors.requiredInputs inputs "lib" [ "nixpkgs" ]) nixpkgs;
inherit (root.errors.requiredInputs inputs "omnibus.pops.self" [ "nixpkgs" ])
nixpkgs
;

inherit (builtins) fromJSON;
inherit (nixpkgs) runCommand yq-go;
Expand Down
1 change: 1 addition & 0 deletions src/outputs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
super.flakeOutputs
28 changes: 28 additions & 0 deletions src/pops/jupyenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
root,
lib,
super,
}:
load:
let
inherit
(root.errors.requiredInputs load.inputs.inputs "omnibus.pops.jupyenv" [
"jupyenv"
"nixpkgs"
])
nixpkgs
jupyenv
;
inherit (jupyenv.lib.${nixpkgs.system}) mkJupyterlabNew mkJupyterlabEval;

setJupyenvModule =
module: mkJupyterlabEval { imports = lib.flatten [ module ]; };
in
(super.nixosProfiles.addLoadExtender {
load = {
inputs = {
inherit setJupyenvModule mkJupyterlabNew mkJupyterlabEval;
};
};
}).addLoadExtender
{ inherit load; }
2 changes: 1 addition & 1 deletion src/pops/load.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ load:
(flops.haumea.pops.default.setInit (
recursiveMerge' [
{
loader = with haumea; [ (matchers.nix loaders.scoped) ];
# loader = with haumea; [ (matchers.nix loaders.default) ];
inputs = root.lib.loaderInputs;
}
load
Expand Down
10 changes: 10 additions & 0 deletions src/pops/std.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let
inherit (root.errors.requiredInputs inputs "omnibus.pops.self" [ "std" ]) std;
in
super.load {
loader = with haumea; [ (matchers.nix loaders.scoped) ];
src = projectDir + "/units/std";
inputs.inputs = {
inherit std;
};
}
4 changes: 4 additions & 0 deletions templates/hivebus/nix/lib/__init.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{ inputs, eachSystem }:
let
inherit ((inputs.omnibus.pops.load { }).load.inputs) haumea;
in
(inputs.omnibus.pops.load {
src = ./.;
loader = with haumea; [ (matchers.nix loaders.scoped) ];
inputs = {
inherit inputs eachSystem;
projectDir = ../..;
Expand Down
1 change: 1 addition & 0 deletions templates/hivebus/nix/lib/flakeOutputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
omnibus,
eachSystem,
projectDir,
flops,
}:
let
filterConfigs =
Expand Down
1 change: 1 addition & 0 deletions templates/hivebus/nix/lib/hosts.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(inputs.omnibus.pops.load {
src = projectDir + "/units/nixos/hosts";
loader = with haumea; [ (matchers.nix loaders.scoped) ];
inputs = {
inputs = inputs // root.pops.subflake.inputs;
omnibus = inputs.omnibus // {
Expand Down
4 changes: 4 additions & 0 deletions templates/nixos/nix/lib/__init.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{ inputs, eachSystem }:
let
inherit ((inputs.omnibus.pops.load { }).load.inputs) haumea;
in
(inputs.omnibus.pops.load {
src = ./.;
loader = with haumea; [ (matchers.nix loaders.scoped) ];
inputs = {
inherit inputs eachSystem;
projectDir = ../..;
Expand Down
1 change: 1 addition & 0 deletions templates/nixos/nix/lib/flakeOutputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
omnibus,
eachSystem,
projectDir,
flops,
}:
let
filterConfigs =
Expand Down
1 change: 1 addition & 0 deletions templates/nixos/nix/lib/hosts.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(inputs.omnibus.pops.load {
src = projectDir + "/units/nixos/hosts";
loader = with haumea; [ (matchers.nix loaders.scoped) ];
inputs = {
inputs = inputs // root.pops.subflake.inputs;
omnibus = inputs.omnibus // {
Expand Down
1 change: 1 addition & 0 deletions tests/nixos/_pops.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
}:
(omnibus.pops.load {
src = ./__fixture;
loader = with haumea; [ (matchers.nix loaders.scoped) ];
inputs = {
data = root.data;
inputs = {
Expand Down
30 changes: 30 additions & 0 deletions units/std/blockTypes/jupyenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{ inputs, root }:
/* Use the Runnables Blocktype for targets that you want to
make accessible with a 'run' action on the TUI.
*/
let
inherit (inputs.std) actions;
inherit (root) mkCommand;
in
name: {
inherit name;
type = "jupyenv";
actions =
{
currentSystem,
fragment,
fragmentRelPath,
target,
inputs,
}:
[
(actions.build currentSystem target.config.build)
(actions.run currentSystem target.config.build)
(mkCommand currentSystem "quarto" "pass any command to quarto" [ ]
''
(cd "$PRJ_ROOT" && ${target.config.quartoEnv}/bin/quarto "$@")
''
{ }
)
];
}
52 changes: 52 additions & 0 deletions units/std/mkCommand.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{ inputs }:
currentSystem: name: description: deps: command: args:
let
inherit (inputs.std.inputs) nixpkgs;
inherit (nixpkgs.legacyPackages.${currentSystem}) pkgs;
inherit (pkgs)
lib
stdenv
haskell
shellcheck
runtimeShell
;
inherit (pkgs.haskell.lib.compose) justStaticExecutables;
in
args
// {
inherit name description;
command = pkgs.writeTextFile {
inherit name;
executable = true;
checkPhase = ''
runHook preCheck
${stdenv.shellDryRun} "$target"
# use shellcheck which does not include docs
# pandoc takes long to build and documentation isn't needed for in nixpkgs usage
${lib.getExe (justStaticExecutables shellcheck.unwrapped)} "$target"
runHook postCheck
'';
text =
''
#!${runtimeShell}
set -o errexit
set -o nounset
set -o pipefail
if test -z "$PRJ_ROOT"; then
echo "All Standard Block Type Actions require an environment that fulfills the PRJ Base Directiory Specification"
echo "see: https://github.com/numtide/prj-spec"
echo "Tip: To achieve that, you can enter a Standard direnv environment or run the action via the Standard CLI/TUI"
exit 1
fi
# Action Code follows ...
''
+ lib.optionalString (deps != [ ]) ''
# Be optionally reproducible due to potential overhead to load some
# quaasi-ubiquitous dependencies that are already generally available
export PATH="${lib.makeBinPath deps}:$PATH"
''
+ command;
};
}

0 comments on commit 841606b

Please sign in to comment.