Compare commits

..

7 commits

18 changed files with 524 additions and 190 deletions

View file

@ -11,6 +11,7 @@ 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,
@ -36,3 +37,18 @@ 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>
```
````

27
docs/importing.md Normal file
View file

@ -0,0 +1,27 @@
# 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;
```

3
docs/options.md Normal file
View file

@ -0,0 +1,3 @@
# Options
{{ include_raw("options.md") }}

13
flake.lock generated
View file

@ -41,11 +41,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1772198003, "lastModified": 1769461804,
"narHash": "sha256-I45esRSssFtJ8p/gLHUZ1OUaaTaVLluNkABkk6arQwE=", "narHash": "sha256-msG8SU5WsBUfVVa/9RPLaymvi5bI8edTavbIq3vRlhI=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "dd9b079222d43e1943b6ebd802f04fd959dc8e61", "rev": "bfc1b8a4574108ceef22f02bafcf6611380c100d",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -76,16 +76,17 @@
}, },
"locked": { "locked": {
"dir": "lib", "dir": "lib",
"lastModified": 1768913456, "lastModified": 1775132170,
"narHash": "sha256-P+uWjzg09q57Ur2jWCkGwNvk1bMyU20kUIKHYj+kxK0=", "narHash": "sha256-ZhXcliu8E1KXlaviFnMHQpb/VSIbsALSFZoeb9Z6bhc=",
"owner": "rensa-nix", "owner": "rensa-nix",
"repo": "core", "repo": "core",
"rev": "e5f47b57ae06f2fc1f888bcb56413baccb5d1062", "rev": "bfdb2c1aa85cd4af286b0833b046e13a96d64d6a",
"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"
} }

View file

