treewide: Reformat with nixfmt

This commit is contained in:
traxys 2024-05-05 19:39:35 +02:00
parent c6281260dc
commit 62f32bfc71
459 changed files with 28139 additions and 26377 deletions

View file

@ -1,20 +1,26 @@
{ modules, helpers }:
{
modules,
helpers,
}: {
lib,
pkgs,
config,
...
}: let
inherit (lib) mkEnableOption mkOption mkOptionType mkForce mkMerge mkIf types;
in {
topLevelModules =
[
./modules/output.nix
(import ./modules/files.nix (modules pkgs))
]
++ (modules pkgs);
}:
let
inherit (lib)
mkEnableOption
mkOption
mkOptionType
mkForce
mkMerge
mkIf
types
;
in
{
topLevelModules = [
./modules/output.nix
(import ./modules/files.nix (modules pkgs))
] ++ (modules pkgs);
helpers = mkOption {
type = mkOptionType {
@ -26,27 +32,12 @@ in {
default = helpers;
};
configFiles = let
cfg = config.programs.nixvim;
in
(
lib.mapAttrs'
(
_: file:
lib.nameValuePair
"nvim/${file.path}"
{text = file.content;}
)
cfg.files
)
// (
lib.mapAttrs'
(
path: content:
lib.nameValuePair
"nvim/${path}"
{text = content;}
)
cfg.extraFiles
);
configFiles =
let
cfg = config.programs.nixvim;
in
(lib.mapAttrs' (_: file: lib.nameValuePair "nvim/${file.path}" { text = file.content; }) cfg.files)
// (lib.mapAttrs' (
path: content: lib.nameValuePair "nvim/${path}" { text = content; }
) cfg.extraFiles);
}

View file

@ -2,34 +2,43 @@
modules,
self,
getHelpers,
}: {
}:
{
pkgs,
config,
lib,
...
} @ args: let
inherit (lib) mkEnableOption mkOption mkOptionType mkForce mkMerge mkIf types;
}@args:
let
inherit (lib)
mkEnableOption
mkOption
mkOptionType
mkForce
mkMerge
mkIf
types
;
helpers = getHelpers pkgs false;
shared = import ./_shared.nix {inherit modules helpers;} args;
shared = import ./_shared.nix { inherit modules helpers; } args;
cfg = config.programs.nixvim;
in {
in
{
options = {
programs.nixvim = mkOption {
default = {};
default = { };
type = types.submoduleWith {
shorthandOnlyDefinesConfig = true;
specialArgs = {
darwinConfig = config;
inherit helpers;
};
modules =
[
{
options.enable = mkEnableOption "nixvim";
config.wrapRc = mkForce true;
}
]
++ shared.topLevelModules;
modules = [
{
options.enable = mkEnableOption "nixvim";
config.wrapRc = mkForce true;
}
] ++ shared.topLevelModules;
};
};
nixvim.helpers = shared.helpers;
@ -37,15 +46,11 @@ in {
config = mkIf cfg.enable (mkMerge [
{
environment.systemPackages =
[
cfg.finalPackage
cfg.printInitPackage
]
++ (lib.optional cfg.enableMan self.packages.${pkgs.system}.man-docs);
}
{
inherit (cfg) warnings assertions;
environment.systemPackages = [
cfg.finalPackage
cfg.printInitPackage
] ++ (lib.optional cfg.enableMan self.packages.${pkgs.system}.man-docs);
}
{ inherit (cfg) warnings assertions; }
]);
}

View file

@ -2,60 +2,56 @@
modules,
self,
getHelpers,
}: {
}:
{
pkgs,
config,
lib,
...
} @ args: let
inherit (lib) mkEnableOption mkOption mkOptionType mkMerge mkIf types;
}@args:
let
inherit (lib)
mkEnableOption
mkOption
mkOptionType
mkMerge
mkIf
types
;
helpers = getHelpers pkgs false;
shared = import ./_shared.nix {inherit modules helpers;} args;
shared = import ./_shared.nix { inherit modules helpers; } args;
cfg = config.programs.nixvim;
files =
shared.configFiles
// {
"nvim/init.lua".text = cfg.initContent;
};
in {
files = shared.configFiles // {
"nvim/init.lua".text = cfg.initContent;
};
in
{
options = {
programs.nixvim = mkOption {
default = {};
default = { };
type = types.submoduleWith {
shorthandOnlyDefinesConfig = true;
specialArgs = {
hmConfig = config;
inherit helpers;
};
modules =
[
(import ./modules/hm.nix {
inherit lib;
})
]
++ shared.topLevelModules;
modules = [ (import ./modules/hm.nix { inherit lib; }) ] ++ shared.topLevelModules;
};
};
nixvim.helpers = shared.helpers;
};
config =
mkIf cfg.enable
(mkMerge [
{
home.packages =
[
cfg.finalPackage
cfg.printInitPackage
]
++ (lib.optional cfg.enableMan self.packages.${pkgs.system}.man-docs);
}
(mkIf (!cfg.wrapRc) {
xdg.configFile = files;
})
{
inherit (cfg) warnings assertions;
home.sessionVariables = mkIf cfg.defaultEditor {EDITOR = "nvim";};
}
]);
config = mkIf cfg.enable (mkMerge [
{
home.packages = [
cfg.finalPackage
cfg.printInitPackage
] ++ (lib.optional cfg.enableMan self.packages.${pkgs.system}.man-docs);
}
(mkIf (!cfg.wrapRc) { xdg.configFile = files; })
{
inherit (cfg) warnings assertions;
home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "nvim"; };
}
]);
}

