mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-20 16:15:43 +02:00
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:
parent
7bda0f1ce4
commit
692e39311e
14 changed files with 129 additions and 73 deletions
|
@ -30,7 +30,7 @@ let
|
|||
);
|
||||
};
|
||||
in
|
||||
result.config.test.derivation;
|
||||
result.config.build.test;
|
||||
|
||||
# Create a nix derivation from a nixvim configuration.
|
||||
# The build phase simply consists in running neovim with the given configuration.
|
||||
|
@ -71,7 +71,7 @@ let
|
|||
check = false;
|
||||
};
|
||||
in
|
||||
result.config.test.derivation;
|
||||
result.config.build.test;
|
||||
in
|
||||
# NOTE: this is exported publicly in the flake outputs as `lib.<system>.check`
|
||||
{
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
../.
|
||||
./files
|
||||
./output.nix
|
||||
./readonly-renames.nix
|
||||
./test.nix
|
||||
];
|
||||
|
||||
|
|
|
@ -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 ];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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 ];
|
||||
};
|
||||
}
|
||||
|
|
41
modules/top-level/readonly-renames.nix
Normal file
41
modules/top-level/readonly-renames.nix
Normal 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;
|
||||
};
|
||||
}
|
|
@ -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.
|
||||
|
|
|
@ -14,7 +14,7 @@ let
|
|||
in
|
||||
pkgs.runCommand "extra-files-test"
|
||||
{
|
||||
root = build.config.filesPlugin;
|
||||
root = build.config.build.extraFiles;
|
||||
files = builtins.attrNames extraFiles;
|
||||
}
|
||||
''
|
||||
|
|
|
@ -90,7 +90,7 @@ in
|
|||
assert(is_byte_compiled(init), "MYVIMRC is expected to be byte compiled, but it's not")
|
||||
|
||||
-- nixvim-print-init prints text
|
||||
local init_content = vim.fn.system("${config.printInitPackage}/bin/nixvim-print-init")
|
||||
local init_content = vim.fn.system("${lib.getExe config.build.printInitPackage}")
|
||||
assert(init_content:find("VALIDATING_STRING"), "nixvim-print-init's output is byte compiled")
|
||||
|
||||
-- lua extraFiles are byte compiled
|
||||
|
@ -116,7 +116,11 @@ in
|
|||
};
|
||||
|
||||
disabled =
|
||||
{ config, ... }:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
{
|
||||
performance.byteCompileLua.enable = false;
|
||||
|
||||
|
@ -140,7 +144,7 @@ in
|
|||
assert(not is_byte_compiled(init), "MYVIMRC is not expected to be byte compiled, but it is")
|
||||
|
||||
-- nixvim-print-init prints text
|
||||
local init_content = vim.fn.system("${config.printInitPackage}/bin/nixvim-print-init")
|
||||
local init_content = vim.fn.system("${lib.getExe config.build.printInitPackage}")
|
||||
assert(init_content:find("VALIDATING_STRING"), "nixvim-print-init's output is byte compiled")
|
||||
|
||||
-- Nothing is byte compiled
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
let
|
||||
inherit (pkgs) lib;
|
||||
|
||||
# Count plugins of given type excluding 'filesPlugin'
|
||||
# Count plugins of given type excluding 'build.extraFiles'
|
||||
pluginCount =
|
||||
pkg: filesPlugin: type:
|
||||
builtins.length (builtins.filter (p: p != filesPlugin) pkg.packpathDirs.myNeovimPackages.${type});
|
||||
pkg: files: type:
|
||||
builtins.length (builtins.filter (p: p != files) pkg.packpathDirs.myNeovimPackages.${type});
|
||||
in
|
||||
{
|
||||
# Test basic functionality
|
||||
|
@ -33,7 +33,7 @@ in
|
|||
'';
|
||||
assertions = [
|
||||
{
|
||||
assertion = pluginCount config.finalPackage config.filesPlugin "start" == 1;
|
||||
assertion = pluginCount config.build.package config.build.extraFiles "start" == 1;
|
||||
message = "More than one plugin is defined in packpathDirs, expected one plugin pack.";
|
||||
}
|
||||
];
|
||||
|
@ -50,7 +50,7 @@ in
|
|||
];
|
||||
assertions = [
|
||||
{
|
||||
assertion = pluginCount config.finalPackage config.filesPlugin "start" >= 2;
|
||||
assertion = pluginCount config.build.package config.build.extraFiles "start" >= 2;
|
||||
message = "Only one plugin is defined in packpathDirs, expected at least two.";
|
||||
}
|
||||
];
|
||||
|
@ -77,7 +77,7 @@ in
|
|||
'';
|
||||
assertions = [
|
||||
{
|
||||
assertion = pluginCount config.finalPackage config.filesPlugin "start" == 1;
|
||||
assertion = pluginCount config.build.package config.build.extraFiles "start" == 1;
|
||||
message = "More than one plugin is defined in packpathDirs.";
|
||||
}
|
||||
];
|
||||
|
@ -105,7 +105,7 @@ in
|
|||
'';
|
||||
assertions = [
|
||||
{
|
||||
assertion = pluginCount config.finalPackage config.filesPlugin "start" == 1;
|
||||
assertion = pluginCount config.build.package config.build.extraFiles "start" == 1;
|
||||
message = "More than one plugin is defined in packpathDirs.";
|
||||
}
|
||||
];
|
||||
|
@ -132,7 +132,7 @@ in
|
|||
'';
|
||||
assertions = [
|
||||
{
|
||||
assertion = pluginCount config.finalPackage config.filesPlugin "start" == 1;
|
||||
assertion = pluginCount config.build.package config.build.extraFiles "start" == 1;
|
||||
message = "More than one plugin is defined in packpathDirs.";
|
||||
}
|
||||
];
|
||||
|
@ -186,11 +186,11 @@ in
|
|||
'';
|
||||
assertions = [
|
||||
{
|
||||
assertion = pluginCount config.finalPackage config.filesPlugin "start" == 1;
|
||||
assertion = pluginCount config.build.package config.build.extraFiles "start" == 1;
|
||||
message = "More than one start plugin is defined in packpathDirs";
|
||||
}
|
||||
{
|
||||
assertion = pluginCount config.finalPackage config.filesPlugin "opt" == 2;
|
||||
assertion = pluginCount config.build.package config.build.extraFiles "opt" == 2;
|
||||
message = "Less than two opt plugins are defined in packpathDirs";
|
||||
}
|
||||
];
|
||||
|
@ -233,13 +233,13 @@ in
|
|||
'';
|
||||
assertions = [
|
||||
{
|
||||
assertion = pluginCount config.finalPackage config.filesPlugin "start" == 1;
|
||||
assertion = pluginCount config.build.package config.build.extraFiles "start" == 1;
|
||||
message = "More than one start plugin is defined in packpathDirs";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
# Test that config.filesPlugin is not combined
|
||||
# Test that config.build.extraFiles is not combined
|
||||
files-plugin =
|
||||
{ config, ... }:
|
||||
{
|
||||
|
@ -248,7 +248,7 @@ in
|
|||
nvim-treesitter
|
||||
vim-nix
|
||||
];
|
||||
# Ensure that filesPlugin is added extraPlugins
|
||||
# Ensure that build.extraFiles is added extraPlugins
|
||||
wrapRc = true;
|
||||
# Extra user files colliding with plugins
|
||||
extraFiles = {
|
||||
|
@ -287,23 +287,23 @@ in
|
|||
assert(#get_paths("ftdetect/nix.vim") == 2, "only one version of ftdetect/nix.vim")
|
||||
assert(#get_paths("queries/nix/highlights.scm") == 2, "only one version of queries/nix/highlights.scm")
|
||||
|
||||
-- First found file is from filesPlugin
|
||||
-- First found file is from build.extraFiles
|
||||
assert(
|
||||
get_paths("ftplugin/nix.vim")[1]:find("${lib.getName config.filesPlugin}", 1, true),
|
||||
"first found ftplugin/nix.vim isn't in filesPlugin runtime path"
|
||||
get_paths("ftplugin/nix.vim")[1]:find("${lib.getName config.build.extraFiles}", 1, true),
|
||||
"first found ftplugin/nix.vim isn't in build.extraFiles runtime path"
|
||||
)
|
||||
assert(
|
||||
get_paths("queries/nix/highlights.scm")[1]:find("${lib.getName config.filesPlugin}", 1, true),
|
||||
"first found queries/nix/highlights.scm isn't in filesPlugin runtime path"
|
||||
get_paths("queries/nix/highlights.scm")[1]:find("${lib.getName config.build.extraFiles}", 1, true),
|
||||
"first found queries/nix/highlights.scm isn't in build.extraFiles runtime path"
|
||||
)
|
||||
assert(
|
||||
get_paths("queries/nix/highlights.scm")[1]:find("${lib.getName config.filesPlugin}", 1, true),
|
||||
"first found queries/nix/highlights.scm isn't in filesPlugin runtime path"
|
||||
get_paths("queries/nix/highlights.scm")[1]:find("${lib.getName config.build.extraFiles}", 1, true),
|
||||
"first found queries/nix/highlights.scm isn't in build.extraFiles runtime path"
|
||||
)
|
||||
'';
|
||||
assertions = [
|
||||
{
|
||||
assertion = pluginCount config.finalPackage config.filesPlugin "start" == 1;
|
||||
assertion = pluginCount config.build.package config.build.extraFiles "start" == 1;
|
||||
message = "More than one start plugin is defined in packpathDirs";
|
||||
}
|
||||
];
|
||||
|
@ -369,7 +369,7 @@ in
|
|||
assertions = [
|
||||
{
|
||||
# plugin-pack, nvim-treesitter, nvim-lspconfig, telescope-nvim, nvim-cmp
|
||||
assertion = pluginCount config.finalPackage config.filesPlugin "start" == 5;
|
||||
assertion = pluginCount config.build.package config.build.extraFiles "start" == 5;
|
||||
message = "Wrong number of plugins in packpathDirs";
|
||||
}
|
||||
];
|
||||
|
|
|
@ -74,7 +74,7 @@ in
|
|||
) extraFiles
|
||||
)
|
||||
// {
|
||||
${filesPrefix + initName}.source = cfg.initPath;
|
||||
${filesPrefix + initName}.source = cfg.build.initFile;
|
||||
}
|
||||
)
|
||||
)
|
||||
|
|
|
@ -41,8 +41,8 @@ in
|
|||
|
||||
config = mkIf cfg.enable {
|
||||
environment.systemPackages = [
|
||||
cfg.finalPackage
|
||||
cfg.printInitPackage
|
||||
cfg.build.package
|
||||
cfg.build.printInitPackage
|
||||
] ++ lib.optional cfg.enableMan self.packages.${pkgs.stdenv.hostPlatform.system}.man-docs;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -55,8 +55,8 @@ in
|
|||
|
||||
config = mkIf cfg.enable {
|
||||
home.packages = [
|
||||
cfg.finalPackage
|
||||
cfg.printInitPackage
|
||||
cfg.build.package
|
||||
cfg.build.printInitPackage
|
||||
] ++ lib.optional cfg.enableMan self.packages.${pkgs.stdenv.hostPlatform.system}.man-docs;
|
||||
|
||||
home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "nvim"; };
|
||||
|
|
|
@ -49,8 +49,8 @@ in
|
|||
|
||||
config = mkIf cfg.enable {
|
||||
environment.systemPackages = [
|
||||
cfg.finalPackage
|
||||
cfg.printInitPackage
|
||||
cfg.build.package
|
||||
cfg.build.printInitPackage
|
||||
] ++ lib.optional cfg.enableMan self.packages.${pkgs.stdenv.hostPlatform.system}.man-docs;
|
||||
|
||||
environment.variables = {
|
||||
|
|
|
@ -23,13 +23,13 @@ let
|
|||
defaultPkgs = pkgs;
|
||||
} // extraSpecialArgs;
|
||||
};
|
||||
inherit (nixvimConfig.config) enableMan finalPackage printInitPackage;
|
||||
inherit (nixvimConfig.config) enableMan build;
|
||||
in
|
||||
(pkgs.symlinkJoin {
|
||||
name = "nixvim";
|
||||
paths = [
|
||||
finalPackage
|
||||
printInitPackage
|
||||
build.package
|
||||
build.printInitPackage
|
||||
] ++ pkgs.lib.optional enableMan self.packages.${pkgs.stdenv.hostPlatform.system}.man-docs;
|
||||
meta.mainProgram = "nvim";
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue