Skip to content

Commit

Permalink
🚸 Support NixOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Nov 12, 2024
1 parent 1ec87c2 commit 384eb23
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 14 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ jobs:
extra_luarocks_args: |
--force
version: scm
dependencies: |
dbus_proxy >= 0.10.4
lua-cjson
template: template.rockspec
- uses: nvim-neorocks/luarocks-tag-release@v5
env:
LUAROCKS_API_KEY: ${{secrets.LUAROCKS_API_KEY}}
if: startsWith(github.ref, 'refs/tags/')
with:
extra_luarocks_args: |
--force
dependencies: |
dbus_proxy >= 0.10.4
lua-cjson
template: template.rockspec
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: fix-byte-order-marker
Expand Down Expand Up @@ -37,23 +37,23 @@ repos:
args:
- --msg-filename
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: 2.7.3
rev: 3.0.3
hooks:
- id: editorconfig-checker
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: check-mailmap
- repo: https://github.com/rhysd/actionlint
rev: v1.7.1
rev: v1.7.4
hooks:
- id: actionlint
- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
hooks:
- id: yamllint
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
rev: 0.7.18
hooks:
- id: mdformat
additional_dependencies:
Expand All @@ -67,7 +67,7 @@ repos:
- mdformat-config
- mdformat-web
- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.13.0
rev: v0.15.0
hooks:
- id: markdownlint-cli2
additional_dependencies:
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ $ luarocks --lua-version 5.1 --local --tree ~/.local/share/nvim/rocks install im
# you can change it according to your vim.g.rocks_nvim.rocks_path
```

For NixOS, `export $GI_TYPELIB_PATH` in your shell profile to make
`require'dbus_proxy'` work. Refer my
[`~/.bash_profile`](https://github.com/Freed-Wu/Freed-Wu/blob/main/.bash_profile).
## Tips

- For NixOS, `require'dbus_proxy'` needs correct `vim.env.GI_TYPELIB_PATH`. This
plugin will do it out of box.
- For Nix user, run
`/the/path/of/luarocks/rocks-5.1/ime.nvim/VERSION/scripts/update.sh`
when dynamic link libraries are broken after `nix-collect-garbage -d`.
5 changes: 5 additions & 0 deletions lua/ime/get-GI_TYPELIB_PATH.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env -S nix eval --impure -f
let pkgs = import <nixpkgs> { };
in
let suffix = "lib/girepository-1.0";
in "${pkgs.glib.out}/${suffix}:${pkgs.gobject-introspection}/${suffix}:${pkgs.gobject-introspection.unwrapped}/${suffix}"
16 changes: 16 additions & 0 deletions lua/ime/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
-- luacheck: ignore 111 113
---@diagnostic disable: undefined-global
if vim and vim.env.GI_TYPELIB_PATH == nil then
local f = io.open("/run/current-system/nixos-version")
if f then
f:close()
f = io.popen(vim.fs.joinpath(
vim.fs.dirname(debug.getinfo(1).source:match("@?(.*)")),
"get-GI_TYPELIB_PATH.nix"
))
if f then
loadstring("vim.env.GI_TYPELIB_PATH = " .. f:read())()
f:close()
end
end
end
local ok
local backend = nil
for _, name in ipairs {
Expand Down
5 changes: 5 additions & 0 deletions scripts/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -e
cd "$(dirname "$(dirname "$(readlink -f "$0")")")"

nix-shell --run 'luarocks install --force --local lgi'
42 changes: 42 additions & 0 deletions template.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local git_ref = '$git_ref'
local modrev = '$modrev'
local specrev = '$specrev'

local repo_url = '$repo_url'

rockspec_format = '3.0'
package = '$package'
version = modrev ..'-'.. specrev

description = {
summary = '$summary',
detailed = $detailed_description,
labels = $labels,
homepage = '$homepage',
$license
}

dependencies = { 'dbus_proxy >= 0.10.4', 'lua-cjson' }

test_dependencies = $test_dependencies

source = {
url = repo_url .. '/archive/' .. git_ref .. '.zip',
dir = '$repo_name-' .. '$archive_dir_suffix',
}

if modrev == 'scm' or modrev == 'dev' then
source = {
url = repo_url:gsub('https', 'git')
}
end

build = {
type = 'builtin',
copy_directories = { 'plugin', 'scripts' },
install = {
conf = {
['..'] = 'shell.nix'
}
}
}

0 comments on commit 384eb23

Please sign in to comment.