View file

@ -1,45 +1,43 @@
modules: {
modules:
{
pkgs,
config,
lib,
helpers,
...
}: let
}:
let
inherit (lib) types;
fileModuleType = types.submoduleWith {
shorthandOnlyDefinesConfig = true;
specialArgs.helpers = helpers;
modules = [
({
name,
config,
...
}: {
imports = modules;
options.plugin = lib.mkOption {
type = types.package;
description = "A derivation with the content of the file in it";
readOnly = true;
internal = true;
};
config = {
path = name;
type = lib.mkDefault (
if lib.hasSuffix ".vim" name
then "vim"
else "lua"
);
plugin = pkgs.writeTextDir config.path config.content;
};
})
(
{ name, config, ... }:
{
imports = modules;
options.plugin = lib.mkOption {
type = types.package;
description = "A derivation with the content of the file in it";
readOnly = true;
internal = true;
};
config = {
path = name;
type = lib.mkDefault (if lib.hasSuffix ".vim" name then "vim" else "lua");
plugin = pkgs.writeTextDir config.path config.content;
};
}
)
];
};
in {
in
{
options = {
files = lib.mkOption {
type = types.attrsOf fileModuleType;
description = "Files to include in the Vim config.";
default = {};
default = { };
};
filesPlugin = lib.mkOption {
@ -50,23 +48,24 @@ in {
};
};
config = let
inherit (config) files;
concatFilesOption = attr:
lib.flatten (lib.mapAttrsToList (_: builtins.getAttr attr) files);
in {
# Each file can declare plugins/packages/warnings/assertions
extraPlugins = concatFilesOption "extraPlugins";
extraPackages = concatFilesOption "extraPackages";
warnings = concatFilesOption "warnings";
assertions = concatFilesOption "assertions";
config =
let
inherit (config) files;
concatFilesOption = attr: lib.flatten (lib.mapAttrsToList (_: builtins.getAttr attr) files);
in
{
# Each file can declare plugins/packages/warnings/assertions
extraPlugins = concatFilesOption "extraPlugins";
extraPackages = concatFilesOption "extraPackages";
warnings = concatFilesOption "warnings";
assertions = concatFilesOption "assertions";
# A directory with all the files in it
filesPlugin = pkgs.buildEnv {
name = "nixvim-config";
paths =
(lib.mapAttrsToList (_: file: file.plugin) files)
++ (lib.mapAttrsToList pkgs.writeTextDir config.extraFiles);
# A directory with all the files in it
filesPlugin = pkgs.buildEnv {
name = "nixvim-config";
paths =
(lib.mapAttrsToList (_: file: file.plugin) files)
++ (lib.mapAttrsToList pkgs.writeTextDir config.extraFiles);
};
};
};
}

View file

@ -1,5 +1,6 @@
{lib}:
with lib; {
{ lib }:
with lib;
{
options = {
enable = mkEnableOption "nixvim";
defaultEditor = mkEnableOption "nixvim as the default editor";

View file

@ -5,7 +5,8 @@
helpers,
...
}:
with lib; {
with lib;
{
options = {
viAlias = mkOption {
type = types.bool;
@ -69,92 +70,90 @@ with lib; {
};
};
config = let
defaultPlugin = {
plugin = null;
config = "";
optional = false;
};
config =
let
defaultPlugin = {
plugin = null;
config = "";
optional = false;
};
normalizedPlugins = map (x:
defaultPlugin
// (
if x ? plugin
then x
else {plugin = x;}
))
config.extraPlugins;
normalizedPlugins = map (
x: defaultPlugin // (if x ? plugin then x else { plugin = x; })
) config.extraPlugins;
neovimConfig = pkgs.neovimUtils.makeNeovimConfig ({
inherit
(config)
extraPython3Packages
viAlias
vimAlias
withNodeJs
;
# inherit customRC;
plugins = normalizedPlugins;
}
# Necessary to make sure the runtime path is set properly in NixOS 22.05,
# or more generally before the commit:
# cda1f8ae468 - neovim: pass packpath via the wrapper
// optionalAttrs (functionArgs pkgs.neovimUtils.makeNeovimConfig ? configure) {
configure.packages = {
nixvim = {
start = map (x: x.plugin) normalizedPlugins;
opt = [];
neovimConfig = pkgs.neovimUtils.makeNeovimConfig (
{
inherit (config)
extraPython3Packages
viAlias
vimAlias
withNodeJs
;
# inherit customRC;
plugins = normalizedPlugins;
}
# Necessary to make sure the runtime path is set properly in NixOS 22.05,
# or more generally before the commit:
# cda1f8ae468 - neovim: pass packpath via the wrapper
// optionalAttrs (functionArgs pkgs.neovimUtils.makeNeovimConfig ? configure) {
configure.packages = {
nixvim = {
start = map (x: x.plugin) normalizedPlugins;
opt = [ ];
};
};
};
});
}
);
customRC =
''
vim.cmd([[
${neovimConfig.neovimRcContent}
]])
''
+ config.content;
customRC =
''
vim.cmd([[
${neovimConfig.neovimRcContent}
]])
''
+ config.content;
init = helpers.writeLua "init.lua" customRC;
initPath = toString init;
init = helpers.writeLua "init.lua" customRC;
initPath = toString init;
extraWrapperArgs = builtins.concatStringsSep " " (
(optional (config.extraPackages != [])
''--prefix PATH : "${makeBinPath config.extraPackages}"'')
++ (optional config.wrapRc
''--add-flags -u --add-flags "${init}"'')
);
extraWrapperArgs = builtins.concatStringsSep " " (
(optional (config.extraPackages != [ ]) ''--prefix PATH : "${makeBinPath config.extraPackages}"'')
++ (optional config.wrapRc ''--add-flags -u --add-flags "${init}"'')
);
wrappedNeovim = pkgs.wrapNeovimUnstable config.package (neovimConfig
// {
wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " " + extraWrapperArgs;
wrapRc = false;
});
in {
type = lib.mkForce "lua";
finalPackage = wrappedNeovim;
initContent = customRC;
inherit initPath;
wrappedNeovim = pkgs.wrapNeovimUnstable config.package (
neovimConfig
// {
wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " " + extraWrapperArgs;
wrapRc = false;
}
);
in
{
type = lib.mkForce "lua";
finalPackage = wrappedNeovim;
initContent = customRC;
inherit initPath;
printInitPackage = pkgs.writeShellApplication {
name = "nixvim-print-init";
runtimeInputs = with pkgs; [stylua bat];
text = ''
stylua - <"${initPath}" | bat --language=lua
printInitPackage = pkgs.writeShellApplication {
name = "nixvim-print-init";
runtimeInputs = with pkgs; [
stylua
bat
];
text = ''
stylua - <"${initPath}" | bat --language=lua
'';
};
extraConfigLuaPre = lib.optionalString config.wrapRc ''
-- Ignore the user lua configuration
vim.opt.runtimepath:remove(vim.fn.stdpath('config')) -- ~/.config/nvim
vim.opt.runtimepath:remove(vim.fn.stdpath('config') .. "/after") -- ~/.config/nvim/after
vim.opt.runtimepath:remove(vim.fn.stdpath('data') .. "/site") -- ~/.local/share/nvim/site
'';
extraPlugins = if config.wrapRc then [ config.filesPlugin ] else [ ];
};
extraConfigLuaPre = lib.optionalString config.wrapRc ''
-- Ignore the user lua configuration
vim.opt.runtimepath:remove(vim.fn.stdpath('config')) -- ~/.config/nvim
vim.opt.runtimepath:remove(vim.fn.stdpath('config') .. "/after") -- ~/.config/nvim/after
vim.opt.runtimepath:remove(vim.fn.stdpath('data') .. "/site") -- ~/.local/share/nvim/site
'';
extraPlugins =
if config.wrapRc
then [config.filesPlugin]
else [];
};
}

View file

@ -2,66 +2,69 @@
modules,
self,
getHelpers,
}: {
}:
{
pkgs,
config,
lib,
...
} @ args: let
inherit (lib) mkEnableOption mkOption mkOptionType mkForce mkMerge mkIf types;
}@args:
let
inherit (lib)
mkEnableOption
mkOption
mkOptionType
mkForce
mkMerge
mkIf
types
;
helpers = getHelpers pkgs false;
shared = import ./_shared.nix {inherit modules helpers;} args;
shared = import ./_shared.nix { inherit modules helpers; } args;
cfg = config.programs.nixvim;
files =
shared.configFiles
// {
"nvim/sysinit.lua".text = cfg.initContent;
};
in {
files = shared.configFiles // {
"nvim/sysinit.lua".text = cfg.initContent;
};
in
{
options = {
programs.nixvim = mkOption {
default = {};
default = { };
type = types.submoduleWith {
shorthandOnlyDefinesConfig = true;
specialArgs = {
nixosConfig = config;
inherit helpers;
};
modules =
[
{
options = {
enable = mkEnableOption "nixvim";
defaultEditor = mkEnableOption "nixvim as the default editor";
};
config.wrapRc = mkForce true;
}
]
++ shared.topLevelModules;
modules = [
{
options = {
enable = mkEnableOption "nixvim";
defaultEditor = mkEnableOption "nixvim as the default editor";
};
config.wrapRc = mkForce true;
}
] ++ shared.topLevelModules;
};
};
nixvim.helpers = shared.helpers;
};
config =
mkIf cfg.enable
(mkMerge [
{
environment.systemPackages =
[
cfg.finalPackage
cfg.printInitPackage
]
++ (lib.optional cfg.enableMan self.packages.${pkgs.system}.man-docs);
}
(mkIf (!cfg.wrapRc) {
environment.etc = files;
environment.variables."VIM" = "/etc/nvim";
})
{
inherit (cfg) warnings assertions;
programs.neovim.defaultEditor = cfg.defaultEditor;
environment.variables.EDITOR = mkIf cfg.defaultEditor (lib.mkOverride 900 "nvim");
}
]);
config = mkIf cfg.enable (mkMerge [
{
environment.systemPackages = [
cfg.finalPackage
cfg.printInitPackage
] ++ (lib.optional cfg.enableMan self.packages.${pkgs.system}.man-docs);
}
(mkIf (!cfg.wrapRc) {
environment.etc = files;
environment.variables."VIM" = "/etc/nvim";
})
{
inherit (cfg) warnings assertions;
programs.neovim.defaultEditor = cfg.defaultEditor;
environment.variables.EDITOR = mkIf cfg.defaultEditor (lib.mkOverride 900 "nvim");
}
]);
}

View file

@ -1,59 +1,69 @@
default_pkgs: {
default_pkgs:
{
modules,
self,
getHelpers,
}: {
}:
{
pkgs ? default_pkgs,
extraSpecialArgs ? {},
extraSpecialArgs ? { },
_nixvimTests ? false,
module,
}: let
}:
let
inherit (pkgs) lib;
helpers = getHelpers pkgs _nixvimTests;
shared = import ./_shared.nix {inherit modules helpers;} {
shared = import ./_shared.nix { inherit modules helpers; } {
inherit pkgs lib;
config = {};
config = { };
};
mkEval = mod:
mkEval =
mod:
lib.evalModules {
modules =
[
mod
{wrapRc = true;}
]
++ shared.topLevelModules;
specialArgs =
{
inherit helpers;
}
// extraSpecialArgs;
modules = [
mod
{ wrapRc = true; }
] ++ shared.topLevelModules;
specialArgs = {
inherit helpers;
} // extraSpecialArgs;
};
handleAssertions = config: let
failedAssertions = map (x: x.message) (lib.filter (x: !x.assertion) config.assertions);
in
if failedAssertions != []
then throw "\nFailed assertions:\n${builtins.concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
else lib.showWarnings config.warnings config;
handleAssertions =
config:
let
failedAssertions = map (x: x.message) (lib.filter (x: !x.assertion) config.assertions);
in
if failedAssertions != [ ] then
throw "\nFailed assertions:\n${builtins.concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
else
lib.showWarnings config.warnings config;
mkNvim = mod: let
config = handleAssertions (mkEval mod).config;
in
mkNvim =
mod:
let
config = handleAssertions (mkEval mod).config;
in
(pkgs.symlinkJoin {
name = "nixvim";
paths =
[
config.finalPackage
config.printInitPackage
]
++ pkgs.lib.optional config.enableMan self.packages.${pkgs.system}.man-docs;
paths = [
config.finalPackage
config.printInitPackage
] ++ pkgs.lib.optional config.enableMan self.packages.${pkgs.system}.man-docs;
meta.mainProgram = "nvim";
})
// {
inherit config;
nixvimExtend = extension: mkNvim {imports = [mod extension];};
nixvimExtend =
extension:
mkNvim {
imports = [
mod
extension
];
};
};
in
mkNvim module
mkNvim module