Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

wlib.wrapperModules.niri

wrapperModules/n/niri

This module is made possible by: Patrick Widmer

"config.kdl"

Configuration file for Niri. See https://github.com/YaLTeR/niri/wiki/Configuration:-Introduction

Type: submodule

Default:

{
  path = <derivation niri.kdl>;
}

Example:

''
  input {
    keyboard {
        numlock
    }
  
    touchpad {
        tap
        natural-scroll
    }
  
    focus-follows-mouse = {
      _attrs = { max-scroll-amount = "0%"; };
    };
  }
''

Declared by:

"config.kdl".content

Content of the file. This can be a multi-line string that will be written to the Nix store and made available via the path option.

Type: strings concatenated with “\n”

Declared by:

"config.kdl".path

The path to the file. By default, this is automatically generated using pkgs.writeText with the attribute name and content.

Type: str|path|drv

Default:

pkgs.writeText name <content>

Declared by:

settings

Niri configuration settings. See https://yalter.github.io/niri/Configuration%3A-Introduction.html

Type: open submodule of (attribute set)

Default:

{ }

Declared by:

settings.binds

Bindings of niri

Type: attribute set

Default:

{ }

Example:

{
  "Mod+0" = {
    focus-workspace = 0;
  };
  "Mod+Escape" = {
    _attrs = {
      allow-inhibiting = false;
    };
    toggle-keyboard-shortcuts-inhibit = null;
  };
  "Mod+J" = {
    focus-column-or-monitor-left = null;
  };
  "Mod+N" = {
    spawn = [
      "alacritty"
      "msg"
      "create-windown"
    ];
  };
  "Mod+T" = {
    spawn-sh = "alacritty";
  };
}

Declared by:

settings.extraConfig

Escape hatch string option added to the config file for options that might not be representable otherwise

Type: string

Default:

""

Declared by:

settings.layer-rules

List of layer rules

Type: list of (attribute set)

Default:

[ ]

Example:

[
  {
    block-out-from = "screen-capture";
    matches = [
      {
        namespace = "^notifications$";
      }
    ];
    opacity = 0.8;
  }
]

Declared by:

settings.layout

Layout definitions

Type: attribute set

Default:

{ }

Example:

{
  border = {
    active-color = "#f5c2e7";
    inactive-color = "#313244";
    width = 3;
  };
  focus-ring = {
    off = null;
  };
}

Declared by:

settings.outputs

Output configuration

Type: attribute set

Default:

{ }

Example:

{
  DP-3 = {
    background-color = "#003300";
    hot-corners = {
      off = null;
    };
  };
}

Declared by:

settings.spawn-at-startup

List of commands to run at startup. The first element in a passed list will be run with the following elements as arguments

Type: list of (string or list of string)

Default:

[ ]

Example:

[
  "hello"
  [
    "nix"
    "build"
  ]
]

Declared by:

settings.window-rules

List of window rules

Type: list of (attribute set)

Default:

[ ]

Example:

[
  {
    excludes = [
      {
        app-id = "org.keepassxc.KeePassXC";
      }
    ];
    matches = [
      {
        app-id = ".*";
      }
    ];
    open-floating = false;
    open-focused = false;
  }
]

Declared by:

settings.workspaces

Named workspace definitons

Type: attribute set of (null or anything)

Default:

{ }

Example:

{
  bar = null;
  foo = {
    open-on-output = "DP-3";
  };
}

Declared by:

modules/symlinkScript

Adds extra options compared to the default builderFunction option value.

Imported by wlib.modules.default


aliases

Aliases for the package to also be added to the PATH

Type: list of string

Default:

[ ]

Declared by:

filesToExclude

List of file paths (glob patterns) relative to package root to exclude from the wrapped package. This allows filtering out unwanted binaries or files. Example: [ "bin/unwanted-tool" "share/applications/*.desktop" ]

Type: list of string

Default:

[ ]

Declared by:

filesToPatch

List of file paths (glob patterns) relative to package root to patch for self-references. Desktop files are patched by default to update Exec= and Icon= paths.

Type: list of string

Default:

[
  "share/applications/*.desktop"
]

Declared by:

modules/makeWrapper

An implementation of the makeWrapper interface via type safe module options.

Allows you to choose one of several underlying implementations of the makeWrapper interface.

Imported by wlib.modules.default

Wherever the type includes DAG you can mentally substitute this with attrsOf

Wherever the type includes DAL or DAG list you can mentally substitute this with listOf

However they also take items of the form { data, name ? null, before ? [], after ? [] }

This allows you to specify that values are added to the wrapper before or after another value.

