Skip to content

Commit

Permalink
wrappers: add nixvim-print-init package
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Dec 7, 2023
1 parent 032f697 commit 45d788b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
5 changes: 4 additions & 1 deletion wrappers/darwin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ in {
config = mkIf cfg.enable (mkMerge [
{
environment.systemPackages =
[cfg.finalPackage]
[
cfg.finalPackage
cfg.printInitPackage
]
++ (lib.optional cfg.enableMan self.packages.${pkgs.system}.man-docs);
}
{
Expand Down
5 changes: 4 additions & 1 deletion wrappers/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ in {
(mkMerge [
{
home.packages =
[cfg.finalPackage]
[
cfg.finalPackage
cfg.printInitPackage
]
++ (lib.optional cfg.enableMan self.packages.${pkgs.system}.man-docs);
}
(mkIf (!cfg.wrapRc) {
Expand Down
29 changes: 28 additions & 1 deletion wrappers/modules/output.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,26 @@ in {
readOnly = true;
};

initPath = mkOption {
type = types.str;
description = "The path to the init.lua file";
readOnly = true;
visible = false;
};

initContent = mkOption {
type = types.str;
description = "The content of the 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.";
readOnly = true;
visible = false;
};
};

config = let
Expand Down Expand Up @@ -110,11 +124,14 @@ in {
''
+ config.content;

init = pkgs.writeText "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 "${pkgs.writeText "init.lua" customRC}"'')
''--add-flags -u --add-flags "${init}"'')
);

wrappedNeovim = pkgs.wrapNeovimUnstable config.package (neovimConfig
Expand All @@ -126,6 +143,16 @@ 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
'';
};

extraPlugins =
if config.wrapRc
then [config.filesPlugin]
Expand Down
5 changes: 4 additions & 1 deletion wrappers/nixos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ in {
(mkMerge [
{
environment.systemPackages =
[cfg.finalPackage]
[
cfg.finalPackage
cfg.printInitPackage
]
++ (lib.optional cfg.enableMan self.packages.${pkgs.system}.man-docs);
}
(mkIf (!cfg.wrapRc) {
Expand Down
5 changes: 4 additions & 1 deletion wrappers/standalone.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ in
pkgs.symlinkJoin {
name = "nixvim";
paths =
[config.finalPackage]
[
config.finalPackage
config.printInitPackage
]
++ pkgs.lib.optional config.enableMan self.packages.${pkgs.system}.man-docs;
meta.mainProgram = "nvim";
}

0 comments on commit 45d788b

Please sign in to comment.