modules/{output,files,test}: move outputs to build scope

Move the following output options into `build`:
- finalPackage -> package
- printInitPackage
- initPath -> initFile
- filesPlugin -> extraFiles
- test.derivation -> test
This commit is contained in:
Matt Sturgeon 2024-09-24 07:02:22 +01:00
parent 7bda0f1ce4
commit 692e39311e
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
14 changed files with 129 additions and 73 deletions

View file

@ -8,6 +8,7 @@
../.
./files
./output.nix
./readonly-renames.nix
./test.nix
];

View file

@ -36,7 +36,7 @@ in
};
};
filesPlugin = lib.mkOption {
build.extraFiles = lib.mkOption {
type = types.package;
description = "A derivation with all the files inside.";
internal = true;
@ -68,7 +68,7 @@ in
# A directory with all the files in it
# Implementation based on NixOS's /etc module
filesPlugin = pkgs.runCommandLocal "nvim-config" { } ''
build.extraFiles = pkgs.runCommandLocal "nvim-config" { } ''
set -euo pipefail
makeEntry() {
@ -91,6 +91,6 @@ in
'';
# Never combine user files with the rest of the plugins
performance.combinePlugins.standalonePlugins = [ config.filesPlugin ];
performance.combinePlugins.standalonePlugins = [ config.build.extraFiles ];
};
}

View file

@ -68,24 +68,31 @@ in
'';
};
finalPackage = mkOption {
type = types.package;
description = "Wrapped Neovim.";
readOnly = true;
};
build = {
# TODO: `standalonePackage`; i.e. package + printInitPackage + man-docs bundled together
initPath = mkOption {
type = types.str;
description = "The path to the `init.lua` file.";
readOnly = true;
visible = false;
};
package = mkOption {
type = types.package;
description = "Wrapped Neovim.";
readOnly = true;
};
printInitPackage = mkOption {
type = types.package;
description = "A tool to show the content of the generated `init.lua` file.";
readOnly = true;
visible = false;
initFile = mkOption {
type = types.path;
description = "The generated `init.lua` file.";
readOnly = true;
visible = false;
};
printInitPackage = mkOption {
type = types.package;
description = ''
A tool to show the content of the generated `init.lua` file.
Run using `${config.build.printInitPackage.meta.mainProgram}`.
'';
readOnly = true;
visible = false;
};
};
};
@ -208,7 +215,7 @@ in
# Combined plugins
combinedPlugins = [ pluginPack ] ++ standaloneStartPlugins ++ optPlugins;
# Plugins to use in finalPackage
# Plugins to use in build.package
plugins = if config.performance.combinePlugins.enable then combinedPlugins else normalizedPlugins;
neovimConfig = pkgs.neovimUtils.makeNeovimConfig (
@ -244,7 +251,7 @@ in
textInit = builders.writeLua "init.lua" customRC;
byteCompiledInit = builders.writeByteCompiledLua "init.lua" customRC;
init =
initFile =
if
config.type == "lua"
&& config.performance.byteCompileLua.enable
@ -258,7 +265,7 @@ in
(optional (
config.extraPackages != [ ]
) ''--prefix PATH : "${lib.makeBinPath config.extraPackages}"'')
++ (optional config.wrapRc ''--add-flags -u --add-flags "${init}"'')
++ (optional config.wrapRc ''--add-flags -u --add-flags "${initFile}"'')
);
package =
@ -291,15 +298,17 @@ in
);
in
{
finalPackage = wrappedNeovim;
initPath = "${init}";
build = {
package = wrappedNeovim;
inherit initFile;
printInitPackage = pkgs.writeShellApplication {
name = "nixvim-print-init";
runtimeInputs = [ pkgs.bat ];
text = ''
bat --language=lua "${textInit}"
'';
printInitPackage = pkgs.writeShellApplication {
name = "nixvim-print-init";
runtimeInputs = [ pkgs.bat ];
text = ''
bat --language=lua "${textInit}"
'';
};
};
# Set `wrapRc` and `impureRtp`s option defaults with even lower priority than `mkOptionDefault`
@ -322,6 +331,6 @@ in
)
);
extraPlugins = lib.mkIf config.wrapRc [ config.filesPlugin ];
extraPlugins = lib.mkIf config.wrapRc [ config.build.extraFiles ];
};
}

View file

@ -0,0 +1,41 @@
{ lib, options, ... }:
let
# Recursively maps an attrset of option-refs into an attrset of option alias declarations.
#
# NOTE: `mkRenameOptionModule` is not appropriate for readOnly options, and we don't need a full two-way alias anyway (since it is read only).
toReadOnlyRenameOptions =
let
mkAlias =
from: toOpt:
assert lib.assertMsg toOpt.readOnly
"toReadOnlyRenameOptions used on non-readOnly option `${lib.showOption toOpt.loc}'.";
assert lib.assertMsg toOpt.isDefined
"toReadOnlyRenameOptions used on undefined option `${lib.showOption toOpt.loc}'.";
lib.mkOption {
inherit (toOpt) type;
default = toOpt.value;
apply = lib.warn "Obsolete option `${lib.showOption from}' is used. It was renamed to `${lib.showOption toOpt.loc}'.";
description = "Alias of {option}`${lib.showOption toOpt.loc}`.";
readOnly = true;
visible = false;
};
go =
path: name: opt:
let
loc = path ++ lib.singleton name;
in
if lib.isOption opt then mkAlias loc opt else lib.mapAttrs (go loc) opt;
in
lib.mapAttrs (go [ ]);
in
{
# TODO: Added 2024-09-24; remove after 24.11
options = toReadOnlyRenameOptions {
inherit (options.build) printInitPackage;
finalPackage = options.build.package;
initPath = options.build.initFile;
filesPlugin = options.build.extraFiles;
test.derivation = options.build.test;
};
}

View file

@ -36,9 +36,10 @@ in
description = "Whether to check `config.assertions` in the test.";
default = true;
};
};
# Output
derivation = lib.mkOption {
options.build = {
test = lib.mkOption {
type = lib.types.package;
description = ''
A derivation that tests the config by running neovim.
@ -66,10 +67,10 @@ in
) "" toCheck;
in
{
test.derivation =
build.test =
pkgs.runCommandNoCCLocal cfg.name
{
nativeBuildInputs = [ config.finalPackage ];
nativeBuildInputs = [ config.build.package ];
# Allow inspecting the test's module a little from the repl
# e.g.