The sorting occurs across ALL the options, thus you can target items in any DAG or DAL within this module from any other DAG or DAL option within this module.

The DAG/DAL entries in this module also accept an extra field, esc-fn ? null

If defined, it will be used instead of the value of options.escapingFunction to escape that value.

It also has a set of submodule options under config.wrapperVariants which allow you to duplicate the effects to other binaries from the package, or add extra ones.

Each one contains an enable option, and a mirror option.

They also contain the same options the top level module does, however if mirror is true, as it is by default, then they will inherit the defaults from the top level as well.

They also have their own package, exePath, and binName options, with sensible defaults.


addFlag

Wrapper for

–add-flag ARG

Prepend the single argument ARG to the invocation of the executable, before any command-line arguments.

This option takes a list. To group them more strongly, option may take a list of lists as well.

Any entry can instead be of type { data, name ? null, before ? [], after ? [], esc-fn ? null }

This will cause it to be added to the DAG.

If no name is provided, it cannot be targeted.

Type: list of spec with main field: data of (str|path|drv or list of str|path|drv)

Default:

[ ]

Example:

[
  "-v"
  "-f"
  [
    "--config"
    ./storePath.cfg
  ]
  [
    "-s"
    "idk"
  ]
]

Declared by:

addFlag.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

appendFlag

–append-flag ARG

Append the single argument ARG to the invocation of the executable, after any command-line arguments.

This option takes a list. To group them more strongly, option may take a list of lists as well.

Any entry can instead be of type { data, name ? null, before ? [], after ? [], esc-fn ? null }

This will cause it to be added to the DAG.

If no name is provided, it cannot be targeted.

Type: list of spec with main field: data of (str|path|drv or list of str|path|drv)

Default:

[ ]

Example:

[
  "-v"
  "-f"
  [
    "--config"
    ./storePath.cfg
  ]
  [
    "-s"
    "idk"
  ]
]

Declared by:

appendFlag.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

argv0

–argv0 NAME

Set the name of the executed process to NAME. If unset or null, defaults to EXECUTABLE.

overrides the setting from argv0type if set.

Type: null or string

Default:

null

Declared by:

argv0type

argv0 overrides this option if not null or unset

Both shell and the nix implementations ignore this option, as the shell always resolves $0

However, the binary implementation will use this option

Values:

  • "inherit":

The executable inherits argv0 from the wrapper. Use instead of --argv0 '$0'.

  • "resolve":

If argv0 does not include a “/” character, resolve it against PATH.

  • Function form: str -> str

This one works only in the nix implementation. The others will treat it as inherit

Rather than calling exec, you get the command plus all its flags supplied, and you can choose how to run it.

e.g. command_string: "eval \"$(${command_string})\";

It will also be added to the end of the overall DAL, with the name NIX_RUN_MAIN_PACKAGE

Thus, you can make things run after it, but by default it is still last.

Type: one of “resolve”, “inherit” or function that evaluates to a(n) string

Default:

"inherit"

Declared by:

chdir

–chdir DIR

Change working directory before running the executable. Use instead of --run "cd DIR".

Type: list of spec with main field: data of str|path|drv

Default:

[ ]

Declared by:

chdir.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

env

Environment variables to set in the wrapper.

This option takes a set.

Any entry can instead be of type { data, before ? [], after ? [], esc-fn ? null }

This will cause it to be added to the DAG, which will cause the resulting wrapper argument to be sorted accordingly

Type: attribute set of spec with main field: data of str|path|drv

Default:

{ }

Example:

{
  XDG_DATA_HOME = "/somewhere/on/your/machine";
}

Declared by:

env.<name>.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

envDefault

Environment variables to set in the wrapper.

Like env, but only adds the variable if not already set in the environment.

This option takes a set.

Any entry can instead be of type { data, before ? [], after ? [], esc-fn ? null }

This will cause it to be added to the DAG, which will cause the resulting wrapper argument to be sorted accordingly

Type: attribute set of spec with main field: data of str|path|drv

Default:

{ }

Example:

{
  XDG_DATA_HOME = "/only/if/not/set";
}

Declared by:

envDefault.<name>.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

escapingFunction

The function to use to escape shell values

Caution: When using shell or binary implementations, these will be expanded at BUILD time.

You should probably leave this as is when using either of those implementations.

However, when using the nix implementation, they will expand at runtime! Which means wlib.escapeShellArgWithEnv may prove to be a useful substitute!

Type: function that evaluates to a(n) string

Default:

lib.escapeShellArg

Declared by:

extraPackages