@ -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?dir=lib"; ren.url = "gitlab:rensa-nix/core/v0.2.0?dir=lib";
kubenix = { kubenix = {
url = "github:TECHNOFAB11/kubenix"; url = "github:TECHNOFAB11/kubenix";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -22,15 +22,6 @@
// { // {
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 [

View file

@ -2,25 +2,68 @@
lib, lib,
kubenix, kubenix,
... ...
} @ attrs: } @ attrs: let
with lib; rec { inherit (lib) mkOption types evalModules concatMapStringsSep assertMsg;
evalValues = file: {rawValues, ...} @ args: (lib.evalModules { nixlet-lib = rec {
specialArgs = { nixletModule = ./nixletModule.nix;
evalValues = file: {
rawValues,
dependencies,
args,
check ? true,
...
}: let
moduleArgs =
args
// {
utils = import ./utils.nix attrs; utils = import ./utils.nix attrs;
}; };
modules = [ # get the values from the dependencies, then import them nested
file # (so you can set postgres.replicaCount in values.nix for example when adding "postgres" as dependency)
(_: { extraModules = map (depName: {
# pass through all args to the values.nix module options.${depName} = mkOption {
config = type = types.submodule {
rawValues imports = ["${dependencies.${depName}.path}/values.nix"];
_module.args =
moduleArgs
// { // {
_module.args = args; # make sure that dependencies see their own name and version etc.
nixlet = {
inherit (dependencies.${depName}) name version description;
inherit (moduleArgs.nixlet) project;
}; };
}) };
]; };
}); default = {};
mkValues = file: args: (evalValues file args).config; description = let
n = dependencies.${depName};
in ''
Imported Nixlet as a dependency:
|Name|Version|Description|
|----|-------|-----------|
|${n.name}|${n.version}|${n.description}|
'';
};
}) (builtins.attrNames dependencies);
in
builtins.addErrorContext "[nixlets] while evaluating values" (
evalModules {
modules =
[
file
{
_module = {
args = moduleArgs;
inherit check;
};
}
{config = rawValues;}
]
++ extraModules;
}
);
# wraps mkNixletInner to allow passing either a path or an attrset # wraps mkNixletInner to allow passing either a path or an attrset
mkNixlet = arg: mkNixlet = arg:
@ -50,10 +93,24 @@ with lib; rec {
project = defaultProject; project = defaultProject;
}; };
nixlet = { nixlet = {
_type = "nixlet";
inherit name version description path; inherit name version description path;
# just values of the current nixlet (lighweight)
values = evalValues "${path}/values.nix" { values = evalValues "${path}/values.nix" {
rawValues = {}; rawValues = {};
nixlet = baseNixletArg; dependencies = {};
# no checking since this doesn't include dependencies
check = false;
args.nixlet = baseNixletArg;
};
# full values, including dependencies etc. (complex)
fullValues = args: let
evaled = nixlet.eval args;
in
evalValues "${path}/values.nix" {
rawValues = {};
inherit (evaled.config.nixlet) dependencies;
args.nixlet = baseNixletArg;
}; };
mkDocs = opts: mkDocs (opts // {inherit nixlet;}); mkDocs = opts: mkDocs (opts // {inherit nixlet;});
eval = { eval = {
@ -62,35 +119,47 @@ with lib; rec {
overrides ? (_: {}), overrides ? (_: {}),
values ? {}, values ? {},
}: }:
assert lib.assertMsg (project != null) "No default project set, please pass a project to the render method"; let assert assertMsg (project != null) "No default project set, please pass a project to the eval/render method"; let
nixletArg = baseNixletArg // {inherit project;}; nixletArg = baseNixletArg // {inherit project;};
in in
builtins.addErrorContext "[nixlets] while evaluating nixlet ${name}" (
kubenix.evalModules.${system} { kubenix.evalModules.${system} {
module = {kubenix, ...}: { module = {
config,
kubenix,
...
}: {
imports = with kubenix.modules; [ imports = with kubenix.modules; [
k8s k8s
helm helm
docker docker
files files
./secretsModule.nix ./secretsModule.nix
(_: let ./nixletModule.nix
finalValues = mkValues "${path}/values.nix" { (let
finalValues =
(evalValues "${path}/values.nix" {
rawValues = values; rawValues = values;
nixlet = nixletArg; inherit (config.nixlet) dependencies;
}; args.nixlet = nixletArg;
}).config;
in { in {
imports = [path]; imports = [path];
_module.args.nixlet = _module.args = {
nixlet =
{ {
values = finalValues; values = finalValues;
} }
// nixletArg; // nixletArg;
inherit nixlet-lib system;
};
}) })
overrides overrides
]; ];
kubenix.project = project; kubenix.project = project;
}; };
}; }
);
render = { render = {
system, system,
project ? defaultProject, project ? defaultProject,
@ -133,8 +202,8 @@ with lib; rec {
exit 1 exit 1
fi fi
'' ''
+ lib.concatStringsSep "\n" ( + concatMapStringsSep "\n"
builtins.map (nixlet: (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
@ -148,9 +217,10 @@ with lib; rec {
fi fi
'') '')
nixlets nixlets
)
); );
mkDocs = opts: mkDocs = opts:
import ./valuesDocs.nix (opts // {inherit lib;}); import ./valuesDocs.nix (opts // {inherit lib;});
} };
in
nixlet-lib

6
lib/flake.lock generated
View file

@ -41,11 +41,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1772173633, "lastModified": 1777641297,
"narHash": "sha256-MOH58F4AIbCkh6qlQcwMycyk5SWvsqnS/TCfnqDlpj4=", "narHash": "sha256-WNGcmeOZ8Tr9dq6ztCspYbzWFswr2mPebM9LpsfGxPk=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "c0f3d81a7ddbc2b1332be0d8481a672b4f6004d6", "rev": "c6d65881c5624c9cae5ea6cedef24699b0c0a4c0",
"type": "github" "type": "github"
}, },
"original": { "original": {

75
lib/nixletModule.nix Normal file
View file

@ -0,0 +1,75 @@
{
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));
};
}

View file

@ -1,6 +1,8 @@
{ {
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,
@ -13,7 +15,12 @@
mapAttrsToList mapAttrsToList
concatStrings concatStrings
replicate replicate
optionalString
optionAttrSetToDocList
attrByPath
generators
; ;
inherit (generators) toPretty;
_transformOptions = opt: _transformOptions = opt:
transformOptions (opt transformOptions (opt
@ -25,7 +32,12 @@
name = lib.removePrefix "config." opt.name; name = lib.removePrefix "config." opt.name;
}); });
rawOpts = lib.optionAttrSetToDocList nixlet.values.options; valueSource =
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;
@ -58,7 +70,20 @@
${opt.type} ${opt.type}
``` ```
'' ''
+ (lib.optionalString (opt ? default && opt.default != null) '' # used to show what changes a nixlet did to values of dependencies
+ (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**:
@ -66,7 +91,7 @@
${removeSuffix "\n" opt.default.text} ${removeSuffix "\n" opt.default.text}
``` ```
'') '')
+ (lib.optionalString (opt ? example) '' + (optionalString (opt ? example) ''
**Example value**: **Example value**:

View file

@ -3,27 +3,67 @@
inputs, inputs,
... ...
}: let }: let
inherit (inputs) pkgs devshell treefmt; inherit (inputs) pkgs devshell treefmt devtools-lib;
inherit (cell) soonix; inherit (cell) soonix;
in { treefmtWrapper = treefmt.mkWrapper pkgs {
default = devshell.mkShell { projectRootFile = "flake.nix";
imports = [soonix.devshellModule];
packages = [
pkgs.nil
(treefmt.mkWrapper pkgs {
programs = { programs = {
alejandra.enable = true; alejandra.enable = true;
deadnix.enable = true; deadnix.enable = true;
statix.enable = true; statix.enable = true;
mdformat.enable = true; mdformat.enable = true;
}; };
settings.formatter.mdformat.command = let settings.formatter.mdformat = {
excludes = ["CHANGELOG.md"];
command = let
pkg = pkgs.python3.withPackages (p: [ pkg = pkgs.python3.withPackages (p: [
p.mdformat p.mdformat
p.mdformat-mkdocs p.mdformat-mkdocs
]); ]);
in "${pkg}/bin/mdformat"; in "${pkg}/bin/mdformat";
}) };
};
in {
default = devshell.mkShell {
imports = [soonix.devshellModule devtools-lib.devshellModule];
packages = [
pkgs.nil
treefmtWrapper
];
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";
};
};
};
} }

View file

@ -3,8 +3,22 @@
cell, cell,
... ...
}: let }: let
inherit (inputs) doclib; inherit (inputs) pkgs doclib nixlet-lib;
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" = {
@ -23,9 +37,13 @@ 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 {};}) (builtins.attrValues nixlets); files."Nixlets Values" = builtins.map (val: {${val.name} = val.mkDocs {fullValues = true;};}) (builtins.attrValues nixlets);
}; };
config = { config = {
site_name = "Nixlets"; site_name = "Nixlets";
@ -43,8 +61,10 @@ 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 = [
{ {

53
nix/repo/flake.lock generated
View file

@ -3,20 +3,39 @@
"devshell-lib": { "devshell-lib": {
"locked": { "locked": {
"dir": "lib", "dir": "lib",
"lastModified": 1767274074, "lastModified": 1767218348,
"narHash": "sha256-h2grM9qoSnYdqN7K8+taeMuWC2umaN/c2FCBu48frlo=", "narHash": "sha256-8MJqwH9sRMuHH+RsB7iqWyWD30TgmpiYKEvegAULggs=",
"owner": "rensa-nix", "owner": "rensa-nix",
"repo": "devshell", "repo": "devshell",
"rev": "5508ced269ee40ff7f5261ee3b5bf5597f7cad5d", "rev": "7a9b7e5d9f162a1fa3edfdc0169cdc29d3a67f8e",
"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",
@ -38,16 +57,17 @@
"nixmkdocs-lib": { "nixmkdocs-lib": {
"locked": { "locked": {
"dir": "lib", "dir": "lib",
"lastModified": 1771673823, "lastModified": 1767549915,
"narHash": "sha256-1WFFaQZDPdTX1vL9BP+myIcgZjwvfxSUMGnUTrFmgVc=", "narHash": "sha256-by3r2qddlyzylup5fzSaDwtoy3eFHNKb65IuIq6bsAs=",
"owner": "TECHNOFAB", "owner": "TECHNOFAB",
"repo": "nixmkdocs", "repo": "nixmkdocs",
"rev": "deebf3dae19776200f9ef016ef6542bf9e17be8d", "rev": "f3b2f4b19178e97c5580367be0f97e61a085db6d",
"type": "gitlab" "type": "gitlab"
}, },
"original": { "original": {
"dir": "lib", "dir": "lib",
"owner": "TECHNOFAB", "owner": "TECHNOFAB",
"ref": "v1.1.0",
"repo": "nixmkdocs", "repo": "nixmkdocs",
"type": "gitlab" "type": "gitlab"
} }
@ -55,16 +75,17 @@
"nixtest-lib": { "nixtest-lib": {
"locked": { "locked": {
"dir": "lib", "dir": "lib",
"lastModified": 1769441055, "lastModified": 1775133683,
"narHash": "sha256-SrHLnM3UMzpj5/o52yf3lFOVpsIGEU5nAFUkdeJO1bM=", "narHash": "sha256-06jKKes7NjBQClKXTZTmo7GiGJhe1j5ZMW6jle8Vr1o=",
"owner": "TECHNOFAB", "owner": "TECHNOFAB",
"repo": "nixtest", "repo": "nixtest",
"rev": "9f9fcb85349003edb554574d0e3f623811866f50", "rev": "143921cad9e6076700a45cdb7ff47c91f9801225",
"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"
} }
@ -72,6 +93,7 @@
"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",
@ -82,16 +104,17 @@
"soonix-lib": { "soonix-lib": {
"locked": { "locked": {
"dir": "lib", "dir": "lib",
"lastModified": 1769607658, "lastModified": 1767647496,
"narHash": "sha256-gF9/QmmaNRgqkC5cqSGgwWvGXj9Mj4qMDkvvF/5BlSA=", "narHash": "sha256-1kvCEp7PJnKTcnAjN+Me6swiygeMgJInsZsRQ5bdpH8=",
"owner": "TECHNOFAB", "owner": "TECHNOFAB",
"repo": "soonix", "repo": "soonix",
"rev": "19a88a0c2681bbc85bc2cbe4f2860316d50fe957", "rev": "5e479f3662db1c338679cdb3fd080cf06e4c67d4",
"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"
} }
@ -99,11 +122,11 @@
"treefmt-nix": { "treefmt-nix": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1770228511, "lastModified": 1769691507,
"narHash": "sha256-wQ6NJSuFqAEmIg2VMnLdCnUc0b7vslUohqqGGD+Fyxk=", "narHash": "sha256-8aAYwyVzSSwIhP2glDhw/G0i5+wOrren3v6WmxkVonM=",
"owner": "numtide", "owner": "numtide",
"repo": "treefmt-nix", "repo": "treefmt-nix",
"rev": "337a4fe074be1042a35086f15481d763b8ddc0e7", "rev": "28b19c5844cc6e2257801d43f2772a4b4c050a1b",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -1,9 +1,10 @@
{ {
inputs = { inputs = {
devshell-lib.url = "gitlab:rensa-nix/devshell?dir=lib"; devshell-lib.url = "gitlab:rensa-nix/devshell/v0.1.0?dir=lib";
nixtest-lib.url = "gitlab:TECHNOFAB/nixtest?dir=lib"; devtools-lib.url = "gitlab:rensa-nix/devtools/v0.1.0?dir=lib";
soonix-lib.url = "gitlab:TECHNOFAB/soonix?dir=lib"; nixtest-lib.url = "gitlab:TECHNOFAB/nixtest/v1.3.0?dir=lib";
nixmkdocs-lib.url = "gitlab:TECHNOFAB/nixmkdocs?dir=lib"; soonix-lib.url = "gitlab:TECHNOFAB/soonix/v0.1.0?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 Normal file
View file

@ -0,0 +1,3 @@
{nixlet-lib, ...}: {
config.nixlet.dependencies."example" = nixlet-lib.mkNixlet ../example;
}

6
tests/fixtures/dependency/nixlet.nix vendored Normal file
View file

@ -0,0 +1,6 @@
{
name = "dep";
version = "0.0.1";
description = "hello world";
defaultProject = "dep";
}

5
tests/fixtures/dependency/values.nix vendored Normal file
View file

@ -0,0 +1,5 @@
_: {
options = {};
config."example".example = "Hello dependency!";
}

4
tests/fixtures/example/default.nix vendored Normal file
View file

@ -0,0 +1,4 @@
{nixlet, ...}:
with nixlet; {
kubernetes.resources.configMaps."test".data."test" = values.example;
}

View file

@ -3,11 +3,14 @@
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";
@ -42,6 +45,27 @@
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";
}
]; ];
}; };
} }