Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ci/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions ci/test-lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let
wlib = self.lib;

errMsg = msg: "(echo ${renderMsg msg} >&2 && return 1)";
errMsg = msg: "(echo \"${renderMsg msg}\" >&2 && return 1)";

indentBlock =
str: num:
Expand Down Expand Up @@ -280,10 +280,27 @@ in
msg = "File ${path} should not exist";
};

/**
Returns an `Assertion` that checks whether `path` does **not** exist as a directory.

# Type
```
notIsFile :: String -> Assertion
```

# Arguments
path
: The filesystem path that should be absent.
*/
notIsDirectory = path: {
cond = ''[ ! -d "${path}" ]'';
msg = "Directory ${path} should not exist";
};

/**
Returns an `Assertion` that checks whether `file` contains a line matching `pattern`.

The check is performed with `grep -q`, so `pattern` is treated as a basic regular expression.
The check is performed with `grep -Eq`, so `pattern` is treated as an extended regular expression.

# Type
```
Expand All @@ -295,10 +312,10 @@ in
: Path to the file to search.

pattern
: Basic regular expression to search for.
: Extended regular expression to search for.
*/
fileContains = file: pattern: {
cond = ''grep -q '${pattern}' "${file}"'';
cond = ''grep -Eq -- '${pattern}' "${file}"'';
msg = "Pattern '${pattern}' not found in ${file}";
};

Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,41 @@ in
Like `wlib.types.attrsRecursive`, but uses `lib.types.lazyAttrsOf` instead.
*/
lazyAttrsRecursive = attrsRecursive true;