Additional packages to add to the wrapper’s runtime PATH. This is useful if the wrapped program needs additional libraries or tools to function correctly.

Adds all its entries to the DAG under the name NIX_PATH_ADDITIONS

Type: list of package

Default:

[ ]

Declared by:

flagSeparator

Separator between flag names and values when generating args from flags. " " for --flag value or "=" for --flag=value

Type: string

Default:

" "

Declared by:

flags

Flags to pass to the wrapper. The key is the flag name, the value is the flag value. If the value is true, the flag will be passed without a value. If the value is false or null, the flag will not be passed. If the value is a list, the flag will be passed multiple times with each value.

This option takes a set.

Any entry can instead be of type { data, before ? [], after ? [], esc-fn ? null, sep ? null }

The sep field may be used to override the value of config.flagSeparator

This will cause it to be added to the DAG, which will cause the resulting wrapper argument to be sorted accordingly

Type: attribute set of spec with main field: data of (null or boolean or str|path|drv or list of str|path|drv)

Default:

{ }

Example:

{
  "--config" = ./nixPath;
}

Declared by:

flags.<name>.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

flags.<name>.sep

A per-item override of the default separator used for flags and their values

Type: null or string

Default:

null

Declared by:

prefixContent

[
  [ "ENV" "SEP" "FILE" ]
]

Prefix ENV with contents of FILE and SEP at build time.

Also accepts sets like the other options

[
  [ "ENV" "SEP" "FILE" ]
  { data = [ "ENV" "SEP" "FILE" ]; esc-fn = lib.escapeShellArg; /* name, before, after */ }
]

Type: list of spec with main field: data of (List of length 3)

Default:

[ ]

Declared by:

prefixContent.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

prefixVar

–prefix ENV SEP VAL

Prefix ENV with VAL, separated by SEP.

Type: list of spec with main field: data of (List of length 3)

Default:

[ ]

Example:

[
  [
    "LD_LIBRARY_PATH"
    ":"
    "${lib.makeLibraryPath (with pkgs; [ ... ])}"
  ]
  [
    "PATH"
    ":"
    "${lib.makeBinPath (with pkgs; [ ... ])}"
  ]
]

Declared by:

prefixVar.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

runShell

–run COMMAND

Run COMMAND before executing the main program.

This option takes a list.

Any entry can instead be of type { data, name ? null, before ? [], after ? [], esc-fn ? null }

This will cause it to be added to the DAG.

If no name is provided, it cannot be targeted.

Type: list of spec with main field: data of str|path|drv

Default:

[ ]

Declared by:

runShell.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

runtimeLibraries

Additional libraries to add to the wrapper’s runtime LD_LIBRARY_PATH. This is useful if the wrapped program needs additional libraries or tools to function correctly.

Adds all its entries to the DAG under the name NIX_LIB_ADDITIONS

Type: list of package

Default:

[ ]

Declared by:

suffixContent

[
  [ "ENV" "SEP" "FILE" ]
]

Suffix ENV with SEP and then the contents of FILE at build time.

Also accepts sets like the other options

[
  [ "ENV" "SEP" "FILE" ]
  { data = [ "ENV" "SEP" "FILE" ]; esc-fn = lib.escapeShellArg; /* name, before, after */ }
]

Type: list of spec with main field: data of (List of length 3)

Default:

[ ]

Declared by:

suffixContent.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

suffixVar

–suffix ENV SEP VAL

Suffix ENV with VAL, separated by SEP.

Type: list of spec with main field: data of (List of length 3)

Default:

[ ]

Example:

[
  [
    "LD_LIBRARY_PATH"
    ":"
    "${lib.makeLibraryPath (with pkgs; [ ... ])}"
  ]
  [
    "PATH"
    ":"
    "${lib.makeBinPath (with pkgs; [ ... ])}"
  ]
]

Declared by:

suffixVar.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

unsetVar

–unset VAR

Remove VAR from the environment.

Type: list of spec with main field: data of string

Default:

[ ]

Declared by:

unsetVar.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

wrapperImplementation

the nix implementation is the default

It makes the escapingFunction most relevant.

This is because the shell and binary implementations use pkgs.makeWrapper or pkgs.makeBinaryWrapper, and arguments to these functions are passed at BUILD time.

So, generally, when not using the nix implementation, you should always prefer to have escapingFunction set to lib.escapeShellArg.

However, if you ARE using the nix implementation, using wlib.escapeShellArgWithEnv will allow you to use $ expansions, which will expand at runtime.

binary implementation is useful for programs which are likely to be used in “shebangs”, as macos will not allow scripts to be used for these.

