From 841606b92492f3c6ec8a37135031e01ab413ed4a Mon Sep 17 00:00:00 2001 From: guangtao Date: Mon, 6 Nov 2023 21:13:45 -0800 Subject: [PATCH] feat(units/std/blockTypes): add jupyenv support --- local/cells/repo/configs.nix | 2 + src/flakeOutputs.nix | 2 +- src/ops/readYAML.nix | 4 +- src/outputs.nix | 1 + src/pops/jupyenv.nix | 28 ++++++++++++ src/pops/load.nix | 2 +- src/pops/std.nix | 10 +++++ templates/hivebus/nix/lib/__init.nix | 4 ++ templates/hivebus/nix/lib/flakeOutputs.nix | 1 + templates/hivebus/nix/lib/hosts.nix | 1 + templates/nixos/nix/lib/__init.nix | 4 ++ templates/nixos/nix/lib/flakeOutputs.nix | 1 + templates/nixos/nix/lib/hosts.nix | 1 + tests/nixos/_pops.nix | 1 + units/std/blockTypes/jupyenv.nix | 30 +++++++++++++ units/std/mkCommand.nix | 52 ++++++++++++++++++++++ 16 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 src/outputs.nix create mode 100644 src/pops/jupyenv.nix create mode 100644 src/pops/std.nix create mode 100644 units/std/blockTypes/jupyenv.nix create mode 100644 units/std/mkCommand.nix diff --git a/local/cells/repo/configs.nix b/local/cells/repo/configs.nix index 29a21dc..77a96a3 100755 --- a/local/cells/repo/configs.nix +++ b/local/cells/repo/configs.nix @@ -26,6 +26,8 @@ in "homeModules" "darwinModules" "darwinProfiles" + "units" + "units/*" ".*." ]; }; diff --git a/src/flakeOutputs.nix b/src/flakeOutputs.nix index 2f52c55..c9bbc32 100644 --- a/src/flakeOutputs.nix +++ b/src/flakeOutputs.nix @@ -17,7 +17,7 @@ in ; units = { - inherit (outputs) configs; + inherit (outputs) configs std; nixos = { inherit (outputs) nixosProfiles nixosModules; }; diff --git a/src/ops/readYAML.nix b/src/ops/readYAML.nix index 214b7b5..11af43d 100644 --- a/src/ops/readYAML.nix +++ b/src/ops/readYAML.nix @@ -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; diff --git a/src/outputs.nix b/src/outputs.nix new file mode 100644 index 0000000..68043a3 --- /dev/null +++ b/src/outputs.nix @@ -0,0 +1 @@ +super.flakeOutputs diff --git a/src/pops/jupyenv.nix b/src/pops/jupyenv.nix new file mode 100644 index 0000000..9df112d --- /dev/null +++ b/src/pops/jupyenv.nix @@ -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; } diff --git a/src/pops/load.nix b/src/pops/load.nix index a118eec..6cc6a48 100644 --- a/src/pops/load.nix +++ b/src/pops/load.nix @@ -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 diff --git a/src/pops/std.nix b/src/pops/std.nix new file mode 100644 index 0000000..1706e65 --- /dev/null +++ b/src/pops/std.nix @@ -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; + }; +} diff --git a/templates/hivebus/nix/lib/__init.nix b/templates/hivebus/nix/lib/__init.nix index cbd3ad8..7aba032 100644 --- a/templates/hivebus/nix/lib/__init.nix +++ b/templates/hivebus/nix/lib/__init.nix @@ -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 = ../..; diff --git a/templates/hivebus/nix/lib/flakeOutputs.nix b/templates/hivebus/nix/lib/flakeOutputs.nix index 111981f..b1a774a 100644 --- a/templates/hivebus/nix/lib/flakeOutputs.nix +++ b/templates/hivebus/nix/lib/flakeOutputs.nix @@ -4,6 +4,7 @@ omnibus, eachSystem, projectDir, + flops, }: let filterConfigs = diff --git a/templates/hivebus/nix/lib/hosts.nix b/templates/hivebus/nix/lib/hosts.nix index fd60cab..9b1c2e1 100644 --- a/templates/hivebus/nix/lib/hosts.nix +++ b/templates/hivebus/nix/lib/hosts.nix @@ -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 // { diff --git a/templates/nixos/nix/lib/__init.nix b/templates/nixos/nix/lib/__init.nix index cbd3ad8..7aba032 100644 --- a/templates/nixos/nix/lib/__init.nix +++ b/templates/nixos/nix/lib/__init.nix @@ -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 = ../..; diff --git a/templates/nixos/nix/lib/flakeOutputs.nix b/templates/nixos/nix/lib/flakeOutputs.nix index 111981f..b1a774a 100644 --- a/templates/nixos/nix/lib/flakeOutputs.nix +++ b/templates/nixos/nix/lib/flakeOutputs.nix @@ -4,6 +4,7 @@ omnibus, eachSystem, projectDir, + flops, }: let filterConfigs = diff --git a/templates/nixos/nix/lib/hosts.nix b/templates/nixos/nix/lib/hosts.nix index fd60cab..9b1c2e1 100644 --- a/templates/nixos/nix/lib/hosts.nix +++ b/templates/nixos/nix/lib/hosts.nix @@ -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 // { diff --git a/tests/nixos/_pops.nix b/tests/nixos/_pops.nix index 0a78b61..8c8db2c 100644 --- a/tests/nixos/_pops.nix +++ b/tests/nixos/_pops.nix @@ -5,6 +5,7 @@ }: (omnibus.pops.load { src = ./__fixture; + loader = with haumea; [ (matchers.nix loaders.scoped) ]; inputs = { data = root.data; inputs = { diff --git a/units/std/blockTypes/jupyenv.nix b/units/std/blockTypes/jupyenv.nix new file mode 100644 index 0000000..2847d63 --- /dev/null +++ b/units/std/blockTypes/jupyenv.nix @@ -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 "$@") + '' + { } + ) + ]; +} diff --git a/units/std/mkCommand.nix b/units/std/mkCommand.nix new file mode 100644 index 0000000..e1cda5b --- /dev/null +++ b/units/std/mkCommand.nix @@ -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; + }; +}