You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
synopsis: "Add `nix_plugin_entry` entry point for plugins"
3
+
issues: [fj#740, fj#359]
4
+
prs: [gh#8699]
5
+
cls: [2826]
6
+
category: Development
7
+
credits: ["jade", "yorickvp"]
8
+
---
9
+
10
+
Plugins are an exceptionally rarely used feature in Lix, but they are important as a prototyping tool for code destined for Lix itself, and we want to keep supporting them as a low-maintenance-cost feature.
11
+
As part of the overall move towards getting rid of static initializers for stability and predictability reasons, we added an explicit `nix_plugin_entry` function like CppNix has, which is called immediately after plugin load, if present.
12
+
This makes control flow more explicit and allows for easily registering things that have had their static initializer registration classes removed.
Copy file name to clipboardExpand all lines: lix/libstore/settings/plugin-files.md
+28-21Lines changed: 28 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,24 +4,31 @@ internalName: pluginFiles
4
4
settingType: PluginFilesSetting
5
5
default: []
6
6
---
7
-
A list of plugin files to be loaded by Nix. Each of these files will
8
-
be dlopened by Nix, allowing them to affect execution through static
9
-
initialization. In particular, these plugins may construct static
10
-
instances of RegisterPrimOp to add new primops or constants to the
11
-
expression language, RegisterStoreImplementation to add new store
12
-
implementations, RegisterCommand to add new subcommands to the `nix`
13
-
command, and RegisterSetting to add new nix config settings. See the
14
-
constructors for those types for more details.
15
-
16
-
Warning! These APIs are inherently unstable and may change from
17
-
release to release.
18
-
19
-
Since these files are loaded into the same address space as Nix
20
-
itself, they must be DSOs compatible with the instance of Nix
21
-
running at the time (i.e. compiled against the same headers, not
22
-
linked to any incompatible libraries). They should not be linked to
23
-
any Lix libs directly, as those will be available already at load
24
-
time.
25
-
26
-
If an entry in the list is a directory, all files in the directory
27
-
are loaded as plugins (non-recursively).
7
+
A list of plugin files to be loaded by Lix.
8
+
9
+
Each of these files will be `dlopen`ed by Lix, allowing them to affect execution by registering various entities in Lix.
10
+
After the plugins are loaded, they will have the function within them with signature `extern "C" void nix_plugin_entry(void)` called if it is defined.
11
+
12
+
If an entry in the list is a directory, all files in the directory are loaded as plugins (non-recursively).
13
+
14
+
FIXME(jade): We should provide a `nix_plugin_finalize()` that gets called at some point in teardown for use cases like nix-otel which need to be able to cleanup, flush things to network, etc, on exit without having to do that from life-after-main().
15
+
16
+
In particular, these plugins may:
17
+
- Construct static instances of `RegisterPrimOp` to add new primops or constants to the expression language (FIXME: will be replaced with an explicit function).
18
+
- Add new store implementations with `StoreImplementations::add`.
19
+
- Construct static instances of `RegisterCommand` to add new subcommands to the `nix` command (FIXME: will be replaced with an explicit function).
20
+
- Construct static instances of `Setting` to add new Lix settings (FIXME: will be replaced with an explicit function).
21
+
22
+
See the documentation for those symbols for more details.
23
+
Note all the FIXMEs above: Lix is removing its usages of static initializers, see <https://git.lix.systems/lix-project/lix/issues/359>.
24
+
25
+
Warning! These APIs are inherently unstable and may change in minor versions.
26
+
It's recommended to, if you *are* relying on Lix's unstable C++ API, develop against Lix `main`, run `main` yourself, and be active in Lix development.
27
+
28
+
Since these files are loaded into the same address space as Lix itself, they must be DSOs compatible with the instance of Lix running at the time (i.e. compiled against the same headers, not linked to any incompatible libraries, produced by the same nixpkgs).
29
+
30
+
It's recommended that this setting *not* be used in `nix.conf` since it is almost always the case that there are multiple versions of the Nix implementation on a machine.
31
+
In particular, CppNix (still true in 2.26 as of this writing) considers plugin load failure to be a hard error unlike Lix (since pre-2.90), which means that putting `plugin-files` in `nix.conf` causes random `nix` execution failures.
32
+
Prefer instead to wrap the `nix` command using either the `NIX_CONFIG` environment variable or `--option plugin-files`.
33
+
34
+
Plugins should not be linked to any Lix libs directly, as those will be available already at load time (FIXME: is it an actual problem if they are, assuming that there are not version mismatches?).
0 commit comments