|
| 1 | +{ |
| 2 | + nixvim, |
| 3 | + pkgs, |
| 4 | + home-manager, |
| 5 | +}: |
| 6 | +let |
| 7 | + config = { |
| 8 | + home = { |
| 9 | + username = "nixvim"; |
| 10 | + homeDirectory = "/invalid/dir"; |
| 11 | + stateVersion = "24.05"; |
| 12 | + }; |
| 13 | + |
| 14 | + programs.nixvim = { |
| 15 | + enable = true; |
| 16 | + |
| 17 | + performance.byteCompileLua.enable = true; |
| 18 | + |
| 19 | + extraFiles = { |
| 20 | + "extra-files/test1.lua".text = "vim.opt.tabstop = 2"; |
| 21 | + "extra-files/test2.lua".source = builtins.toFile "file_source.lua" "vim.opt.tabstop = 2"; |
| 22 | + "extra-files/test.vim".text = "set tabstop=2"; |
| 23 | + "extra-files/test.json".text = builtins.toJSON { a = 1; }; |
| 24 | + }; |
| 25 | + |
| 26 | + files = { |
| 27 | + "files/test.lua".opts.tabstop = 2; |
| 28 | + "files/test.vim".opts.tabstop = 2; |
| 29 | + }; |
| 30 | + }; |
| 31 | + }; |
| 32 | + |
| 33 | + homeFilesByteCompilingEnabled = |
| 34 | + (home-manager.lib.homeManagerConfiguration { |
| 35 | + inherit pkgs; |
| 36 | + |
| 37 | + modules = [ |
| 38 | + nixvim.homeManagerModules.nixvim |
| 39 | + config |
| 40 | + { programs.nixvim.performance.byteCompileLua.configs = true; } |
| 41 | + ]; |
| 42 | + }).config.home-files; |
| 43 | + |
| 44 | + homeFilesByteCompilingDisabled = |
| 45 | + (home-manager.lib.homeManagerConfiguration { |
| 46 | + inherit pkgs; |
| 47 | + |
| 48 | + modules = [ |
| 49 | + nixvim.homeManagerModules.nixvim |
| 50 | + config |
| 51 | + { programs.nixvim.performance.byteCompileLua.configs = false; } |
| 52 | + ]; |
| 53 | + }).config.home-files; |
| 54 | +in |
| 55 | +pkgs.runCommand "home-manager-extra-files-byte-compiling" { } '' |
| 56 | + is_binary() { |
| 57 | + ! grep -qI . "$1" |
| 58 | + } |
| 59 | + test_byte_compiled() { |
| 60 | + if ! is_binary "$home_files/.config/nvim/$1"; then |
| 61 | + echo "File $1 is expected to be byte compiled, but it's not" |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | + } |
| 65 | + test_not_byte_compiled() { |
| 66 | + if is_binary "$home_files/.config/nvim/$1"; then |
| 67 | + echo "File $1 is not expected to be byte compiled, but it is" |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | + } |
| 71 | +
|
| 72 | + # Test directory with extraFiles byte compiling enabled |
| 73 | + home_files="${homeFilesByteCompilingEnabled}" |
| 74 | +
|
| 75 | + echo "Testing home-files with extraFiles byte compiling enabled" |
| 76 | +
|
| 77 | + # extraFiles |
| 78 | + test_byte_compiled extra-files/test1.lua |
| 79 | + test_byte_compiled extra-files/test2.lua |
| 80 | + test_not_byte_compiled extra-files/test.vim |
| 81 | + test_not_byte_compiled extra-files/test.json |
| 82 | + # files |
| 83 | + test_byte_compiled files/test.lua |
| 84 | + test_not_byte_compiled files/test.vim |
| 85 | +
|
| 86 | + # Test directory with extraFiles byte compiling disabled |
| 87 | + home_files="${homeFilesByteCompilingDisabled}" |
| 88 | +
|
| 89 | + echo "Testing home-files with extraFiles byte compiling disabled" |
| 90 | +
|
| 91 | + # extraFiles |
| 92 | + test_not_byte_compiled extra-files/test1.lua |
| 93 | + test_not_byte_compiled extra-files/test2.lua |
| 94 | + test_not_byte_compiled extra-files/test.vim |
| 95 | + test_not_byte_compiled extra-files/test.json |
| 96 | + # files |
| 97 | + test_not_byte_compiled files/test.lua |
| 98 | + test_not_byte_compiled files/test.vim |
| 99 | +
|
| 100 | + touch $out |
| 101 | +'' |
0 commit comments