about summary refs log tree commit diff
path: root/pkgs/misc/vim-plugins/vim2nix
diff options
context:
space:
mode:
authorArseniy Seroka <ars.seroka@gmail.com>2016-01-10 13:19:06 +0300
committerArseniy Seroka <ars.seroka@gmail.com>2016-01-10 13:19:06 +0300
commit4a0a0592db45584b61a10ee2a801969f9a6f35ed (patch)
tree6240f2bbbab46d985750ddb89dfbc31ccf66b270 /pkgs/misc/vim-plugins/vim2nix
parentada9b3b666e58158223686be37d8641c42748575 (diff)
downloadnixlib-4a0a0592db45584b61a10ee2a801969f9a6f35ed.tar
nixlib-4a0a0592db45584b61a10ee2a801969f9a6f35ed.tar.gz
nixlib-4a0a0592db45584b61a10ee2a801969f9a6f35ed.tar.bz2
nixlib-4a0a0592db45584b61a10ee2a801969f9a6f35ed.tar.lz
nixlib-4a0a0592db45584b61a10ee2a801969f9a6f35ed.tar.xz
nixlib-4a0a0592db45584b61a10ee2a801969f9a6f35ed.tar.zst
nixlib-4a0a0592db45584b61a10ee2a801969f9a6f35ed.zip
vimPlugins: move vim2nix into nixpkgs repo
Diffstat (limited to 'pkgs/misc/vim-plugins/vim2nix')
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/README.txt3
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/additional-nix-code/command-t7
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/additional-nix-code/matchit.zip7
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/additional-nix-code/racer4
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/additional-nix-code/taglist6
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-addon-manager1
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-hier1
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-wakatime1
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-xdebug1
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-xkbswitch5
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vimproc.vim9
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vimshell.vim1
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/additional-nix-code/youcompleteme24
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/addon-info.json1
-rw-r--r--pkgs/misc/vim-plugins/vim2nix/autoload/nix.vim307
15 files changed, 378 insertions, 0 deletions
diff --git a/pkgs/misc/vim-plugins/vim2nix/README.txt b/pkgs/misc/vim-plugins/vim2nix/README.txt
new file mode 100644
index 000000000000..4263481461f1
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/README.txt
@@ -0,0 +1,3 @@
+Usage see vim-utils.nix in nixpkgs
+
+This code depends on vim-addon-manager
diff --git a/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/command-t b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/command-t
new file mode 100644
index 000000000000..a29c602b5d7e
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/command-t
@@ -0,0 +1,7 @@
+    buildInputs = [ perl ruby ];
+    buildPhase = ''
+      pushd ruby/command-t
+      ruby extconf.rb
+      make
+      popd
+    '';
diff --git a/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/matchit.zip b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/matchit.zip
new file mode 100644
index 000000000000..cc9d3fb72640
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/matchit.zip
@@ -0,0 +1,7 @@
+    unpackPhase = ''
+      (
+       sourceRoot=d
+       mkdir $sourceRoot; cd $sourceRoot;
+       unzip $src
+      )
+    '';
diff --git a/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/racer b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/racer
new file mode 100644
index 000000000000..57000b870645
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/racer
@@ -0,0 +1,4 @@
+    buildPhase = ''
+      find . -type f -not -name 'racer.vim' -exec rm -rf {} \;
+      rm -rf editors images src
+    '';
diff --git a/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/taglist b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/taglist
new file mode 100644
index 000000000000..90f6e3367a3b
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/taglist
@@ -0,0 +1,6 @@
+    setSourceRoot = ''
+      export sourceRoot=taglist
+      mkdir taglist
+      mv doc taglist
+      mv plugin taglist
+    '';
diff --git a/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-addon-manager b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-addon-manager
new file mode 100644
index 000000000000..e3d8dfb69210
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-addon-manager
@@ -0,0 +1 @@
+    buildInputs = stdenv.lib.optional stdenv.isDarwin Cocoa;
diff --git a/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-hier b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-hier
new file mode 100644
index 000000000000..d1f756a99d3b
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-hier
@@ -0,0 +1 @@
+    buildInputs = [ vim ];
diff --git a/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-wakatime b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-wakatime
new file mode 100644
index 000000000000..31ffa7f8ff97
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-wakatime
@@ -0,0 +1 @@
+    buildInputs = [ python ];
diff --git a/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-xdebug b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-xdebug
new file mode 100644
index 000000000000..62a3c22c0369
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-xdebug
@@ -0,0 +1 @@
+    postInstall = false;
diff --git a/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-xkbswitch b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-xkbswitch
new file mode 100644
index 000000000000..4e73ac9a73b3
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vim-xkbswitch
@@ -0,0 +1,5 @@
+    patchPhase = ''
+      substituteInPlace plugin/xkbswitch.vim \
+              --replace /usr/local/lib/libxkbswitch.so ${xkb_switch}/lib/libxkbswitch.so
+    '';
+    buildInputs = [ xkb_switch ];
diff --git a/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vimproc.vim b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vimproc.vim
new file mode 100644
index 000000000000..e720559fa3d6
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vimproc.vim
@@ -0,0 +1,9 @@
+    buildInputs = [ which ];
+
+    buildPhase = ''
+      substituteInPlace autoload/vimproc.vim \
+        --replace vimproc_mac.so vimproc_unix.so \
+        --replace vimproc_linux64.so vimproc_unix.so \
+        --replace vimproc_linux32.so vimproc_unix.so
+      make -f make_unix.mak
+    '';
diff --git a/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vimshell.vim b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vimshell.vim
new file mode 100644
index 000000000000..5be233050793
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/vimshell.vim
@@ -0,0 +1 @@
+    dependencies = [ "vimproc-vim" ];
diff --git a/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/youcompleteme b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/youcompleteme
new file mode 100644
index 000000000000..625dfcb4f3ee
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/youcompleteme
@@ -0,0 +1,24 @@
+    buildInputs = [
+      python go cmake
+      (if stdenv.isDarwin then llvmPackages.clang else llvmPackages.clang-unwrapped)
+      llvmPackages.llvm
+    ] ++ stdenv.lib.optional stdenv.isDarwin Cocoa;
+
+    buildPhase = ''
+      patchShebangs .
+
+      mkdir build
+      pushd build
+      cmake -G "Unix Makefiles" . ../third_party/ycmd/cpp -DPYTHON_LIBRARIES:PATH=${python}/lib/libpython2.7.so -DPYTHON_INCLUDE_DIR:PATH=${python}/include/python2.7 -DUSE_CLANG_COMPLETER=ON -DUSE_SYSTEM_LIBCLANG=ON
+      make ycm_support_libs -j''${NIX_BUILD_CORES} -l''${NIX_BUILD_CORES}}
+      ${python}/bin/python ../third_party/ycmd/build.py --gocode-completer --clang-completer --system-libclang
+      popd
+    '';
+
+    meta = {
+      description = "Fastest non utf-8 aware word and C completion engine for Vim";
+      homepage = http://github.com/Valloric/YouCompleteMe;
+      license = stdenv.lib.licenses.gpl3;
+      maintainers = with stdenv.lib.maintainers; [marcweber jagajaga];
+      platforms = stdenv.lib.platforms.linux;
+    };
diff --git a/pkgs/misc/vim-plugins/vim2nix/addon-info.json b/pkgs/misc/vim-plugins/vim2nix/addon-info.json
new file mode 100644
index 000000000000..93ca9bc129b5
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/addon-info.json
@@ -0,0 +1 @@
+{'dependencies': {'vim-addon-manager': {}}}
diff --git a/pkgs/misc/vim-plugins/vim2nix/autoload/nix.vim b/pkgs/misc/vim-plugins/vim2nix/autoload/nix.vim
new file mode 100644
index 000000000000..376b7c674d6c
--- /dev/null
+++ b/pkgs/misc/vim-plugins/vim2nix/autoload/nix.vim
@@ -0,0 +1,307 @@
+" usage example:
+"
+" call nix#ExportPluginsForNix({'path_to_nixpkgs': '/etc/nixos/nixpkgs', 'names': ["vim-addon-manager", "vim-addon-nix"], 'cache_file': 'cache'})
+let s:plugin_root = expand('<sfile>:h:h')
+
+fun! nix#ToNixAttrName(s) abort
+    return nix#ToNixName(a:s)
+endf
+
+fun! nix#ToNixName(s) abort
+  return substitute(substitute(a:s, '[:/.]', '-', 'g'), 'github-', '', 'g')
+endf
+
+fun! s:System(...)
+  let args = a:000
+  let r = call('vam#utils#System', args)
+  if r is 0
+    throw "command ".join(args, '').' failed'
+  else
+    return r
+  endif
+endf
+
+fun! nix#DependenciesFromCheckout(opts, name, repository, dir)
+  " check for dependencies
+  " vam#PluginDirFromName(a:name)
+  let info = vam#ReadAddonInfo(vam#AddonInfoFile(a:dir, a:name))
+  return keys(get(info, 'dependencies', {}))
+endf
+
+
+" without deps
+fun! nix#NixDerivation(opts, name, repository) abort
+  let n_a_name = nix#ToNixAttrName(a:name)
+  let n_n_name = nix#ToNixName(a:name)
+  let type = get(a:repository, 'type', '')
+  let created_notice = " # created by nix#NixDerivation"
+
+  let ancf = s:plugin_root.'/additional-nix-code/'.a:name
+  let additional_nix_code = file_readable(ancf) ? join(readfile(ancf), "\n") : ""
+
+  if type == 'git'
+    " should be using shell abstraction ..
+    echo 'fetching '. a:repository.url
+    let s = s:System('$ --fetch-submodules $ 2>&1',a:opts.nix_prefetch_git, a:repository.url)
+    let rev = matchstr(s, 'git revision is \zs[^\n\r]\+\ze')
+    let sha256 = matchstr(s, 'hash is \zs[^\n\r]\+\ze')
+    let dir = matchstr(s, 'path is \zs[^\n\r]\+\ze')
+    let date = matchstr(s, 'Commit date is \zs[0-9-]\+\ze')
+
+    let dependencies = nix#DependenciesFromCheckout(a:opts, a:name, a:repository, dir)
+    return {'n_a_name': n_a_name, 'n_n_name': n_n_name, 'dependencies': dependencies, 'derivation': join([
+          \ '  '.n_a_name.' = buildVimPluginFrom2Nix {'.created_notice,
+          \ '    name = "'.n_n_name.'-'.date.'";',
+          \ '    src = fetchgit {',
+          \ '      url = "'. a:repository.url .'";',
+          \ '      rev = "'.rev.'";',
+          \ '      sha256 = "'.sha256.'";',
+          \ '    };',
+          \ '    dependencies = ['.join(map(copy(dependencies), "'\"'.nix#ToNixAttrName(v:val).'\"'")).'];',
+          \ additional_nix_code,
+          \ '  };',
+          \ '',
+          \ '',
+          \ ], "\n")}
+
+  elseif type == 'hg'
+    " should be using shell abstraction ..
+    echo 'fetching '. a:repository.url
+    let s = s:System('$ $ 2>&1',a:opts.nix_prefetch_hg, a:repository.url)
+    let rev = matchstr(s, 'hg revision is \zs[^\n\r]\+\ze')
+    let sha256 = matchstr(s, 'hash is \zs[^\n\r]\+\ze')
+    let dir = matchstr(s, 'path is \zs[^\n\r]\+\ze')
+
+    let dependencies = nix#DependenciesFromCheckout(a:opts, a:name, a:repository, dir)
+    return {'n_a_name': n_a_name, 'n_n_name': n_n_name, 'dependencies': dependencies, 'derivation':  join([
+          \ '  '.n_a_name.' = buildVimPluginFrom2Nix {'.created_notice,
+          \ '    name = "'.n_n_name.'";',
+          \ '    src = fetchhg {',
+          \ '      url = "'. a:repository.url .'";',
+          \ '      rev = "'.rev.'";',
+          \ '      sha256 = "'.sha256.'";',
+          \ '    };',
+          \ '    dependencies = ['.join(map(copy(dependencies), "'\"'.nix#ToNixAttrName(v:val).'\"'")).'];',
+          \ additional_nix_code,
+          \ '  };',
+          \ '',
+          \ '',
+          \ ], "\n")}
+
+  elseif type == 'archive'
+    let sha256 = split(s:System('nix-prefetch-url $ 2>/dev/null', a:repository.url), "\n")[0]
+    " we should unpack the sources, look for the addon-info.json file ..
+    " however most packages who have the addon-info.json file also are on
+    " github thus will be of type "git" instead. The dependency information
+    " from vim-pi is encoded in the reposiotry. Thus this is likely to do the
+    " right thing most of the time.
+    let addon_info = get(a:repository, 'addon-info', {})
+    let dependencies = keys(get(addon_info, 'dependencies', {}))
+
+    return {'n_a_name': n_a_name, 'n_n_name': n_n_name, 'dependencies': dependencies, 'derivation':  join([
+          \ '  '.n_a_name.' = buildVimPluginFrom2Nix {'.created_notice,
+          \ '    name = "'.n_n_name.'";',
+          \ '    src = fetchurl {',
+          \ '      url = "'. a:repository.url .'";',
+          \ '      name = "'. a:repository.archive_name .'";',
+          \ '      sha256 = "'.sha256.'";',
+          \ '    };',
+          \ '    buildInputs = [ unzip ];',
+          \ '    dependencies = ['.join(map(copy(dependencies), "'\"'.nix#ToNixAttrName(v:val).'\"'")).'];',
+          \ '    meta = {',
+          \ '       url = "http://www.vim.org/scripts/script.php?script_id='.a:repository.vim_script_nr.'";',
+          \ '    };',
+          \ addon_info == {} ? '' : ('    addon_info = '.nix#ToNix(string(addon_info), [], "").';'),
+          \ additional_nix_code,
+          \ '  };',
+          \ '',
+          \ '',
+          \ ], "\n")}
+  else
+    throw a:name.' TODO: implement source '.string(a:repository)
+  endif
+endf
+
+" also tries to handle dependencies
+fun! nix#AddNixDerivation(opts, cache, name, ...) abort
+  if has_key(a:cache, a:name) | return | endif
+  let repository = a:0 > 0 ? a:1 : {}
+  let name = a:name
+
+  if repository == {}
+    call vam#install#LoadPool()
+    let list = matchlist(a:name, 'github:\([^/]*\)\%(\/\(.*\)\)\?$')
+    if len(list) > 0
+      if '' != list[2]
+        let name = list[2]
+        let repository = { 'type': 'git', 'owner': list[1], 'repo': list[2], 'url': 'git://github.com/'.list[1].'/'.list[2] }
+      else
+        let name = list[1]
+        let repository = { 'type': 'git', 'owner': list[1], 'repo': 'vim-addon-'.list[1], 'url': 'git://github.com/'.list[1].'/vim-addon-'.list[1] }
+      endif
+    else
+      let repository = get(g:vim_addon_manager.plugin_sources, a:name, {})
+      if repository == {}
+        throw "repository ".a:name." unkown!"
+      else
+          if repository.url =~ 'github'
+            let owner = matchstr(repository.url, 'github.com/\zs.\+\ze/')
+            let repo = matchstr(repository.url, '\/\zs[^\/]\+\ze$')
+            let url = repository.url
+            let repository = { 'type': 'git', 'owner': owner, 'repo': repo, 'url': url }
+          endif
+      endif
+    endif
+  endif
+
+  let a:cache[a:name] = nix#NixDerivation(a:opts, name, repository)
+
+  " take known dependencies into account:
+  let deps = get(a:cache[a:name], 'dependencies', [])
+  call extend(a:opts.names_to_process, deps)
+  call extend(a:opts.names_to_export,  deps)
+endfun
+
+fun! nix#TopNixOptsByParent(parents)
+  if (a:parents == [])
+    return {'ind': '  ', 'next_ind': '    ', 'sep': "\n"}
+  else
+    return {'ind': '', 'next_ind': '', 'sep': ' '}
+  endif
+endf
+
+fun! nix#ToNix(x, parents, opts_fun) abort
+  let opts = a:opts_fun == "" ? "" : call(a:opts_fun, [a:parents])
+  let next_parents = [a:x] + a:parents
+  let seps = a:0 > 1 ? a:2 : []
+
+  let ind = get(opts, 'ind', '')
+  let next_ind = get(opts, 'next_ind', ind.'  ')
+  let sep = get(opts, 'sep', ind.'  ')
+
+  if type(a:x) == type("")
+    return "''". substitute(a:x, '[$]', '$$', 'g')."''"
+  elseif type(a:x) == type({})
+    let s = ind."{".sep
+    for [k,v] in items(a:x)
+      let s .= '"'.k.'" = '.nix#ToNix(v, next_parents, a:opts_fun).";".sep
+      unlet k v
+    endfor
+    return  s.ind."}"
+
+    " let s = ind."{\n"
+    " for [k,v] in items(a:x)
+    "   let s .= next_ind . nix#ToNix(k).' = '.nix#ToNix(v, next_ind)."\n"
+    "   unlet k v
+    " endfor
+    " return  s.ind."}\n"
+  elseif type(a:x) == type([])
+    let s = ind."[".sep
+    for v in a:x
+      let s .= next_ind . nix#ToNix(v, next_parents, a:opts_fun)."".sep
+      unlet v
+    endfor
+    return s.ind."]"
+  endif
+endf
+
+
+" with dependencies
+" opts.cache_file (caches the checkout and dependency information
+" opts.path_to_nixpkgs or  opts.nix_prefetch_{git,hg}
+" opts.plugin_dictionaries: list of any
+"     - string
+"     - dictionary having key name or names
+" This is so that plugin script files can be loaded/ merged
+fun! nix#ExportPluginsForNix(opts) abort
+  let cache_file = get(a:opts, 'cache_file', '')
+
+  let opts = a:opts
+
+  " set nix_prefetch_* scripts
+  for scm in ['git', 'hg']
+    if !has_key(opts, 'nix_prefetch_'.scm)
+      let opts['nix_prefetch_'.scm] = a:opts.path_to_nixpkgs.'/pkgs/build-support/fetch'.scm.'/nix-prefetch-'.scm
+    endif
+  endfor
+
+  " create list of names from dictionaries
+  let a:opts.names_to_process = []
+  for x in a:opts.plugin_dictionaries
+    if type(x) == type('')
+      call add(opts.names_to_process, x)
+    elseif type(x) == type({}) && has_key(x, 'name')
+      call add(opts.names_to_process, x.name)
+    elseif type(x) == type({}) && has_key(x, 'names')
+      call extend(opts.names_to_process, x.names)
+    else
+      throw "unexpected"
+    endif
+    unlet x
+  endfor
+  let a:opts.names_to_export = a:opts.names_to_process
+
+  let cache = (cache_file == '' || !filereadable(cache_file)) ? {} : eval(readfile(cache_file)[0])
+  let failed = {}
+  while len(opts.names_to_process) > 0
+    let name = opts.names_to_process[0]
+    if get(opts, 'try_catch', 1)
+      try
+        call nix#AddNixDerivation(opts, cache, name)
+      catch /.*/
+        echom 'failed : '.name.' '.v:exception
+        let failed[name] = v:exception
+      endtry
+    else
+      call nix#AddNixDerivation(opts, cache, name)
+    endif
+    let opts.names_to_process = opts.names_to_process[1:]
+  endwhile
+  echom join(keys(failed), ", ")
+  echom string(failed)
+
+  if cache_file != ''
+    call writefile([string(cache)], cache_file)
+  endif
+
+  enew
+
+  let uniq = {}
+  for x in a:opts.names_to_export
+    let uniq[x] = 1
+  endfor
+
+  for k in sort(keys(uniq))
+    call append('$', split(cache[k].derivation,"\n"))
+  endfor
+
+  " for VAM users output vam.pluginDictionaries which can be fed to
+  " vim_customizable.customize.vimrc.vam.pluginDictionaries
+  call append('$', ["", "", "", '# vam.pluginDictionaries'])
+
+  let ns = []
+  for x in a:opts.plugin_dictionaries
+    if type(x) == type("")
+      call add(ns, nix#ToNixAttrName(x))
+    elseif type(x) == type({})
+      if has_key(x, 'name')
+        call add(ns, extend({'name': nix#ToNixAttrName(x.name)}, x, "keep"))
+      elseif has_key(x, 'names')
+        call add(ns, extend({'names': map(copy(x.names), 'nix#ToNixAttrName(v:val)')}, x, "keep"))
+      else
+        throw "unexpected"
+      endif
+    else
+      throw "unexpected"
+    endif
+    unlet x
+  endfor
+
+  call append('$', split(nix#ToNix(ns, [], 'nix#TopNixOptsByParent'), "\n"))
+
+  " failures:
+  for [k,v] in items(failed)
+    call append('$', ['# '.k.', failure: '.v])
+    unlet k v
+  endfor
+endf