Add library function to read public vars
This commit is contained in:
@@ -30,6 +30,8 @@ lib.fix (
|
|||||||
jsonschema = import ./jsonschema { inherit lib; };
|
jsonschema = import ./jsonschema { inherit lib; };
|
||||||
docs = import ./docs.nix { inherit lib; };
|
docs = import ./docs.nix { inherit lib; };
|
||||||
|
|
||||||
|
vars = import ./vars.nix { inherit lib; };
|
||||||
|
|
||||||
# flakes
|
# flakes
|
||||||
flakes = clanLib.callLib ./flakes.nix { };
|
flakes = clanLib.callLib ./flakes.nix { };
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ in
|
|||||||
{ name, ... }:
|
{ name, ... }:
|
||||||
{
|
{
|
||||||
_module.args._ctx = [ name ];
|
_module.args._ctx = [ name ];
|
||||||
|
_module.args.clanLib = specialArgs.clanLib;
|
||||||
|
_module.args.exports = config.exports;
|
||||||
|
_module.args.directory = directory;
|
||||||
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
./service-module.nix
|
./service-module.nix
|
||||||
|
|||||||
25
lib/vars.nix
Normal file
25
lib/vars.nix
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
_: {
|
||||||
|
getPublicValue =
|
||||||
|
{
|
||||||
|
|
||||||
|
backend ? "in_repo",
|
||||||
|
default ? throw "getPublicValue: Public value ${machine}/${generator}/${file} not found!",
|
||||||
|
shared ? false,
|
||||||
|
generator,
|
||||||
|
machine,
|
||||||
|
file,
|
||||||
|
flake,
|
||||||
|
}:
|
||||||
|
|
||||||
|
if backend == "in_repo" then
|
||||||
|
let
|
||||||
|
path =
|
||||||
|
if shared then
|
||||||
|
"${flake}/vars/shared/${generator}/${file}/value"
|
||||||
|
else
|
||||||
|
"${flake}/vars/per-machine/${machine}/${generator}/${file}/value";
|
||||||
|
in
|
||||||
|
if builtins.pathExists path then builtins.readFile path else default
|
||||||
|
else
|
||||||
|
throw "backend ${backend} does not implement getPublicValue";
|
||||||
|
}
|
||||||
@@ -167,7 +167,7 @@ in
|
|||||||
'';
|
'';
|
||||||
type = types.submoduleWith {
|
type = types.submoduleWith {
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
inherit (config) machines;
|
inherit (config) machines clanLib;
|
||||||
};
|
};
|
||||||
modules = [
|
modules = [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user