mirror of
https://gitlab.com/TECHNOFAB/nixlets.git
synced 2026-05-04 16:49:28 +02:00
Compare commits
1 commit
17229aa69b
...
1431a8f55d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1431a8f55d |
17 changed files with 178 additions and 512 deletions
|
|
@ -11,7 +11,6 @@ This is all that's needed:
|
||||||
```nix
|
```nix
|
||||||
(<nixlet>).mkDocs {
|
(<nixlet>).mkDocs {
|
||||||
# Params:
|
# Params:
|
||||||
# fullValues ? false,
|
|
||||||
# transformOptions ? opt: opt,
|
# transformOptions ? opt: opt,
|
||||||
# filter ? _: true,
|
# filter ? _: true,
|
||||||
# headingDepth ? 3,
|
# headingDepth ? 3,
|
||||||
|
|
@ -37,18 +36,3 @@ string
|
||||||
"Hello world!"
|
"Hello world!"
|
||||||
```
|
```
|
||||||
````
|
````
|
||||||
|
|
||||||
The `fullValues` param controls whether the docs should include dependency Nixlets.
|
|
||||||
For example, when defining `postgres` as a dependency, by default the docs would not
|
|
||||||
include these options. If it's `true`, everything is included.
|
|
||||||
|
|
||||||
Dependency Nixlets' options which you override from your own `values.nix` will show both
|
|
||||||
default values:
|
|
||||||
|
|
||||||
````md
|
|
||||||
**Overridden value**:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
<the overridden value set in values.nix>
|
|
||||||
```
|
|
||||||
````
|
|
||||||
|
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
# Importing Nixlets
|
|
||||||
|
|
||||||
Nixlets can now define dependency Nixlets and handle them similarly to how nested
|
|
||||||
Helm Charts work.
|
|
||||||
|
|
||||||
## Importing
|
|
||||||
|
|
||||||
To define a dependency Nixlet, give it a name and pass the Nixlet as a value:
|
|
||||||
|
|
||||||
```nix title="default.nix of Nixlet"
|
|
||||||
nixlet.dependencies."postgres" = <any nixlet>;
|
|
||||||
```
|
|
||||||
|
|
||||||
`<any nixlet>` here could be stuff like `nixlet-lib.fetchNixletFromGitlab {...}`,
|
|
||||||
`nixlet-lib.fetchNixlet <url> <sha>`, etc.
|
|
||||||
|
|
||||||
## Defining Values
|
|
||||||
|
|
||||||
You can pre-define values for dependency Nixlets like this:
|
|
||||||
|
|
||||||
```nix title="values.nix of Nixlet"
|
|
||||||
options = {
|
|
||||||
# options for the current Nixlet
|
|
||||||
};
|
|
||||||
# overwriting the default of dependency Nixlets (the user can still overwrite this using mkForce for example)
|
|
||||||
config."postgres".replicaCount = 10;
|
|
||||||
```
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
# Options
|
|
||||||
|
|
||||||
{{ include_raw("options.md") }}
|
|
||||||
7
flake.lock
generated
7
flake.lock
generated
|
|
@ -76,17 +76,16 @@
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"dir": "lib",
|
"dir": "lib",
|
||||||
"lastModified": 1775132170,
|
"lastModified": 1768913456,
|
||||||
"narHash": "sha256-ZhXcliu8E1KXlaviFnMHQpb/VSIbsALSFZoeb9Z6bhc=",
|
"narHash": "sha256-P+uWjzg09q57Ur2jWCkGwNvk1bMyU20kUIKHYj+kxK0=",
|
||||||
"owner": "rensa-nix",
|
"owner": "rensa-nix",
|
||||||
"repo": "core",
|
"repo": "core",
|
||||||
"rev": "bfdb2c1aa85cd4af286b0833b046e13a96d64d6a",
|
"rev": "e5f47b57ae06f2fc1f888bcb56413baccb5d1062",
|
||||||
"type": "gitlab"
|
"type": "gitlab"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"dir": "lib",
|
"dir": "lib",
|
||||||
"owner": "rensa-nix",
|
"owner": "rensa-nix",
|
||||||
"ref": "v0.2.0",
|
|
||||||
"repo": "core",
|
"repo": "core",
|
||||||
"type": "gitlab"
|
"type": "gitlab"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
flake.nix
11
flake.nix
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
ren.url = "gitlab:rensa-nix/core/v0.2.0?dir=lib";
|
ren.url = "gitlab:rensa-nix/core?dir=lib";
|
||||||
kubenix = {
|
kubenix = {
|
||||||
url = "github:TECHNOFAB11/kubenix";
|
url = "github:TECHNOFAB11/kubenix";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
@ -22,6 +22,15 @@
|
||||||
// {
|
// {
|
||||||
pkgs = import i.nixpkgs {inherit system;};
|
pkgs = import i.nixpkgs {inherit system;};
|
||||||
};
|
};
|
||||||
|
cellBlocks = with ren.blocks; [
|
||||||
|
(simple "devShells")
|
||||||
|
(simple "ci")
|
||||||
|
(simple "docs")
|
||||||
|
(simple "soonix")
|
||||||
|
(simple "apps")
|
||||||
|
(simple "nixlets")
|
||||||
|
(simple "tests")
|
||||||
|
];
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
packages = ren.select self [
|
packages = ren.select self [
|
||||||
|
|
|
||||||
330
lib/default.nix
330
lib/default.nix
|
|
@ -2,208 +2,139 @@
|
||||||
lib,
|
lib,
|
||||||
kubenix,
|
kubenix,
|
||||||
...
|
...
|
||||||
} @ attrs: let
|
} @ attrs:
|
||||||
inherit (lib) mkOption types evalModules concatMapStringsSep assertMsg;
|
with lib; rec {
|
||||||
nixlet-lib = rec {
|
evalValues = file: {rawValues, ...} @ args: (lib.evalModules {
|
||||||
nixletModule = ./nixletModule.nix;
|
specialArgs = {
|
||||||
|
utils = import ./utils.nix attrs;
|
||||||
evalValues = file: {
|
};
|
||||||
rawValues,
|
modules = [
|
||||||
dependencies,
|
file
|
||||||
args,
|
(_: {
|
||||||
check ? true,
|
# pass through all args to the values.nix module
|
||||||
...
|
config =
|
||||||
}: let
|
rawValues
|
||||||
moduleArgs =
|
// {
|
||||||
args
|
_module.args = args;
|
||||||
// {
|
|
||||||
utils = import ./utils.nix attrs;
|
|
||||||
};
|
|
||||||
# get the values from the dependencies, then import them nested
|
|
||||||
# (so you can set postgres.replicaCount in values.nix for example when adding "postgres" as dependency)
|
|
||||||
extraModules = map (depName: {
|
|
||||||
options.${depName} = mkOption {
|
|
||||||
type = types.submodule {
|
|
||||||
imports = ["${dependencies.${depName}.path}/values.nix"];
|
|
||||||
_module.args =
|
|
||||||
moduleArgs
|
|
||||||
// {
|
|
||||||
# make sure that dependencies see their own name and version etc.
|
|
||||||
nixlet = {
|
|
||||||
inherit (dependencies.${depName}) name version description;
|
|
||||||
inherit (moduleArgs.nixlet) project;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
default = {};
|
})
|
||||||
description = let
|
];
|
||||||
n = dependencies.${depName};
|
});
|
||||||
in ''
|
mkValues = file: args: (evalValues file args).config;
|
||||||
Imported Nixlet as a dependency:
|
|
||||||
|
|
||||||
|Name|Version|Description|
|
# wraps mkNixletInner to allow passing either a path or an attrset
|
||||||
|----|-------|-----------|
|
mkNixlet = arg:
|
||||||
|${n.name}|${n.version}|${n.description}|
|
mkNixletInner (
|
||||||
'';
|
if (builtins.typeOf arg) == "set"
|
||||||
};
|
then arg
|
||||||
}) (builtins.attrNames dependencies);
|
else
|
||||||
in
|
{path = arg;}
|
||||||
builtins.addErrorContext "[nixlets] while evaluating values" (
|
// (
|
||||||
evalModules {
|
if builtins.pathExists "${arg}/nixlet.nix"
|
||||||
modules =
|
then (import "${arg}/nixlet.nix")
|
||||||
[
|
else throw "Nixlet at '${arg}' does not contain nixlet.nix and mkNixlet was called with just a path"
|
||||||
file
|
)
|
||||||
{
|
);
|
||||||
_module = {
|
|
||||||
args = moduleArgs;
|
|
||||||
inherit check;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
{config = rawValues;}
|
|
||||||
]
|
|
||||||
++ extraModules;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
# wraps mkNixletInner to allow passing either a path or an attrset
|
mkNixletInner = {
|
||||||
mkNixlet = arg:
|
path,
|
||||||
mkNixletInner (
|
name,
|
||||||
if (builtins.typeOf arg) == "set"
|
version ? null,
|
||||||
then arg
|
description ? "",
|
||||||
else
|
defaultProject ? null,
|
||||||
{path = arg;}
|
...
|
||||||
// (
|
}: let
|
||||||
if builtins.pathExists "${arg}/nixlet.nix"
|
# every nixlet gets "nixlet" as arg with some useful data about itself
|
||||||
then (import "${arg}/nixlet.nix")
|
baseNixletArg = {
|
||||||
else throw "Nixlet at '${arg}' does not contain nixlet.nix and mkNixlet was called with just a path"
|
inherit name version description;
|
||||||
)
|
project = defaultProject;
|
||||||
);
|
};
|
||||||
|
nixlet = {
|
||||||
mkNixletInner = {
|
inherit name version description path;
|
||||||
path,
|
values = evalValues "${path}/values.nix" {
|
||||||
name,
|
rawValues = {};
|
||||||
version ? null,
|
nixlet = baseNixletArg;
|
||||||
description ? "",
|
|
||||||
defaultProject ? null,
|
|
||||||
...
|
|
||||||
}: let
|
|
||||||
# every nixlet gets "nixlet" as arg with some useful data about itself
|
|
||||||
baseNixletArg = {
|
|
||||||
inherit name version description;
|
|
||||||
project = defaultProject;
|
|
||||||
};
|
};
|
||||||
nixlet = {
|
mkDocs = opts: mkDocs (opts // {inherit nixlet;});
|
||||||
_type = "nixlet";
|
eval = {
|
||||||
inherit name version description path;
|
system,
|
||||||
# just values of the current nixlet (lighweight)
|
project ? defaultProject,
|
||||||
values = evalValues "${path}/values.nix" {
|
overrides ? (_: {}),
|
||||||
rawValues = {};
|
values ? {},
|
||||||
dependencies = {};
|
}:
|
||||||
# no checking since this doesn't include dependencies
|
assert lib.assertMsg (project != null) "No default project set, please pass a project to the render method"; let
|
||||||
check = false;
|
nixletArg = baseNixletArg // {inherit project;};
|
||||||
args.nixlet = baseNixletArg;
|
|
||||||
};
|
|
||||||
# full values, including dependencies etc. (complex)
|
|
||||||
fullValues = args: let
|
|
||||||
evaled = nixlet.eval args;
|
|
||||||
in
|
in
|
||||||
evalValues "${path}/values.nix" {
|
kubenix.evalModules.${system} {
|
||||||
rawValues = {};
|
module = {kubenix, ...}: {
|
||||||
inherit (evaled.config.nixlet) dependencies;
|
imports = with kubenix.modules; [
|
||||||
args.nixlet = baseNixletArg;
|
k8s
|
||||||
|
helm
|
||||||
|
docker
|
||||||
|
files
|
||||||
|
./secretsModule.nix
|
||||||
|
(_: let
|
||||||
|
finalValues = mkValues "${path}/values.nix" {
|
||||||
|
rawValues = values;
|
||||||
|
nixlet = nixletArg;
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
imports = [path];
|
||||||
|
_module.args.nixlet =
|
||||||
|
{
|
||||||
|
values = finalValues;
|
||||||
|
}
|
||||||
|
// nixletArg;
|
||||||
|
})
|
||||||
|
overrides
|
||||||
|
];
|
||||||
|
kubenix.project = project;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
mkDocs = opts: mkDocs (opts // {inherit nixlet;});
|
render = {
|
||||||
eval = {
|
system,
|
||||||
system,
|
project ? defaultProject,
|
||||||
project ? defaultProject,
|
overrides ? (_: {}),
|
||||||
overrides ? (_: {}),
|
values ? {},
|
||||||
values ? {},
|
}:
|
||||||
}:
|
(nixlet.eval {
|
||||||
assert assertMsg (project != null) "No default project set, please pass a project to the eval/render method"; let
|
inherit system project overrides values;
|
||||||
nixletArg = baseNixletArg // {inherit project;};
|
})
|
||||||
in
|
.config
|
||||||
builtins.addErrorContext "[nixlets] while evaluating nixlet ${name}" (
|
.kubernetes
|
||||||
kubenix.evalModules.${system} {
|
.resultYAML;
|
||||||
module = {
|
# combines all secrets files in a single directory
|
||||||
config,
|
secrets = args: (nixlet.eval args).config.kubernetes.secretsCombined;
|
||||||
kubenix,
|
};
|
||||||
...
|
in
|
||||||
}: {
|
nixlet;
|
||||||
imports = with kubenix.modules; [
|
|
||||||
k8s
|
|
||||||
helm
|
|
||||||
docker
|
|
||||||
files
|
|
||||||
./secretsModule.nix
|
|
||||||
./nixletModule.nix
|
|
||||||
(let
|
|
||||||
finalValues =
|
|
||||||
(evalValues "${path}/values.nix" {
|
|
||||||
rawValues = values;
|
|
||||||
inherit (config.nixlet) dependencies;
|
|
||||||
args.nixlet = nixletArg;
|
|
||||||
}).config;
|
|
||||||
in {
|
|
||||||
imports = [path];
|
|
||||||
_module.args = {
|
|
||||||
nixlet =
|
|
||||||
{
|
|
||||||
values = finalValues;
|
|
||||||
}
|
|
||||||
// nixletArg;
|
|
||||||
inherit nixlet-lib system;
|
|
||||||
};
|
|
||||||
})
|
|
||||||
overrides
|
|
||||||
];
|
|
||||||
kubenix.project = project;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
render = {
|
|
||||||
system,
|
|
||||||
project ? defaultProject,
|
|
||||||
overrides ? (_: {}),
|
|
||||||
values ? {},
|
|
||||||
}:
|
|
||||||
(nixlet.eval {
|
|
||||||
inherit system project overrides values;
|
|
||||||
})
|
|
||||||
.config
|
|
||||||
.kubernetes
|
|
||||||
.resultYAML;
|
|
||||||
# combines all secrets files in a single directory
|
|
||||||
secrets = args: (nixlet.eval args).config.kubernetes.secretsCombined;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
nixlet;
|
|
||||||
|
|
||||||
fetchNixlet = url: sha256: mkNixlet (builtins.fetchTarball {inherit url sha256;});
|
fetchNixlet = url: sha256: mkNixlet (builtins.fetchTarball {inherit url sha256;});
|
||||||
fetchNixletFromGitlab = {
|
fetchNixletFromGitlab = {
|
||||||
project,
|
project,
|
||||||
name,
|
name,
|
||||||
version,
|
version,
|
||||||
sha256,
|
sha256,
|
||||||
}: let
|
}: let
|
||||||
projectEscaped = builtins.replaceStrings ["/"] ["%2F"] project;
|
projectEscaped = builtins.replaceStrings ["/"] ["%2F"] project;
|
||||||
in
|
in
|
||||||
fetchNixlet "https://gitlab.com/api/v4/projects/${projectEscaped}/packages/generic/${name}/${version}/${name}.tar.gz" sha256;
|
fetchNixlet "https://gitlab.com/api/v4/projects/${projectEscaped}/packages/generic/${name}/${version}/${name}.tar.gz" sha256;
|
||||||
|
|
||||||
uploadNixletsToGitlab = {
|
uploadNixletsToGitlab = {
|
||||||
pkgs,
|
pkgs,
|
||||||
projectId,
|
projectId,
|
||||||
nixlets,
|
nixlets,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
pkgs.writeShellScriptBin "nixlets-upload" (
|
pkgs.writeShellScriptBin "nixlets-upload" (
|
||||||
''
|
''
|
||||||
if [[ -z "$AUTH_HEADER" ]]; then
|
if [[ -z "$AUTH_HEADER" ]]; then
|
||||||
echo "Must provide AUTH_HEADER environment variable!" 1>&2
|
echo "Must provide AUTH_HEADER environment variable!" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
''
|
''
|
||||||
+ concatMapStringsSep "\n"
|
+ lib.concatStringsSep "\n" (
|
||||||
(nixlet:
|
builtins.map (nixlet:
|
||||||
with nixlet; ''
|
with nixlet; ''
|
||||||
URL="https://gitlab.com/api/v4/projects/${projectId}/packages/generic/${name}/${version}/${name}.tar.gz"
|
URL="https://gitlab.com/api/v4/projects/${projectId}/packages/generic/${name}/${version}/${name}.tar.gz"
|
||||||
if ${pkgs.curl}/bin/curl --output /dev/null --silent --head --fail --header "$AUTH_HEADER" $URL; then
|
if ${pkgs.curl}/bin/curl --output /dev/null --silent --head --fail --header "$AUTH_HEADER" $URL; then
|
||||||
|
|
@ -217,10 +148,9 @@
|
||||||
fi
|
fi
|
||||||
'')
|
'')
|
||||||
nixlets
|
nixlets
|
||||||
);
|
)
|
||||||
|
);
|
||||||
|
|
||||||
mkDocs = opts:
|
mkDocs = opts:
|
||||||
import ./valuesDocs.nix (opts // {inherit lib;});
|
import ./valuesDocs.nix (opts // {inherit lib;});
|
||||||
};
|
}
|
||||||
in
|
|
||||||
nixlet-lib
|
|
||||||
|
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
{
|
|
||||||
lib,
|
|
||||||
config,
|
|
||||||
nixlet,
|
|
||||||
system,
|
|
||||||
...
|
|
||||||
}: let
|
|
||||||
inherit (lib) mkOption types mkOptionType isType mkMerge mapAttrs mkIf literalExpression;
|
|
||||||
cfg = config.nixlet;
|
|
||||||
|
|
||||||
nixletType = mkOptionType {
|
|
||||||
name = "nixlet";
|
|
||||||
description = "reference";
|
|
||||||
descriptionClass = "noun";
|
|
||||||
check = isType "nixlet";
|
|
||||||
};
|
|
||||||
in {
|
|
||||||
imports = [
|
|
||||||
{
|
|
||||||
# shortcut, allows accessing deps a bit shorter/more easily
|
|
||||||
_module.args.deps = cfg.deps;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
options.nixlet = {
|
|
||||||
dependencies = mkOption {
|
|
||||||
type = types.attrsOf nixletType;
|
|
||||||
default = {};
|
|
||||||
description = ''
|
|
||||||
Import other nixlets as dependencies. Works similar to Helm, specify values for these
|
|
||||||
Nixlets by using their name as a prefix. Like `postgres.replicaCount` in `values.nix` for example.
|
|
||||||
'';
|
|
||||||
example = literalExpression ''
|
|
||||||
{
|
|
||||||
"postgres" = nixlet-lib.mkNixlet <path>;
|
|
||||||
"mongodb" = nixlet-lib.fetchNixlet ...; # etc.
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
deps = mkOption {
|
|
||||||
readOnly = true;
|
|
||||||
type = types.attrsOf types.attrs;
|
|
||||||
default = mapAttrs (name: val:
|
|
||||||
builtins.addErrorContext "[nixlets] while evaluating dependency ${name}"
|
|
||||||
(val.eval {
|
|
||||||
inherit system;
|
|
||||||
inherit (config.kubenix) project;
|
|
||||||
values = nixlet.values.${name};
|
|
||||||
}).config)
|
|
||||||
cfg.dependencies;
|
|
||||||
description = ''
|
|
||||||
Evaluated dependency nixlets. Allows accessing their resources like for example:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
config.nixlet.deps."<name>".kubernetes.resources
|
|
||||||
```
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
depAutoMerge = mkOption {
|
|
||||||
type = types.bool;
|
|
||||||
default = true;
|
|
||||||
description = ''
|
|
||||||
Whether to automatically merge dependency nixlets' configs
|
|
||||||
with the current nixlet. If disabled, you can access dependency outputs via:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
config.nixlet.deps."<name>".kubernetes.resources
|
|
||||||
```
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = mkIf cfg.depAutoMerge {
|
|
||||||
kubernetes.resources = mkMerge (map (dep: dep.kubernetes.resources) (builtins.attrValues cfg.deps));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
nixlet,
|
nixlet,
|
||||||
# whether to generate docs for the full values, including dependencies
|
|
||||||
fullValues ? false,
|
|
||||||
transformOptions ? opt: opt,
|
transformOptions ? opt: opt,
|
||||||
filter ? _: true,
|
filter ? _: true,
|
||||||
headingDepth ? 3,
|
headingDepth ? 3,
|
||||||
|
|
@ -15,12 +13,7 @@
|
||||||
mapAttrsToList
|
mapAttrsToList
|
||||||
concatStrings
|
concatStrings
|
||||||
replicate
|
replicate
|
||||||
optionalString
|
|
||||||
optionAttrSetToDocList
|
|
||||||
attrByPath
|
|
||||||
generators
|
|
||||||
;
|
;
|
||||||
inherit (generators) toPretty;
|
|
||||||
|
|
||||||
_transformOptions = opt:
|
_transformOptions = opt:
|
||||||
transformOptions (opt
|
transformOptions (opt
|
||||||
|
|
@ -32,12 +25,7 @@
|
||||||
name = lib.removePrefix "config." opt.name;
|
name = lib.removePrefix "config." opt.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
valueSource =
|
rawOpts = lib.optionAttrSetToDocList nixlet.values.options;
|
||||||
if fullValues
|
|
||||||
# TODO: get rid of system, just here cuz of kubenix
|
|
||||||
then (nixlet.fullValues {system = "x86_64-linux";})
|
|
||||||
else nixlet.values;
|
|
||||||
rawOpts = optionAttrSetToDocList valueSource.options;
|
|
||||||
transformedOpts = map _transformOptions rawOpts;
|
transformedOpts = map _transformOptions rawOpts;
|
||||||
filteredOpts = lib.filter (opt: opt.visible && !opt.internal) transformedOpts;
|
filteredOpts = lib.filter (opt: opt.visible && !opt.internal) transformedOpts;
|
||||||
|
|
||||||
|
|
@ -70,20 +58,7 @@
|
||||||
${opt.type}
|
${opt.type}
|
||||||
```
|
```
|
||||||
''
|
''
|
||||||
# used to show what changes a nixlet did to values of dependencies
|
+ (lib.optionalString (opt ? default && opt.default != null) ''
|
||||||
+ (let
|
|
||||||
val = toPretty {} (attrByPath opt.loc "_not found_" valueSource.config);
|
|
||||||
default = removeSuffix "\n" opt.default.text;
|
|
||||||
in
|
|
||||||
optionalString (opt.type != "submodule" && val != default)
|
|
||||||
''
|
|
||||||
**Overridden value**:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
${val}
|
|
||||||
```
|
|
||||||
'')
|
|
||||||
+ (optionalString (opt ? default && opt.default != null) ''
|
|
||||||
|
|
||||||
**Default value**:
|
**Default value**:
|
||||||
|
|
||||||
|
|
@ -91,7 +66,7 @@
|
||||||
${removeSuffix "\n" opt.default.text}
|
${removeSuffix "\n" opt.default.text}
|
||||||
```
|
```
|
||||||
'')
|
'')
|
||||||
+ (optionalString (opt ? example) ''
|
+ (lib.optionalString (opt ? example) ''
|
||||||
|
|
||||||
**Example value**:
|
**Example value**:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,67 +3,27 @@
|
||||||
inputs,
|
inputs,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (inputs) pkgs devshell treefmt devtools-lib;
|
inherit (inputs) pkgs devshell treefmt;
|
||||||
inherit (cell) soonix;
|
inherit (cell) soonix;
|
||||||
treefmtWrapper = treefmt.mkWrapper pkgs {
|
|
||||||
projectRootFile = "flake.nix";
|
|
||||||
programs = {
|
|
||||||
alejandra.enable = true;
|
|
||||||
deadnix.enable = true;
|
|
||||||
statix.enable = true;
|
|
||||||
mdformat.enable = true;
|
|
||||||
};
|
|
||||||
settings.formatter.mdformat = {
|
|
||||||
excludes = ["CHANGELOG.md"];
|
|
||||||
command = let
|
|
||||||
pkg = pkgs.python3.withPackages (p: [
|
|
||||||
p.mdformat
|
|
||||||
p.mdformat-mkdocs
|
|
||||||
]);
|
|
||||||
in "${pkg}/bin/mdformat";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in {
|
in {
|
||||||
default = devshell.mkShell {
|
default = devshell.mkShell {
|
||||||
imports = [soonix.devshellModule devtools-lib.devshellModule];
|
imports = [soonix.devshellModule];
|
||||||
packages = [
|
packages = [
|
||||||
pkgs.nil
|
pkgs.nil
|
||||||
treefmtWrapper
|
(treefmt.mkWrapper pkgs {
|
||||||
|
programs = {
|
||||||
|
alejandra.enable = true;
|
||||||
|
deadnix.enable = true;
|
||||||
|
statix.enable = true;
|
||||||
|
mdformat.enable = true;
|
||||||
|
};
|
||||||
|
settings.formatter.mdformat.command = let
|
||||||
|
pkg = pkgs.python3.withPackages (p: [
|
||||||
|
p.mdformat
|
||||||
|
p.mdformat-mkdocs
|
||||||
|
]);
|
||||||
|
in "${pkg}/bin/mdformat";
|
||||||
|
})
|
||||||
];
|
];
|
||||||
lefthook.config = {
|
|
||||||
"pre-commit" = {
|
|
||||||
parallel = true;
|
|
||||||
jobs = [
|
|
||||||
{
|
|
||||||
name = "treefmt";
|
|
||||||
stage_fixed = true;
|
|
||||||
run = "${treefmtWrapper}/bin/treefmt";
|
|
||||||
env.TERM = "dumb";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "soonix";
|
|
||||||
stage_fixed = true;
|
|
||||||
run = "nix run .#soonix:update";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
cocogitto.config = {
|
|
||||||
tag_prefix = "v";
|
|
||||||
ignore_merge_commits = true;
|
|
||||||
changelog = {
|
|
||||||
authors = [
|
|
||||||
{
|
|
||||||
username = "TECHNOFAB";
|
|
||||||
signature = "technofab";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
path = "CHANGELOG.md";
|
|
||||||
template = "remote";
|
|
||||||
remote = "gitlab.com";
|
|
||||||
repository = "nixlets";
|
|
||||||
owner = "TECHNOFAB";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,22 +3,8 @@
|
||||||
cell,
|
cell,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (inputs) pkgs doclib nixlet-lib;
|
inherit (inputs) doclib;
|
||||||
inherit (cell) nixlets;
|
inherit (cell) nixlets;
|
||||||
|
|
||||||
optionsDoc = doclib.mkOptionDocs {
|
|
||||||
module = nixlet-lib.nixletModule;
|
|
||||||
roots = [
|
|
||||||
{
|
|
||||||
url = "https://gitlab.com/TECHNOFAB/nixlets/-/blob/main/lib";
|
|
||||||
path = "${inputs.self}/lib";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
optionsDocs = pkgs.runCommand "options-docs" {} ''
|
|
||||||
mkdir -p $out
|
|
||||||
ln -s ${optionsDoc} $out/options.md
|
|
||||||
'';
|
|
||||||
in
|
in
|
||||||
(doclib.mkDocs {
|
(doclib.mkDocs {
|
||||||
docs."default" = {
|
docs."default" = {
|
||||||
|
|
@ -37,13 +23,9 @@ in
|
||||||
domains = ["nixlets.projects.tf"];
|
domains = ["nixlets.projects.tf"];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
macros = {
|
|
||||||
enable = true;
|
|
||||||
includeDir = toString optionsDocs;
|
|
||||||
};
|
|
||||||
dynamic-nav = {
|
dynamic-nav = {
|
||||||
enable = true;
|
enable = true;
|
||||||
files."Nixlets Values" = builtins.map (val: {${val.name} = val.mkDocs {fullValues = true;};}) (builtins.attrValues nixlets);
|
files."Nixlets Values" = builtins.map (val: {${val.name} = val.mkDocs {};}) (builtins.attrValues nixlets);
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
site_name = "Nixlets";
|
site_name = "Nixlets";
|
||||||
|
|
@ -61,10 +43,8 @@ in
|
||||||
{"Creating Nixlets" = "creation.md";}
|
{"Creating Nixlets" = "creation.md";}
|
||||||
{"Packaging" = "packaging.md";}
|
{"Packaging" = "packaging.md";}
|
||||||
{"Usage" = "usage.md";}
|
{"Usage" = "usage.md";}
|
||||||
{"Importing" = "importing.md";}
|
|
||||||
{"Generating Docs" = "generating_docs.md";}
|
{"Generating Docs" = "generating_docs.md";}
|
||||||
{"Secrets" = "secrets.md";}
|
{"Secrets" = "secrets.md";}
|
||||||
{"Options" = "options.md";}
|
|
||||||
];
|
];
|
||||||
markdown_extensions = [
|
markdown_extensions = [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
41
nix/repo/flake.lock
generated
41
nix/repo/flake.lock
generated
|
|
@ -3,39 +3,20 @@
|
||||||
"devshell-lib": {
|
"devshell-lib": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"dir": "lib",
|
"dir": "lib",
|
||||||
"lastModified": 1767218348,
|
"lastModified": 1767274074,
|
||||||
"narHash": "sha256-8MJqwH9sRMuHH+RsB7iqWyWD30TgmpiYKEvegAULggs=",
|
"narHash": "sha256-h2grM9qoSnYdqN7K8+taeMuWC2umaN/c2FCBu48frlo=",
|
||||||
"owner": "rensa-nix",
|
"owner": "rensa-nix",
|
||||||
"repo": "devshell",
|
"repo": "devshell",
|
||||||
"rev": "7a9b7e5d9f162a1fa3edfdc0169cdc29d3a67f8e",
|
"rev": "5508ced269ee40ff7f5261ee3b5bf5597f7cad5d",
|
||||||
"type": "gitlab"
|
"type": "gitlab"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"dir": "lib",
|
"dir": "lib",
|
||||||
"owner": "rensa-nix",
|
"owner": "rensa-nix",
|
||||||
"ref": "v0.1.0",
|
|
||||||
"repo": "devshell",
|
"repo": "devshell",
|
||||||
"type": "gitlab"
|
"type": "gitlab"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"devtools-lib": {
|
|
||||||
"locked": {
|
|
||||||
"dir": "lib",
|
|
||||||
"lastModified": 1767214272,
|
|
||||||
"narHash": "sha256-gvW7flZ60xdv3Z3Ksec5jcRjW2sqRHsGoJdwsNWQVPk=",
|
|
||||||
"owner": "rensa-nix",
|
|
||||||
"repo": "devtools",
|
|
||||||
"rev": "f40e59c32c48cdbf4cbc621c2f0f11e7bb80dbd3",
|
|
||||||
"type": "gitlab"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"dir": "lib",
|
|
||||||
"owner": "rensa-nix",
|
|
||||||
"ref": "v0.1.0",
|
|
||||||
"repo": "devtools",
|
|
||||||
"type": "gitlab"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nix-gitlab-ci-lib": {
|
"nix-gitlab-ci-lib": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"dir": "lib",
|
"dir": "lib",
|
||||||
|
|
@ -67,7 +48,6 @@
|
||||||
"original": {
|
"original": {
|
||||||
"dir": "lib",
|
"dir": "lib",
|
||||||
"owner": "TECHNOFAB",
|
"owner": "TECHNOFAB",
|
||||||
"ref": "v1.1.0",
|
|
||||||
"repo": "nixmkdocs",
|
"repo": "nixmkdocs",
|
||||||
"type": "gitlab"
|
"type": "gitlab"
|
||||||
}
|
}
|
||||||
|
|
@ -75,17 +55,16 @@
|
||||||
"nixtest-lib": {
|
"nixtest-lib": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"dir": "lib",
|
"dir": "lib",
|
||||||
"lastModified": 1775133683,
|
"lastModified": 1769441055,
|
||||||
"narHash": "sha256-06jKKes7NjBQClKXTZTmo7GiGJhe1j5ZMW6jle8Vr1o=",
|
"narHash": "sha256-SrHLnM3UMzpj5/o52yf3lFOVpsIGEU5nAFUkdeJO1bM=",
|
||||||
"owner": "TECHNOFAB",
|
"owner": "TECHNOFAB",
|
||||||
"repo": "nixtest",
|
"repo": "nixtest",
|
||||||
"rev": "143921cad9e6076700a45cdb7ff47c91f9801225",
|
"rev": "9f9fcb85349003edb554574d0e3f623811866f50",
|
||||||
"type": "gitlab"
|
"type": "gitlab"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"dir": "lib",
|
"dir": "lib",
|
||||||
"owner": "TECHNOFAB",
|
"owner": "TECHNOFAB",
|
||||||
"ref": "v1.3.0",
|
|
||||||
"repo": "nixtest",
|
"repo": "nixtest",
|
||||||
"type": "gitlab"
|
"type": "gitlab"
|
||||||
}
|
}
|
||||||
|
|
@ -93,7 +72,6 @@
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"devshell-lib": "devshell-lib",
|
"devshell-lib": "devshell-lib",
|
||||||
"devtools-lib": "devtools-lib",
|
|
||||||
"nix-gitlab-ci-lib": "nix-gitlab-ci-lib",
|
"nix-gitlab-ci-lib": "nix-gitlab-ci-lib",
|
||||||
"nixmkdocs-lib": "nixmkdocs-lib",
|
"nixmkdocs-lib": "nixmkdocs-lib",
|
||||||
"nixtest-lib": "nixtest-lib",
|
"nixtest-lib": "nixtest-lib",
|
||||||
|
|
@ -104,17 +82,16 @@
|
||||||
"soonix-lib": {
|
"soonix-lib": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"dir": "lib",
|
"dir": "lib",
|
||||||
"lastModified": 1767647496,
|
"lastModified": 1769607658,
|
||||||
"narHash": "sha256-1kvCEp7PJnKTcnAjN+Me6swiygeMgJInsZsRQ5bdpH8=",
|
"narHash": "sha256-gF9/QmmaNRgqkC5cqSGgwWvGXj9Mj4qMDkvvF/5BlSA=",
|
||||||
"owner": "TECHNOFAB",
|
"owner": "TECHNOFAB",
|
||||||
"repo": "soonix",
|
"repo": "soonix",
|
||||||
"rev": "5e479f3662db1c338679cdb3fd080cf06e4c67d4",
|
"rev": "19a88a0c2681bbc85bc2cbe4f2860316d50fe957",
|
||||||
"type": "gitlab"
|
"type": "gitlab"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"dir": "lib",
|
"dir": "lib",
|
||||||
"owner": "TECHNOFAB",
|
"owner": "TECHNOFAB",
|
||||||
"ref": "v0.1.0",
|
|
||||||
"repo": "soonix",
|
"repo": "soonix",
|
||||||
"type": "gitlab"
|
"type": "gitlab"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
devshell-lib.url = "gitlab:rensa-nix/devshell/v0.1.0?dir=lib";
|
devshell-lib.url = "gitlab:rensa-nix/devshell?dir=lib";
|
||||||
devtools-lib.url = "gitlab:rensa-nix/devtools/v0.1.0?dir=lib";
|
nixtest-lib.url = "gitlab:TECHNOFAB/nixtest?dir=lib";
|
||||||
nixtest-lib.url = "gitlab:TECHNOFAB/nixtest/v1.3.0?dir=lib";
|
soonix-lib.url = "gitlab:TECHNOFAB/soonix?dir=lib";
|
||||||
soonix-lib.url = "gitlab:TECHNOFAB/soonix/v0.1.0?dir=lib";
|
nixmkdocs-lib.url = "gitlab:TECHNOFAB/nixmkdocs?dir=lib";
|
||||||
nixmkdocs-lib.url = "gitlab:TECHNOFAB/nixmkdocs/v1.1.0?dir=lib";
|
|
||||||
nix-gitlab-ci-lib.url = "gitlab:TECHNOFAB/nix-gitlab-ci/3.1.2?dir=lib";
|
nix-gitlab-ci-lib.url = "gitlab:TECHNOFAB/nix-gitlab-ci/3.1.2?dir=lib";
|
||||||
treefmt-nix = {
|
treefmt-nix = {
|
||||||
url = "github:numtide/treefmt-nix";
|
url = "github:numtide/treefmt-nix";
|
||||||
|
|
|
||||||
3
tests/fixtures/dependency/default.nix
vendored
3
tests/fixtures/dependency/default.nix
vendored
|
|
@ -1,3 +0,0 @@
|
||||||
{nixlet-lib, ...}: {
|
|
||||||
config.nixlet.dependencies."example" = nixlet-lib.mkNixlet ../example;
|
|
||||||
}
|
|
||||||
6
tests/fixtures/dependency/nixlet.nix
vendored
6
tests/fixtures/dependency/nixlet.nix
vendored
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
name = "dep";
|
|
||||||
version = "0.0.1";
|
|
||||||
description = "hello world";
|
|
||||||
defaultProject = "dep";
|
|
||||||
}
|
|
||||||
5
tests/fixtures/dependency/values.nix
vendored
5
tests/fixtures/dependency/values.nix
vendored
|
|
@ -1,5 +0,0 @@
|
||||||
_: {
|
|
||||||
options = {};
|
|
||||||
|
|
||||||
config."example".example = "Hello dependency!";
|
|
||||||
}
|
|
||||||
4
tests/fixtures/example/default.nix
vendored
4
tests/fixtures/example/default.nix
vendored
|
|
@ -1,4 +0,0 @@
|
||||||
{nixlet, ...}:
|
|
||||||
with nixlet; {
|
|
||||||
kubernetes.resources.configMaps."test".data."test" = values.example;
|
|
||||||
}
|
|
||||||
|
|
@ -3,14 +3,11 @@
|
||||||
ntlib,
|
ntlib,
|
||||||
nixlet-lib,
|
nixlet-lib,
|
||||||
...
|
...
|
||||||
}: let
|
}: {
|
||||||
inherit (pkgs.lib) mkForce;
|
|
||||||
in {
|
|
||||||
suites."Lib Tests" = {
|
suites."Lib Tests" = {
|
||||||
pos = __curPos;
|
pos = __curPos;
|
||||||
tests = let
|
tests = let
|
||||||
nixlet = nixlet-lib.mkNixlet ./fixtures/example;
|
nixlet = nixlet-lib.mkNixlet ./fixtures/example;
|
||||||
depNixlet = nixlet-lib.mkNixlet ./fixtures/dependency;
|
|
||||||
in [
|
in [
|
||||||
{
|
{
|
||||||
name = "mkNixlet fail on nonexistant nixlet.nix";
|
name = "mkNixlet fail on nonexistant nixlet.nix";
|
||||||
|
|
@ -45,27 +42,6 @@ in {
|
||||||
assert_file_contains "${docs}" '"Hello world!"'
|
assert_file_contains "${docs}" '"Hello world!"'
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
{
|
|
||||||
name = "Nixlet dependencies";
|
|
||||||
expected = "Hello dependency!";
|
|
||||||
actual = let
|
|
||||||
evaled = depNixlet.eval {inherit (pkgs.stdenv.hostPlatform) system;};
|
|
||||||
in
|
|
||||||
evaled.config.kubernetes.resources.configMaps."test".data."test";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "Nixlet dependency value override";
|
|
||||||
expected = "Hello override!";
|
|
||||||
actual = let
|
|
||||||
evaled = depNixlet.eval {
|
|
||||||
inherit (pkgs.stdenv.hostPlatform) system;
|
|
||||||
values = {
|
|
||||||
"example".example = mkForce "Hello override!";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
|
||||||
evaled.config.kubernetes.resources.configMaps."test".data."test";
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue