Skip to content

Commit

Permalink
Can now be launched with nvim.
Browse files Browse the repository at this point in the history
Can also now install packages made with different versions of
neovim-unwrapped to the same user's path via home.packages and
environment.systemPackages.
  • Loading branch information
BirdeeHub committed Aug 8, 2024
1 parent a54f843 commit 9f1bd3e
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 100 deletions.
21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,18 @@ When you are ready, start [with](./nix/templates/nixExpressionFlakeOutputs) a [t

If you use lazy, consider using the lazy.nvim wrapper [in luaUtils](./nix/templates/luaUtils/lua/nixCatsUtils) documented in [:h luaUtils](./nix/nixCatsHelp/luaUtils.txt) and [demonstrated here.](./nix/templates/kickstart-nvim). The luaUtils template also contains other simple tools that will help if you want your configuration to still load without nix involved in any way.

##### (just remember to change your $EDITOR variable, the reason why is explained below in the section marked [Attention](#attention))
##### (just remember to change your $EDITOR variable, the reason why is explained below)

## Attention: <a name="attention"></a>
> You cannot launch nixCats with the nvim command. You may, however, launch it with anything else you would like to choose.
> This is a side effect of being able to install multiple simultaneous versions of the same version of nvim to the same user's PATH via a module such as home manager, something that would normally cause a collision error.
> You may launch your nixCats via any name you would like to choose.
> The default launch name is the package name in the packageDefinitions set in flake.nix for that package. You may then make any other aliases that you please as long as they do not conflict.
> This also means that your $EDITOR variable should match the name in your packageDefinitions set in flake.nix so that stuff like git opens the right thing.
> This means that your $EDITOR variable should match the name in your packageDefinitions set in flake.nix so that stuff like git opens the right thing, because that is what the desktop file is called.
> Nvim does not know about the wrapper script. Nvim is named `nvim` and is in a file in the store. It is still at `<store_path>/bin/nvim` and is aware of that. Thus, this should not cause any other issues beyond the way nvim is normally wrapped via the wrappers in nixpkgs.
> If your aliases conflict and you try to install them both to your path via home.packages or environment.systemPackages, it will throw a collision error.
> Because it is still at `<store_path>/bin/nvim`, you also may only have 1 version of neovim itself per user. This particular requirement however might be possible to fix because this version is not in your PATH, the wrappers are. I am honestly unsure why this is not possible, but it wasn't solved by nixpkgs either and hasn't been an issue.
> Nvim does not know about the wrapper script. Nvim is named `nvim` and is in a file in the store. It is still at `<store_path>/bin/nvim` and is aware of that. Thus, this should not cause any other issues beyond the way nvim is normally wrapped via the wrappers in nixpkgs.
## Table of Contents
1. [Features](#features)
Expand Down Expand Up @@ -118,8 +116,6 @@ Everything you need to make a config based on nixCats is exported by the nixCats

You will not be backed into any corners using the nixCats scheme, either as a flake or module.

Except 1. The section above marked [attention](#attention)

You should make use of the in-editor help at:

[:help nixCats](./nix/nixCatsHelp/nixCats.txt)
Expand Down Expand Up @@ -271,15 +267,10 @@ and also :help [nixCats.flake.outputs.exports](./nix/nixCatsHelp/nixCatsFlake.tx

#### Drawbacks:

Specific to this project:

You cannot launch nvim with nvim and must choose an alias.
This is the trade off for installing multiple versions of nvim to the same user's PATH from a module, something that would normally cause a collision error.

General nix + nvim things:

Some vscode debuggers are not on nixpkgs so you have to build them (there's a place for it in customBuildsOverlay).
Let people know when you figure one out or submit it to nixpkgs.
Let people know when you figure one out or submit it to nixpkgs. Sometimes you can extract them from vscode plugins.

[Mason](https://github.com/williamboman/mason.nvim) does not work on nixOS although it does on other OS options. However you can make it work with SharedLibraries and lspsAndRuntimeDeps options if you choose to not use those fields for their intended purpose!

Expand Down
2 changes: 0 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@
wrapRc = true;
configDirName = "nixCats-nvim";
aliases = [ "vim" "vimcat" ];
# caution: this option must be the same for all packages.
# or at least, all packages that are to be installed simultaneously.
# neovim-unwrapped = inputs.neovim-nightly-overlay.packages.${pkgs.system}.neovim;
};
# see :help nixCats.flake.outputs.packageDefinitions
Expand Down
37 changes: 26 additions & 11 deletions nix/builder/wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ stdenv.mkDerivation {
# extra actions upon
# nixCats: modified to start with packagename instead of nvim to avoid collisions with multiple neovims
postBuild = lib.optionalString stdenv.isLinux ''
rm $out/share/applications/nvim.desktop
mkdir -p $out/share/applications
substitute ${neovim-unwrapped}/share/applications/nvim.desktop $out/share/applications/${nixCats_packageName}.desktop \
--replace 'Name=Neovim' 'Name=${nixCats_packageName}'\
--replace 'TryExec=nvim' 'TryExec=${nixCats_packageName}'\
--replace 'Exec=nvim %F' 'Exec=${nixCats_packageName} %F'
--replace 'Icon=nvim' 'Icon=${neovim-unwrapped}/share/icons/hicolor/128x128/apps/nvim.png'\
--replace 'Exec=nvim %F' "Exec=${nixCats_packageName} %F"
''
+ lib.optionalString (python3Env != null && withPython3) ''
makeWrapper ${python3Env.interpreter} $out/bin/${nixCats_packageName}-python3 --unset PYTHONPATH ${builtins.concatStringsSep " " extraPython3wrapperArgs}
Expand Down Expand Up @@ -166,6 +167,9 @@ stdenv.mkDerivation {
manifestWrapperArgs =
[ "${neovim-unwrapped}/bin/nvim" "${placeholder "out"}/bin/nvim-wrapper" ] ++ generatedWrapperArgs;
in /* bash */ ''
mkdir -p $out/nix-support
cp -r ${neovim-unwrapped}/nix-support/* $out/nix-support
echo "Generating remote plugin manifest"
export NVIM_RPLUGIN_MANIFEST=$out/rplugin.vim
makeWrapper ${lib.escapeShellArgs manifestWrapperArgs} ${wrapperArgsStr}
Expand Down Expand Up @@ -199,7 +203,7 @@ stdenv.mkDerivation {
'')

+ /* bash */ ''
rm $out/bin/nvim
# rm $out/bin/nvim # <-- we no longer copy everything and no longer need this.
touch $out/rplugin.vim
# see:
# https://github.com/NixOS/nixpkgs/issues/318925
Expand Down Expand Up @@ -230,14 +234,25 @@ stdenv.mkDerivation {
rm $BASHCACHE
'';

buildPhase = ''
runHook preBuild
mkdir -p $out
for i in ${neovim-unwrapped}; do
lndir -silent $i $out
done
runHook postBuild
'';
# we dont need to copy everything!!!!
# we can hardcode the icon path in the desktop file.
# neovim knows about vim.env.VIMRUNTIME
# neovim knows about vim.fn.fnamemodify(vim.v.progpath, ":p:h:h") .. "/lib/nvim/parser"
# gettext uses the c version of vim.v.progpath as well for locales and translation.

# so all we need is a desktop file, and nix-support

# buildPhase = ''
# runHook preBuild
# mkdir -p $out
# for i in ${neovim-unwrapped}; do
# lndir -silent $i $out
# done
# runHook postBuild
# '';

# This was the cause of the collision error preventing multiple
# versions of nvim being installed to the same user's path, and it wasnt needed!

preferLocalBuild = true;

Expand Down
10 changes: 2 additions & 8 deletions nix/nixCatsHelp/nixCats.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ NIX CATEGORIES *nixCats*
For help with the nix flake files, see :help |nixCats.flake|

*******************************************************
TWO IMPORTANT NOTES:
AN IMPORTANT NOTE:

<1> YOU CANNOT LAUNCH THIS VIA nvim COMMAND
IT HAS THE NAME OF THE PACKAGE YOU SET,
AND WHATEVER ALIASES YOU GAVE IT.
This is due to the ability to install multiple nvims via home manager
or per single user on nixos.

<2> When editing the files within the flake directory,
<1> When editing the files within the flake directory,
nix will not package a new file if it isn't staged in git.
run git add before rebuilding it whenever adding a new file.
Using wrapRc = true would mean this also applies to lua files.
Expand Down
13 changes: 2 additions & 11 deletions nix/nixCatsHelp/nixCatsFlake.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ Download in flake.nix and then, simply pretend the root of the flake
is the root of your Lua config.

*******************************************************
TWO IMPORTANT NOTES:
AN IMPORTANT NOTE:

<1> YOU CANNOT LAUNCH THIS VIA nvim COMMAND
IT HAS THE NAME OF THE PACKAGE YOU SET,
AND WHATEVER ALIASES YOU GAVE IT.
This is due to the ability to install multiple nvims via home manager
or per single user on nixos.

<2> When editing the files within the flake directory,
<1> When editing the files within the flake directory,
nix will not package a new file if it isn't staged in git.
run git add before rebuilding it whenever adding a new file.
Using wrapRc = true would mean this also applies to lua files.
Expand Down Expand Up @@ -536,9 +530,6 @@ These are the defaults:
# is still needed for .local/share or .cache and the like
unwrappedCfgPath = null;

### CAUTION: These next 2 options must be the same
# for ALL nvim packages that you wish to have simultaneously installed.

# use this to pin a specific neovim version.
# This one will specify the base neovim derivation to use.
neovim-unwrapped = null;
Expand Down
10 changes: 1 addition & 9 deletions nix/nixCatsHelp/nixCatsModules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,10 @@ but your system will not inherit overlays from nixCats.
description = ''
VERY IMPORTANT when setting aliases for each package,
they must not be the same as ANY other neovim package for that user.
YOU MAY NOT ALIAS TO NVIM ITSELF
It will cause a build conflict.
again, YOU MAY NOT ALIAS TO NVIM ITSELF

You also cannot install nixCats via
multiple nixCats modules from different repos per user.
This should not be an issue as a single module can output multiple packages.

You can have as many nixCats installed per user as you want,
as long as you obey those rules.
This is a big step up from only being able to have 1 neovim
at all per user, so excuse me for the inconvenience.
as long as you obey that rule.

for information on the values you may return,
see :help nixCats.flake.outputs.settings
Expand Down
3 changes: 0 additions & 3 deletions nix/templates/fresh/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,8 @@
settings = {
wrapRc = true;
# IMPORTANT:
# you may not alias to nvim
# your alias may not conflict with your other packages.
aliases = [ "vim" ];
# caution: this option must be the same for all packages.
# or at least, all packages that are to be installed simultaneously.
# neovim-unwrapped = inputs.neovim-nightly-overlay.packages.${pkgs.system}.neovim;
};
# and a set of categories that you want
Expand Down
3 changes: 0 additions & 3 deletions nix/templates/kickstart-nvim/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,8 @@
settings = {
wrapRc = true;
# IMPORTANT:
# you may not alias to nvim
# your alias may not conflict with your other packages.
aliases = [ "vim" ];
# caution: this option must be the same for all packages.
# or at least, all packages that are to be installed simultaneously.
# neovim-unwrapped = inputs.neovim-nightly-overlay.packages.${pkgs.system}.neovim;
};
# and a set of categories that you want
Expand Down
3 changes: 0 additions & 3 deletions nix/templates/module/homeCat.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ in {
settings = {
wrapRc = true;
# IMPORTANT:
# you may not alias to nvim
# your alias may not conflict with your other packages.
aliases = [ "vim" "homeVim" ];
# caution: this option must be the same for all packages.
# or at least, all packages that are to be installed simultaneously.
# neovim-unwrapped = inputs.neovim-nightly-overlay.packages.${pkgs.system}.neovim;
};
# and a set of categories that you want
Expand Down
5 changes: 0 additions & 5 deletions nix/templates/module/systemCat.nix
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,8 @@ in {
settings = {
wrapRc = true;
# IMPORTANT:
# you may not alias to nvim
# your alias may not conflict with your other packages.
aliases = [ "vim" "systemVim" ];
# caution: this option must be the same for all packages.
# or at least, all packages that are to be installed simultaneously.
# neovim-unwrapped = inputs.neovim-nightly-overlay.packages.${pkgs.system}.neovim;
};
# and a set of categories that you want
Expand Down Expand Up @@ -156,8 +153,6 @@ in {
wrapRc = true;
configDirName = "nixCats-nvim";
aliases = [ "REPLACE_MY_VIM" ];
# caution: this option must be the same for all packages.
# or at least, all packages that are to be installed simultaneously.
# neovim-unwrapped = inputs.neovim-nightly-overlay.packages.${pkgs.system}.neovim;
};
# see :help nixCats.flake.outputs.packageDefinitions
Expand Down
3 changes: 0 additions & 3 deletions nix/templates/nixExpressionFlakeOutputs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,8 @@
settings = {
wrapRc = true;
# IMPORTANT:
# you may not alias to nvim
# your alias may not conflict with your other packages.
aliases = [ "vim" ];
# caution: this option must be the same for all packages.
# or at least, all packages that are to be installed simultaneously.
# neovim-unwrapped = inputs.neovim-nightly-overlay.packages.${pkgs.system}.neovim;
};
# and a set of categories that you want
Expand Down
10 changes: 1 addition & 9 deletions nix/utils/homeManagerModule.nix
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,10 @@
description = ''
VERY IMPORTANT when setting aliases for each package,
they must not be the same as ANY other neovim package for that user.
YOU MAY NOT ALIAS TO NVIM ITSELF
It will cause a build conflict.
again, YOU MAY NOT ALIAS TO NVIM ITSELF
You also cannot install nixCats via
multiple nixCats modules from different repos per user.
This should not be an issue as a single module can output multiple packages.
You can have as many nixCats installed per user as you want,
as long as you obey those rules.
This is a big step up from only being able to have 1 neovim
at all per user, so excuse me for the inconvenience.
as long as you obey that rule.
for information on the values you may return,
see :help nixCats.flake.outputs.settings
Expand Down
22 changes: 4 additions & 18 deletions nix/utils/nixosModule.nix
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,10 @@
description = ''
VERY IMPORTANT when setting aliases for each package,
they must not be the same as ANY other neovim package for that user.
YOU MAY NOT ALIAS TO NVIM ITSELF
It will cause a build conflict.
You also cannot install nixCats via multiple sources per user.
i.e. if you have it installed as a package, you cannot install it
as a module.
However, you can have as many nixCats as you want,
as long as you obey those rules.
This is a big step up from only being able to have 1 neovim
at all per user, so excuse me for the inconvenience. This may be fixed someday.
You can have as many nixCats installed per user as you want,
as long as you obey that rule.
for information on the values you may return,
see :help nixCats.flake.outputs.settings
Expand Down Expand Up @@ -247,17 +240,10 @@
description = ''
VERY IMPORTANT when setting aliases for each package,
they must not be the same as ANY other neovim package for that user.
YOU MAY NOT ALIAS TO NVIM ITSELF
It will cause a build conflict.
You also cannot install nixCats via multiple sources per user.
i.e. if you have it installed as a package, you cannot install it
as a module.
However, you can have as many nixCats as you want,
as long as you obey those rules.
This is a big step up from only being able to have 1 neovim
at all per user, so excuse me for the inconvenience. This may be fixed someday.
You can have as many nixCats installed per user as you want,
as long as you obey that rule.
for information on the values you may return,
see :help nixCats.flake.outputs.settings
Expand Down

0 comments on commit 9f1bd3e

Please sign in to comment.