However, it is more limited. It does not have access to runShell, prefixContent, and suffixContent options.

Chosing binary will thus cause values in those options to be ignored.

Type: one of “nix”, “shell”, “binary”

Default:

"nix"

Declared by:

wrapperVariants

Allows for you to apply the wrapper options to multiple binaries from config.package (or elsewhere)

They are called variants because they are the same options as the top level makeWrapper options, however, their defaults mirror the values of the top level options.

Meaning if you set config.env.MYVAR = "HELLO" at the top level, then the following statement would be true by default:

config.wrapperVariants.foo.env.MYVAR.data == "HELLO"

They achieve this by receiving mainConfig and mainOpts via specialArgs, which contain config and options from the top level.

Type: attribute set of (submodule)

Default:

{ }

Declared by:

wrapperVariants.<name>.addFlag

Wrapper for

–add-flag ARG

Prepend the single argument ARG to the invocation of the executable, before any command-line arguments.

This option takes a list. To group them more strongly, option may take a list of lists as well.

Any entry can instead be of type { data, name ? null, before ? [], after ? [], esc-fn ? null }

This will cause it to be added to the DAG.

If no name is provided, it cannot be targeted.

Type: list of spec with main field: data of (str|path|drv or list of str|path|drv)

Default:

[ ]

Example:

[
  "-v"
  "-f"
  [
    "--config"
    ./storePath.cfg
  ]
  [
    "-s"
    "idk"
  ]
]

Declared by:

wrapperVariants.<name>.addFlag.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

wrapperVariants.<name>.appendFlag

–append-flag ARG

Append the single argument ARG to the invocation of the executable, after any command-line arguments.

This option takes a list. To group them more strongly, option may take a list of lists as well.

Any entry can instead be of type { data, name ? null, before ? [], after ? [], esc-fn ? null }

This will cause it to be added to the DAG.

If no name is provided, it cannot be targeted.

Type: list of spec with main field: data of (str|path|drv or list of str|path|drv)

Default:

[ ]

Example:

[
  "-v"
  "-f"
  [
    "--config"
    ./storePath.cfg
  ]
  [
    "-s"
    "idk"
  ]
]

Declared by:

wrapperVariants.<name>.appendFlag.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

wrapperVariants.<name>.argv0

–argv0 NAME

Set the name of the executed process to NAME. If unset or null, defaults to EXECUTABLE.

overrides the setting from argv0type if set.

Type: null or string

Default:

null

Declared by:

wrapperVariants.<name>.argv0type

argv0 overrides this option if not null or unset

Both shell and the nix implementations ignore this option, as the shell always resolves $0

However, the binary implementation will use this option

Values:

  • "inherit":

The executable inherits argv0 from the wrapper. Use instead of --argv0 '$0'.

  • "resolve":

If argv0 does not include a “/” character, resolve it against PATH.

  • Function form: str -> str

This one works only in the nix implementation. The others will treat it as inherit

Rather than calling exec, you get the command plus all its flags supplied, and you can choose how to run it.

e.g. command_string: "eval \"$(${command_string})\";

It will also be added to the end of the overall DAL, with the name NIX_RUN_MAIN_PACKAGE

Thus, you can make things run after it, but by default it is still last.

Type: one of “resolve”, “inherit” or function that evaluates to a(n) string

Default:

"inherit"

Declared by:

wrapperVariants.<name>.binName

The name of the file to output to $out/bin/

Type: non-empty line

Default:

"‹name›"

Declared by:

wrapperVariants.<name>.chdir

–chdir DIR

Change working directory before running the executable. Use instead of --run "cd DIR".

Type: list of spec with main field: data of str|path|drv

Default:

[ ]

Declared by:

wrapperVariants.<name>.chdir.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

wrapperVariants.<name>.enable

Enables the wrapping of this variant

Type: boolean

Default:

true

Declared by:

wrapperVariants.<name>.env

Environment variables to set in the wrapper.

This option takes a set.

Any entry can instead be of type { data, before ? [], after ? [], esc-fn ? null }

This will cause it to be added to the DAG, which will cause the resulting wrapper argument to be sorted accordingly

Type: attribute set of spec with main field: data of str|path|drv

Default:

{
  NIRI_CONFIG = {
    after = [ ];
    before = [ ];
    data = "/nix/store/nzrj6dzcnr0rkp0x7pvs0f0xzfmqpm83-niri.kdl";
    esc-fn = null;
    name = null;
  };
}

Example:

{
  XDG_DATA_HOME = "/somewhere/on/your/machine";
}

