Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vim, neovim: format with nixfmt-rfc-style #359401

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 70 additions & 51 deletions nixos/modules/programs/neovim.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{ config, lib, pkgs, ... }:
{
config,
lib,
pkgs,
...
}:

let
cfg = config.programs.neovim;
Expand Down Expand Up @@ -102,45 +107,49 @@ in
Set of files that have to be linked in {file}`runtime`.
'';

type = with lib.types; attrsOf (submodule (
{ name, config, ... }:
{
options = {

enable = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether this runtime directory should be generated. This
option allows specific runtime files to be disabled.
'';
};

target = lib.mkOption {
type = lib.types.str;
description = ''
Name of symlink. Defaults to the attribute
name.
'';
};

text = lib.mkOption {
default = null;
type = lib.types.nullOr lib.types.lines;
description = "Text of the file.";
};

source = lib.mkOption {
default = null;
type = lib.types.nullOr lib.types.path;
description = "Path of the source file.";
};

};

config.target = lib.mkDefault name;
}
));
type =
with lib.types;
attrsOf (
submodule (
{ name, config, ... }:
{
options = {

enable = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether this runtime directory should be generated. This
option allows specific runtime files to be disabled.
'';
};

target = lib.mkOption {
type = lib.types.str;
description = ''
Name of symlink. Defaults to the attribute
name.
'';
};

text = lib.mkOption {
default = null;
type = lib.types.nullOr lib.types.lines;
description = "Text of the file.";
};

source = lib.mkOption {
default = null;
type = lib.types.nullOr lib.types.path;
description = "Path of the source file.";
};

};

config.target = lib.mkDefault name;
}
)
);

};
};
Expand All @@ -155,19 +164,29 @@ in
# from other packages will be used by neovim.
environment.pathsToLink = [ "/share/nvim" ];

environment.etc = builtins.listToAttrs (builtins.attrValues (builtins.mapAttrs
(name: value: {
name = "xdg/nvim/${name}";
value = builtins.removeAttrs
(value // {
target = "xdg/nvim/${value.target}";
})
(lib.optionals (builtins.isNull value.source) [ "source" ]);
})
cfg.runtime));
environment.etc = builtins.listToAttrs (
builtins.attrValues (
builtins.mapAttrs (name: value: {
name = "xdg/nvim/${name}";
value = builtins.removeAttrs (
value
// {
target = "xdg/nvim/${value.target}";
}
) (lib.optionals (builtins.isNull value.source) [ "source" ]);
}) cfg.runtime
)
);

programs.neovim.finalPackage = pkgs.wrapNeovim cfg.package {
inherit (cfg) viAlias vimAlias withPython3 withNodeJs withRuby configure;
inherit (cfg)
viAlias
vimAlias
withPython3
withNodeJs
withRuby
configure
;
};
};
}
74 changes: 42 additions & 32 deletions pkgs/applications/editors/neovim/build-neovim-plugin.nix
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
{ lib
, stdenv
, lua
, toVimPlugin
{
lib,
stdenv,
lua,
toVimPlugin,
}:
let
# sanitizeDerivationName
normalizeName = lib.replaceStrings [ "." ] [ "-" ];
in

# function to create vim plugin from lua packages that are already packaged in
# luaPackages
{
# the lua derivation to convert into a neovim plugin
luaAttr ? (lua.pkgs.${normalizeName attrs.pname})
, ...
}@attrs:
let
originalLuaDrv = if (lib.typeOf luaAttr == "string") then
lib.warn "luaAttr as string is deprecated since September 2024. Pass a lua derivation directly ( e.g., `buildNeovimPlugin { luaAttr = lua.pkgs.plenary-nvim; }`)" lua.pkgs.${normalizeName luaAttr}
else luaAttr;

# function to create vim plugin from lua packages that are already packaged in
# luaPackages
{
# the lua derivation to convert into a neovim plugin
luaAttr ? (lua.pkgs.${normalizeName attrs.pname}),
...
}@attrs:
let
originalLuaDrv =
if (lib.typeOf luaAttr == "string") then
lib.warn
"luaAttr as string is deprecated since September 2024. Pass a lua derivation directly ( e.g., `buildNeovimPlugin { luaAttr = lua.pkgs.plenary-nvim; }`)"
lua.pkgs.${normalizeName luaAttr}
else
luaAttr;

luaDrv = originalLuaDrv.overrideAttrs (oa: {
version = attrs.version or oa.version;
rockspecVersion = oa.rockspecVersion;
luaDrv = originalLuaDrv.overrideAttrs (oa: {
version = attrs.version or oa.version;
rockspecVersion = oa.rockspecVersion;

extraConfig = ''
-- to create a flat hierarchy
lua_modules_path = "lua"
'';
});
extraConfig = ''
-- to create a flat hierarchy
lua_modules_path = "lua"
'';
});

finalDrv = toVimPlugin (luaDrv.overrideAttrs(oa: attrs // {
nativeBuildInputs = oa.nativeBuildInputs or [] ++ [
lua.pkgs.luarocksMoveDataFolder
];
version = "${originalLuaDrv.version}-unstable-${oa.version}";
}));
in
finalDrv
finalDrv = toVimPlugin (
luaDrv.overrideAttrs (
oa:
attrs
// {
nativeBuildInputs = oa.nativeBuildInputs or [ ] ++ [
lua.pkgs.luarocksMoveDataFolder
];
version = "${originalLuaDrv.version}-unstable-${oa.version}";
}
)
);
in
finalDrv
14 changes: 12 additions & 2 deletions pkgs/applications/editors/neovim/gnvim/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{ lib, rustPlatform, fetchFromGitHub, pkg-config, glib, gtk4 }:
{
lib,
rustPlatform,
fetchFromGitHub,
pkg-config,
glib,
gtk4,
}:

