From e9158314725af06854009b829d2249d0d6c23c79 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 3 Jul 2024 17:36:14 -0400 Subject: [PATCH] yazi: allow literal string for `initLua` --- modules/programs/yazi.nix | 9 +++++++-- tests/modules/programs/yazi/default.nix | 1 + tests/modules/programs/yazi/init-lua-string.nix | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/modules/programs/yazi/init-lua-string.nix diff --git a/modules/programs/yazi.nix b/modules/programs/yazi.nix index 105bbec4..d7b88020 100644 --- a/modules/programs/yazi.nix +++ b/modules/programs/yazi.nix @@ -141,7 +141,7 @@ in { }; initLua = mkOption { - type = with types; nullOr path; + type = with types; nullOr (either path lines); default = null; description = '' The init.lua for Yazi itself. @@ -210,7 +210,12 @@ in { "yazi/theme.toml" = mkIf (cfg.theme != { }) { source = tomlFormat.generate "yazi-theme" cfg.theme; }; - "yazi/init.lua" = mkIf (cfg.initLua != null) { source = cfg.initLua; }; + "yazi/init.lua" = mkIf (cfg.initLua != null) + (if builtins.isPath cfg.initLua then { + source = cfg.initLua; + } else { + text = cfg.initLua; + }); } // (mapAttrs' (name: value: nameValuePair "yazi/flavors/${name}.yazi" { source = value; }) cfg.flavors) // (mapAttrs' (name: value: diff --git a/tests/modules/programs/yazi/default.nix b/tests/modules/programs/yazi/default.nix index 09d52ac3..ec543c84 100644 --- a/tests/modules/programs/yazi/default.nix +++ b/tests/modules/programs/yazi/default.nix @@ -1,5 +1,6 @@ { yazi-settings = ./settings.nix; + yazi-init-lua-string = ./init-lua-string.nix; yazi-bash-integration-enabled = ./bash-integration-enabled.nix; yazi-zsh-integration-enabled = ./zsh-integration-enabled.nix; yazi-fish-integration-enabled = ./fish-integration-enabled.nix; diff --git a/tests/modules/programs/yazi/init-lua-string.nix b/tests/modules/programs/yazi/init-lua-string.nix new file mode 100644 index 00000000..999dd6bc --- /dev/null +++ b/tests/modules/programs/yazi/init-lua-string.nix @@ -0,0 +1,14 @@ +{ ... }: { + programs.yazi = { + enable = true; + + initLua = builtins.readFile ./init.lua; + }; + + test.stubs.yazi = { }; + + nmt.script = '' + assertFileContent home-files/.config/yazi/init.lua \ + ${./init.lua} + ''; +}