Declared by:

wrapperVariants.<name>.env.<name>.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

wrapperVariants.<name>.envDefault

Environment variables to set in the wrapper.

Like env, but only adds the variable if not already set in the environment.

This option takes a set.

Any entry can instead be of type { data, before ? [], after ? [], esc-fn ? null }

This will cause it to be added to the DAG, which will cause the resulting wrapper argument to be sorted accordingly

Type: attribute set of spec with main field: data of str|path|drv

Default:

{ }

Example:

{
  XDG_DATA_HOME = "/only/if/not/set";
}

Declared by:

wrapperVariants.<name>.envDefault.<name>.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

wrapperVariants.<name>.escapingFunction

The function to use to escape shell values

Caution: When using shell or binary implementations, these will be expanded at BUILD time.

You should probably leave this as is when using either of those implementations.

However, when using the nix implementation, they will expand at runtime! Which means wlib.escapeShellArgWithEnv may prove to be a useful substitute!

Type: function that evaluates to a(n) string

Default:

lib.escapeShellArg

Declared by:

wrapperVariants.<name>.exePath

The location within the package of the thing to wrap.

Type: null or non-empty line

Default:

"bin/‹name›"

Declared by:

wrapperVariants.<name>.extraPackages

Additional packages to add to the wrapper’s runtime PATH. This is useful if the wrapped program needs additional libraries or tools to function correctly.

Adds all its entries to the DAG under the name NIX_PATH_ADDITIONS

Type: list of package

Default:

[ ]

Declared by:

wrapperVariants.<name>.flagSeparator

Separator between flag names and values when generating args from flags. " " for --flag value or "=" for --flag=value

Type: string

Default:

" "

Declared by:

wrapperVariants.<name>.flags

Flags to pass to the wrapper. The key is the flag name, the value is the flag value. If the value is true, the flag will be passed without a value. If the value is false or null, the flag will not be passed. If the value is a list, the flag will be passed multiple times with each value.

This option takes a set.

Any entry can instead be of type { data, before ? [], after ? [], esc-fn ? null, sep ? null }

The sep field may be used to override the value of config.flagSeparator

This will cause it to be added to the DAG, which will cause the resulting wrapper argument to be sorted accordingly

Type: attribute set of spec with main field: data of (null or boolean or str|path|drv or list of str|path|drv)

Default:

{ }

Example:

{
  "--config" = ./nixPath;
}

Declared by:

wrapperVariants.<name>.flags.<name>.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

wrapperVariants.<name>.flags.<name>.sep

A per-item override of the default separator used for flags and their values

Type: null or string

Default:

null

Declared by:

wrapperVariants.<name>.mirror

Allows the variant to inherit defaults from the top level

Type: boolean

Default:

true

Declared by:

wrapperVariants.<name>.package

The package to wrap with these options

Type: str|path|drv

Default:

<derivation niri-25.11>

Declared by:

wrapperVariants.<name>.prefixContent

[
  [ "ENV" "SEP" "FILE" ]
]

Prefix ENV with contents of FILE and SEP at build time.

Also accepts sets like the other options

[
  [ "ENV" "SEP" "FILE" ]
  { data = [ "ENV" "SEP" "FILE" ]; esc-fn = lib.escapeShellArg; /* name, before, after */ }
]

Type: list of spec with main field: data of (List of length 3)

Default:

[ ]

Declared by:

wrapperVariants.<name>.prefixContent.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

wrapperVariants.<name>.prefixVar

–prefix ENV SEP VAL

Prefix ENV with VAL, separated by SEP.

Type: list of spec with main field: data of (List of length 3)

Default:

[ ]

Example:

[
  [
    "LD_LIBRARY_PATH"
    ":"
    "${lib.makeLibraryPath (with pkgs; [ ... ])}"
  ]
  [
    "PATH"
    ":"
    "${lib.makeBinPath (with pkgs; [ ... ])}"
  ]
]

Declared by:

wrapperVariants.<name>.prefixVar.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

wrapperVariants.<name>.runShell

–run COMMAND

Run COMMAND before executing the main program.

This option takes a list.

Any entry can instead be of type { data, name ? null, before ? [], after ? [], esc-fn ? null }

This will cause it to be added to the DAG.

If no name is provided, it cannot be targeted.

Type: list of spec with main field: data of str|path|drv

Default:

[ ]

Declared by:

wrapperVariants.<name>.runShell.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

wrapperVariants.<name>.runtimeLibraries

Additional libraries to add to the wrapper’s runtime LD_LIBRARY_PATH. This is useful if the wrapped program needs additional libraries or tools to function correctly.

