From 21c233919d747d3375e3a173b65f7f26ccf01256 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 13 Apr 2024 08:40:47 +0100 Subject: [PATCH] output: format init.lua --- lib/builders.nix | 30 ++++++++++++++++++++++++++++++ lib/helpers.nix | 2 ++ wrappers/modules/output.nix | 3 ++- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 lib/builders.nix diff --git a/lib/builders.nix b/lib/builders.nix new file mode 100644 index 00000000..c19d1bd9 --- /dev/null +++ b/lib/builders.nix @@ -0,0 +1,30 @@ +{ + lib, + pkgs, +}: { + /* + Write a lua file to the nix store, formatted using stylua. + + # Type + + ``` + writeLua :: String -> String -> Derivation + ``` + + # Arguments + + - [name] The name of the derivation + - [text] The content of the lua file + */ + writeLua = name: text: + pkgs.runCommand name {inherit text;} '' + echo -n "$text" > "$out" + + ${lib.getExe pkgs.stylua} \ + --no-editorconfig \ + --line-endings Unix \ + --indent-type Spaces \ + --indent-width 4 \ + "$out" + ''; +} diff --git a/lib/helpers.nix b/lib/helpers.nix index 4103c115..5b8e5f70 100644 --- a/lib/helpers.nix +++ b/lib/helpers.nix @@ -4,6 +4,7 @@ _nixvimTests, ... }: let + nixvimBuilders = import ./builders.nix {inherit lib pkgs;}; nixvimTypes = import ./types.nix {inherit lib nixvimOptions;}; nixvimUtils = import ./utils.nix {inherit lib _nixvimTests;}; nixvimOptions = import ./options.nix {inherit lib nixvimTypes nixvimUtils;}; @@ -20,3 +21,4 @@ in } // nixvimUtils // nixvimOptions + // nixvimBuilders diff --git a/wrappers/modules/output.nix b/wrappers/modules/output.nix index 74e7ed55..f2c6db7e 100644 --- a/wrappers/modules/output.nix +++ b/wrappers/modules/output.nix @@ -2,6 +2,7 @@ pkgs, config, lib, + helpers, ... }: with lib; { @@ -115,7 +116,7 @@ with lib; { '' + config.content; - init = pkgs.writeText "init.lua" customRC; + init = helpers.writeLua "init.lua" customRC; initPath = toString init; extraWrapperArgs = builtins.concatStringsSep " " (