rustPlatform.buildRustPackage rec {
pname = "gnvim-unwrapped";
Expand All @@ -18,7 +25,10 @@ rustPlatform.buildRustPackage rec {
# for the `glib-compile-resources` command
glib
];
buildInputs = [ glib gtk4 ];
buildInputs = [
glib
gtk4
];

# The default build script tries to get the version through Git, so we
# replace it
Expand Down
37 changes: 22 additions & 15 deletions pkgs/applications/editors/neovim/gnvim/wrapper.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
{ lib, stdenv, gnvim-unwrapped, neovim, makeWrapper }:
{
lib,
stdenv,
gnvim-unwrapped,
neovim,
makeWrapper,
}:

stdenv.mkDerivation {
pname = "gnvim";
version = gnvim-unwrapped.version;
buildCommand = ''
makeWrapper '${gnvim-unwrapped}/bin/gnvim' "$out/bin/gnvim" \
--prefix PATH : "${neovim}/bin" \
--set GNVIM_RUNTIME_PATH "${gnvim-unwrapped}/share/gnvim/runtime"
'' + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
mkdir -p "$out/share"
ln -s '${gnvim-unwrapped}/share/icons' "$out/share/icons"
buildCommand =
''
makeWrapper '${gnvim-unwrapped}/bin/gnvim' "$out/bin/gnvim" \
--prefix PATH : "${neovim}/bin" \
--set GNVIM_RUNTIME_PATH "${gnvim-unwrapped}/share/gnvim/runtime"
''
+ lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
mkdir -p "$out/share"
ln -s '${gnvim-unwrapped}/share/icons' "$out/share/icons"

# copy and fix .desktop file
cp -r '${gnvim-unwrapped}/share/applications' "$out/share/applications"
# Sed needs a writable directory to do inplace modifications
chmod u+rw "$out/share/applications"
sed -e "s|Exec=.\\+gnvim\\>|Exec=gnvim|" -i $out/share/applications/*.desktop
'';
# copy and fix .desktop file
cp -r '${gnvim-unwrapped}/share/applications' "$out/share/applications"
# Sed needs a writable directory to do inplace modifications
chmod u+rw "$out/share/applications"
sed -e "s|Exec=.\\+gnvim\\>|Exec=gnvim|" -i $out/share/applications/*.desktop
'';

preferLocalBuild = true;

Expand All @@ -28,4 +36,3 @@ stdenv.mkDerivation {

inherit (gnvim-unwrapped) meta;
}

29 changes: 16 additions & 13 deletions pkgs/applications/editors/neovim/ruby_provider/gemset.nix
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
{
logger = {
groups = ["default"];
platforms = [];
groups = [ "default" ];
platforms = [ ];
source = {
remotes = ["https://rubygems.org"];
remotes = [ "https://rubygems.org" ];
sha256 = "0lwncq2rf8gm79g2rcnnyzs26ma1f4wnfjm6gs4zf2wlsdz5in9s";
type = "gem";
};
version = "1.6.1";
};
msgpack = {
groups = ["default"];
platforms = [];
groups = [ "default" ];
platforms = [ ];
source = {
remotes = ["https://rubygems.org"];
remotes = [ "https://rubygems.org" ];
sha256 = "1a5fsgchkpcca4wf3pipbb2jbj523l7fbaq37j10cr0yymwlkc7z";
type = "gem";
};
version = "1.7.5";
};
multi_json = {
groups = ["default"];
platforms = [];
groups = [ "default" ];
platforms = [ ];
source = {
remotes = ["https://rubygems.org"];
remotes = [ "https://rubygems.org" ];
sha256 = "sha256-H9BBOLbkqQAX6NG4BMA5AxOZhm/z+6u3girqNnx4YV0=";
type = "gem";
};
version = "1.15.0";
};
neovim = {
dependencies = ["msgpack" "multi_json"];
groups = ["default"];
platforms = [];
dependencies = [
"msgpack"
"multi_json"
];
groups = [ "default" ];
platforms = [ ];
source = {
remotes = ["https://rubygems.org"];
remotes = [ "https://rubygems.org" ];
sha256 = "0gl34rriwwmj6p1s6ms0b311wmqaqiyc510svq31283jk0kp0qcd";
type = "gem";
};
Expand Down
Loading