Adds all its entries to the DAG under the name NIX_LIB_ADDITIONS

Type: list of package

Default:

[ ]

Declared by:

wrapperVariants.<name>.suffixContent

[
  [ "ENV" "SEP" "FILE" ]
]

Suffix ENV with SEP and then the contents of FILE at build time.

Also accepts sets like the other options

[
  [ "ENV" "SEP" "FILE" ]
  { data = [ "ENV" "SEP" "FILE" ]; esc-fn = lib.escapeShellArg; /* name, before, after */ }
]

Type: list of spec with main field: data of (List of length 3)

Default:

[ ]

Declared by:

wrapperVariants.<name>.suffixContent.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

wrapperVariants.<name>.suffixVar

–suffix ENV SEP VAL

Suffix ENV with VAL, separated by SEP.

Type: list of spec with main field: data of (List of length 3)

Default:

[ ]

Example:

[
  [
    "LD_LIBRARY_PATH"
    ":"
    "${lib.makeLibraryPath (with pkgs; [ ... ])}"
  ]
  [
    "PATH"
    ":"
    "${lib.makeBinPath (with pkgs; [ ... ])}"
  ]
]

Declared by:

wrapperVariants.<name>.suffixVar.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

wrapperVariants.<name>.unsetVar

–unset VAR

Remove VAR from the environment.

Type: list of spec with main field: data of string

Default:

[ ]

Declared by:

wrapperVariants.<name>.unsetVar.*.esc-fn

A per-item override of the default string escape function

Type: null or (function that evaluates to a(n) string)

Default:

null

Declared by:

wrapperVariants.<name>.wrapperImplementation

the nix implementation is the default

It makes the escapingFunction most relevant.

This is because the shell and binary implementations use pkgs.makeWrapper or pkgs.makeBinaryWrapper, and arguments to these functions are passed at BUILD time.

So, generally, when not using the nix implementation, you should always prefer to have escapingFunction set to lib.escapeShellArg.

However, if you ARE using the nix implementation, using wlib.escapeShellArgWithEnv will allow you to use $ expansions, which will expand at runtime.

binary implementation is useful for programs which are likely to be used in “shebangs”, as macos will not allow scripts to be used for these.

However, it is more limited. It does not have access to runShell, prefixContent, and suffixContent options.

Chosing binary will thus cause values in those options to be ignored.

Type: one of “nix”, “shell”, “binary”

Default:

"nix"

Declared by:

lib/core.nix

These are the core options that make everything else possible.

They include the .extendModules, .apply, .eval, and .wrap functions, and the .wrapper itself

They are always imported with every module evaluation.

They are somewhat minimal by design. They pertain to building the derivation, not the wrapper script.

The default builderFunction value provides no options.

The default wrapperFunction is null.

wlib.modules.default provides great values for these options, and creates many more for you to use.

But you may want to wrap your package via different means, provide different options, or provide modules for others to use to help do those things!

Doing it this way allows wrapper modules to do anything you might wish involving wrapping some source/package in a derivation.

Excited to see what ways to use these options everyone comes up with! Docker helpers? BubbleWrap? If it’s a derivation, it should be possible!


apply

Function to extend the current configuration with additional modules. Can accept a single module, or a list of modules. Re-evaluates the configuration with the original settings plus the new module(s).

Returns .config from the lib.evalModules result

Type: (read-only) function that evaluates to a(n) raw value

Default:

<function>

Declared by:

binName

The name of the binary output by wrapperFunction to $out/bin

If not specified, the default name from the package will be used.

Type: non-empty line

Default:

"niri"

Declared by:

builderFunction

Outside of importing wlib.modules.symlinkScript module, which is included in wlib.modules.default, This is usually an option you will never have to redefine.

This option takes a function receiving the following arguments:

module arguments + wrapper + pkgs.callPackage

{
  wlib,
  config,
  wrapper,
  ... # <- anything you can get from pkgs.callPackage
}@initialArgs:
"<buildCommand>"

It is in charge of linking wrapper and config.outputs to the final package.

wrapper is the unchecked result of calling wrapperFunction, or null if one was not provided.

  • The function is to return a string which will be added to the buildCommand of the wrapper.

The builtin implementation, and also the wlib.modules.symlinkScript module, accept either a string to prepend to the returned buildCommand string, or a derivation to link with lndir

  • Alternatively, it may return a function which returns a set like:
{ wlib, config, wrapper, ... }@initialArgs:
drvArgs:
drvArgs // {}