/**
Creates a value type suitable for serialization formats.

Parameters:
- typeName: String describing the format (e.g. "JSON", "YAML", "XML")
- nullable: Whether the structured value type allows `null` values.
- extraValueTypes: List of extra value types to allow, e.g. "[ lib.types.luaInline ]"

Returns a type suitable for structured data formats that supports:
- Basic types: boolean, integer, float, string, path
- Complex types: attribute sets and lists
- Other user provided value types
*/
structuredValueWith =
{
typeName,
nullable ? true,
extraValueTypes ? [ ],
}:
let
baseType = lib.types.oneOf (
(lib.toList extraValueTypes)
++ [
lib.types.bool
lib.types.int
lib.types.float
wlib.types.stringable
(lib.types.attrsOf valueType)
(lib.types.listOf valueType)
]
);
valueType = (if nullable then lib.types.nullOr baseType else baseType) // {
description = "${typeName} value";
};
in
valueType;
}
8 changes: 4 additions & 4 deletions wrapperModules/a/alacritty/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
pkgs,
...
}:
let
tomlFmt = pkgs.formats.toml { };
in
{
imports = [ wlib.modules.default ];
options = {
settings = lib.mkOption {
type = tomlFmt.type;
type = wlib.types.structuredValueWith {
nullable = false;
typeName = "TOML";
};
default = { };
description = ''
Configuration of alacritty.
Expand Down
9 changes: 6 additions & 3 deletions wrapperModules/a/atuin/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@
...
}:
let
tomlFmt = pkgs.formats.toml { };
tomlFmtType = wlib.types.structuredValueWith {
nullable = false;
typeName = "TOML";
};
in
{
imports = [ wlib.modules.default ];

options = {
settings = lib.mkOption {
type = tomlFmt.type;
type = tomlFmtType;
default = { };
description = ''
Atuin configuration options.
'';
};
server-settings = lib.mkOption {
type = tomlFmt.type;
type = tomlFmtType;
default = { };
description = ''
Atuin server configuration options.
Expand Down
8 changes: 4 additions & 4 deletions wrapperModules/b/bottom/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
pkgs,
...
}:
let
tomlFmt = pkgs.formats.toml { };
in
{
imports = [ wlib.modules.default ];
options = {
settings = lib.mkOption {
type = tomlFmt.type;
type = wlib.types.structuredValueWith {
nullable = false;
typeName = "TOML";
};
default = { };
description = ''
Configuration passed to `btm` using `--config_location` flag.
Expand Down
8 changes: 4 additions & 4 deletions wrapperModules/c/claude-code/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
...
}:
let
jsonFmt = pkgs.formats.json { };
jsonFmtType = wlib.types.structuredValueWith { typeName = "JSON"; };
in
{
imports = [ wlib.modules.default ];

options = {

agents = lib.mkOption {
type = jsonFmt.type;
type = jsonFmtType;
default = { };
description = ''
Custom agents to add to Claude Code.
Expand All @@ -37,7 +37,7 @@ in
};

mcpConfig = lib.mkOption {
type = jsonFmt.type;
type = jsonFmtType;
default = { };
description = ''
MCP Server configuration
Expand Down Expand Up @@ -71,7 +71,7 @@ in
};

settings = lib.mkOption {
type = jsonFmt.type;
type = jsonFmtType;
default = { };
description = ''
Claude Code settings
Expand Down
150 changes: 150 additions & 0 deletions wrapperModules/d/direnv/check.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
pkgs,
self,
tlib,
}:

let
inherit (tlib)
fileContains
isDirectory
isFile
notIsFile
test
;

lib = pkgs.lib;

getDotdir =
wrapper:
let
cfg = (wrapper.eval { }).config;
dotdir = "${wrapper}/${cfg.configDirname}";
in
dotdir;
in
test { wrapper = "direnv"; } {

"direnv wrapper should be created" =
let
wrapper = self.wrappers.direnv.wrap {
inherit pkgs;
nix-direnv.enable = true;
};
in
''
"${wrapper}/bin/direnv" --version | grep -q "${wrapper.version}"
'';

"if nix-direnv is enabled then lib/nix-direnv.sh should exists" =
let
wrapper = self.wrappers.direnv.wrap {
inherit pkgs;
nix-direnv.enable = true;
};
in
[
(isDirectory (getDotdir wrapper))
(isFile "${getDotdir wrapper}/lib/nix-direnv.sh")
];

"if nix-direnv is disabled then lib/nix-direnv.sh should not exist" =
let
wrapper = self.wrappers.direnv.wrap {
inherit pkgs;
nix-direnv.enable = false;
};
in
[
(isDirectory (getDotdir wrapper))
(notIsFile "${getDotdir wrapper}/lib/nix-direnv.sh")
];

"if mise is enabled then lib/mise.sh should exists" =
let
wrapper = self.wrappers.direnv.wrap {
inherit pkgs;
mise.enable = true;
};
in
[
(isDirectory (getDotdir wrapper))
(isFile "${getDotdir wrapper}/lib/mise.sh")
];

"if mise is disabled then lib/mise.sh should not exist" =
let
wrapper = self.wrappers.direnv.wrap {
inherit pkgs;
mise.enable = false;
};
in
[
(isDirectory (getDotdir wrapper))
(notIsFile "${getDotdir wrapper}/lib/mise.sh")
];

"if a lib-script is set then it should be generated" =
let
libScriptFile = "${getDotdir wrapper}/lib/foo.sh";
libScriptContent = "echo foo";
wrapper = self.wrappers.direnv.wrap {
inherit pkgs;
lib."foo.sh" = libScriptContent;
};
in
[
(isDirectory (getDotdir wrapper))
(isFile libScriptFile)
(fileContains libScriptFile libScriptContent)
];

"if silent mode is enabled then log settings should be set" =
let
direnvTomlFile = "${getDotdir wrapper}/direnv.toml";
wrapper = self.wrappers.direnv.wrap {
inherit pkgs;
silent = true;
};
in
[
(isDirectory (getDotdir wrapper))
(isFile direnvTomlFile)
(fileContains direnvTomlFile "log_format")
(fileContains direnvTomlFile "log_filter")

];

"if extraConfig is working" =
let
direnvTomlFile = "${getDotdir wrapper}/direnv.toml";
wrapper = self.wrappers.direnv.wrap {
inherit pkgs;
extraConfig = {
fooSection.fooKey = "fooValue";
};
};
in
[
(isDirectory (getDotdir wrapper))
(isFile direnvTomlFile)
(fileContains direnvTomlFile "\\[fooSection\\]")
(fileContains direnvTomlFile "fooKey.*fooValue")
];

"if direnvrc is working" =
let
direnvrcFile = "${getDotdir wrapper}/direnvrc";
direnvrcContent = "echo foo";

wrapper = self.wrappers.direnv.wrap {
inherit pkgs;
direnvrc = direnvrcContent;
};
in
[
(isDirectory (getDotdir wrapper))
(isFile direnvrcFile)
(fileContains direnvrcFile direnvrcContent)
];
}
Loading