If it does this, that function will be given the final computed derivation attributes, and it will be expected to return the final attribute set to be passed to pkgs.stdenv.mkDerivation.

Regardless of if you return a string or function, passthru.wrap, passthru.apply, passthru.eval, passthru.extendModules, passthru.override, passthru.overrideAttrs will be added to the thing you return, and config.sourceStdenv will be handled for you.

However:

  • You can also return a functor with a (required) mkDerivation field.
  { config, stdenv, wrapper, wlib, ... }@initialArgs:
  {
    inherit (stdenv) mkDerivation;
    __functor = {
      mkDerivation,
      __functor,
      defaultPhases, # [ "<all stdenv phases>" ... ]
      setupPhases, # phases: "if [ -z \"${phases[*]:-}\" ]; then phases="etc..."; fi"
      runPhases, # "for curPhase in ${phases[*]}; do runPhase \"$curPhase\"; done"
      ...
    }@self:
    defaultArgs:
    defaultArgs // (if config.sourceStdenv then { } else { buildCommand = ""; }
  }
  • If you do this:
    • You are in control over the entire derivation.
    • This means you need to take care of config.passthru and config.sourceStdenv yourself.
    • The mkDerivation function will be called with the final result of your functor.

As you can see, you are provided with some things to help you via the self argument to your functor.

The generated passthru items mentioned above are given to you as part of what is shown as defaultArgs above

And you are also given some helpers to help you run the phases if needed!

Tip: A functor is a set with a { __functor = self: args: ...; } field. You can call it like a function and it gets passed itself as its first argument!

Type: function that evaluates to a(n) (string or function that evaluates to a(n) attribute set of raw value)

Default:

<function, args: {config, lib, lndir, wlib, wrapper}>

Declared by:

drv

Extra attributes to add to the resulting derivation.

Cannot affect passthru, or outputs. For that, use config.passthru, or config.outputs instead.

Also cannot override buildCommand. That is controlled by the config.builderFunction and config.sourceStdenv options.

Type: attrsRecursive

Default:

{ }

Declared by:

eval

Function to extend the current configuration with additional modules. Can accept a single module, or a list of modules. Re-evaluates the configuration with the original settings plus the new module(s).

Returns the raw lib.evalModules result

Type: (read-only) function that evaluates to a(n) raw value

Default:

<function>

Declared by:

exePath

The relative path to the executable to wrap. i.e. bin/exename

If not specified, the path gained from calling lib.getExe on config.package and subtracting the path to the package will be used.

Type: null or non-empty line

Default:

"bin/niri"

Declared by:

extendModules

Alias for .extendModules so that you can call it from outside of wlib.types.subWrapperModule types

In addition, it is also a set which stores the function args for the module evaluation. This may prove useful when dealing with subWrapperModules or packages, which otherwise would not have access to some of them.

Type: (read-only) function that evaluates to a(n) raw value

Default:

<function, args: {modules?, prefix?, specialArgs?}>

Declared by:

meta.description

Description of the module.

Accepts either a string, or a set of { pre ? "", post ? "" }

Resulting config value will be a list of { pre, post, file }

Type: string or { pre ? “”, post ? “” } (converted to [ { pre, post, file } ])

Default:

""

Declared by:

meta.maintainers

Maintainers of this module.

Type: list of (open submodule of attrsRecursive)

Default:

[ ]

Declared by:

meta.maintainers.*.email

email

Type: null or string

Default:

null

Declared by:

meta.maintainers.*.github

GitHub username

Type: string

Declared by:

meta.maintainers.*.githubId

GitHub id

Type: signed integer

Declared by:

meta.maintainers.*.matrix

Matrix ID

Type: null or string

Default:

null

Declared by:

meta.maintainers.*.name

name

Type: string

Default:

"‹name›"

Declared by:

meta.platforms

Supported platforms

Type: list of strings from enum of lib.platforms.all

Default:

lib.platforms.all

Example:

[
  "x86_64-linux"
  "aarch64-linux"
]

Declared by:

outputs

Override the list of nix outputs that get symlinked into the final package.

Default is config.package.outputs or [ "out" ] if invalid.

Type: non-empty list of string

Default:

[
  "out"
  "doc"
]

Declared by:

overrides

the list of .override and .overrideAttrs to apply to config.package

Accessing config.package will return the package with all overrides applied.

Accepts a list of { data, type ? null, name ? null, before ? [], after ? [] }

If type == null then data must be a function. It will receive and return the package.

If type is a string like override or overrideAttrs, it represents the attribute of config.package to pass the data field to.

If a raw value is given, it will be used as the data field, and type will be null.

config.package = pkgs.mpv;
config.overrides = [
  { # If they don't have a name they cannot be targeted!
    type = "override";
    after = [ "MPV_SCRIPTS" ];
    data = (prev: {
      scripts = (prev.scripts or []) ++ [ pkgs.mpvScripts.visualizer ];
    });
  }
  {
    name = "MPV_SCRIPTS";
    type = "override";
    data = (prev: {
      scripts = (prev.scripts or []) ++ [ pkgs.mpvScripts.modernz ];
    });
  }
  # the default `type` is `null`
  (pkg: pkg.override (prev: {
    scripts = (prev.scripts or []) ++ [ pkgs.mpvScripts.autocrop ];
  }))
  {
    type = null;
    before = [ "MPV_SCRIPTS" ];
    data = (pkg: pkg.override (prev: {
      scripts = (prev.scripts or []) ++ config.scripts;
    }));
  }
  { # It was already after "MPV_SCRIPTS" so this will stay where it is
    type = "overrideAttrs";
    after = [ "MPV_SCRIPTS" ];
    data = prev: {
      name = prev.name + "-wrapped";
    };
  }
];

The above will add config.scripts, then modernz then visualizer and finally autocrop

Then it will add -wrapped to the end of config.package’s name attribute.

The sort will not always put the value directly after the targeted value, it fulfils the requested before or after dependencies and no more.

You can modify the specs!

The type supports type merging, so you may redeclare it in order to add more options or change default values.

{ config, lib, wlib, pkgs, ... }:{
  options.overrides = lib.mkOption {
    type = wlib.types.seriesOf (wlib.types.spec ({ config, ... }: {
      options = {};
      config = {};
    }));
  };
}

Type: series of spec with main field: data of raw value

Default:

[ ]

Declared by:

overrides.*.after

Items that this spec should be ordered after.

Type: list of string

Default:

[ ]

Declared by:

overrides.*.before

Items that this spec should be ordered before.

Type: list of string

Default:

[ ]

Declared by:

overrides.*.data

If type is null, then this is the function to call on the package.

If type is a string, then this is the data to pass to the function corresponding with that attribute.

Type: raw value

Declared by:

overrides.*.name

The name for targeting from the before or after fields of other specs.

If null it cannot be targeted by other specs.

Type: null or string

Default:

null

Declared by:

overrides.*.type

The attribute of config.package to pass the override argument to. If null, then data receives and returns the package instead.

If null, data must be a function. If a string, config.package must have the corresponding attribute, and it must be a function.

Type: null or one of “override”, “overrideAttrs” or string

Default:

null

Declared by:

package

The base package to wrap. This means config.builderFunction will be responsible for inheriting all other files from this package (like man page, /share, …)

The config.package value given by this option already has all values from config.overrides applied to it.

Type: str|path|drv

Declared by:

passthru

Additional attributes to add to the resulting derivation’s passthru. This can be used to add additional metadata or functionality to the wrapped package. Anything added under the attribute name configuration will be ignored, as that value is used internally.

Type: attrsRecursive

Default:

{ }

Declared by:

pkgs

The nixpkgs pkgs instance to use.

Required in order to access .wrapper attribute, either directly, or indirectly.

Type: Nixpkgs package set

Declared by:

sourceStdenv

Run the enabled stdenv phases on the wrapper derivation.

NOTE: often you may prefer to use things like drv.doDist = true;, or even drv.phases = [ ... "buildPhase" etc ... ]; instead, to override this choice in a more fine-grained manner

Type: boolean

Default:

true

Declared by:

wrap

Function to extend the current configuration with additional modules. Can accept a single module, or a list of modules. Re-evaluates the configuration with the original settings plus the new module(s).

Returns the updated package.

Type: (read-only) function that evaluates to a(n) package

Default:

<function>

Declared by:

wrapper

The final wrapped package.

You may still call .eval and the rest on the package again afterwards.

Accessing this value without defining pkgs option, either directly, or via some other means like .wrap, will cause an error.

Type: (read-only) package

Default:

<derivation niri-25.11>

Declared by:

wrapperFunction

Arguments:

This option takes a function receiving the following arguments:

module arguments + pkgs.callPackage

{
  config,
  wlib,
  ... # <- anything you can get from pkgs.callPackage
}

The result of this function is passed DIRECTLY to the value of the builderFunction function.

The relative path to the thing to wrap from within config.package is config.exePath

You should wrap the package and place the wrapper at "$out/bin/${config.binName}"

Type: null or (function that evaluates to a(n) raw value)

Default:

null

Declared by: