Skip to content

Instantly share code, notes, and snippets.

@unclechu
Created August 20, 2021 13:34
Show Gist options
  • Save unclechu/f8d19a4e71a4641c02e5adbbfe064265 to your computer and use it in GitHub Desktop.
Save unclechu/f8d19a4e71a4641c02e5adbbfe064265 to your computer and use it in GitHub Desktop.

Revisions

  1. unclechu created this gist Aug 20, 2021.
    25 changes: 25 additions & 0 deletions neovim.nix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    # How to use/test:
    # nix-build neovim.nix -o neovim
    # neovim/bin/nvim

    let
    nixpkgs-unstable-pin = fetchTarball {
    url = "https://releases.nixos.org/nixos/unstable/nixos-21.11pre308897.e41ba381140/nixexprs.tar.xz";
    sha256 = "1smkm0z569lp321m7jsyy1fvnvl2nc8vh2nak946r9fd4hl4px4p";
    };
    in
    { pkgs ? import nixpkgs-unstable-pin {}
    }:
    let
    inherit (pkgs) callPackage lib makeWrapper symlinkJoin neovim;
    perlForNeovim = callPackage ./perl.nix {};
    in
    symlinkJoin {
    name = "${lib.getName neovim}-wrapper";
    nativeBuildInputs = [ makeWrapper ];
    paths = [ neovim ];
    postBuild = ''
    wrapProgram "$out"/bin/nvim \
    --prefix PATH : ${lib.escapeShellArg (lib.makeBinPath [ perlForNeovim ])}
    '';
    }
    58 changes: 58 additions & 0 deletions perl-dependencies.nix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    # Author: Viacheslav Lotsmanov
    # License: MIT https://raw.githubusercontent.com/unclechu/neovimrc/master/LICENSE

    # This module is intended to be called with ‘nixpkgs.callPackage’
    { fetchurl, lib, buildPerlPackage, perlPackages }:
    with perlPackages;
    rec {
    # Automatically generated using “nix-generate-from-cpan Neovim::Ext”
    NeovimExt = buildPerlPackage {
    pname = "Neovim-Ext";
    version = "0.05";
    src = fetchurl {
    url = "mirror://cpan/authors/id/J/JA/JACQUESG/Neovim-Ext-0.05.tar.gz";
    sha256 = "9f3d91b040ed218b4d9523708c680533b33b4e81efcaf3e6c01ae51da2bfdd2c";
    };
    buildInputs = [ ArchiveZip FileSlurper FileWhich ProcBackground TestPod TestPodCoverage ];
    propagatedBuildInputs = [ ClassAccessor EvalSafe IOAsync MsgPackRaw ];
    meta = {
    description = "Perl bindings for neovim";
    license = with lib.licenses; [ artistic1 gpl1Plus ];
    };

    # The test is huge and it fails. It tries to download Neovim executable binary. Insane.
    doCheck = false;
    };

    # A dependency of “NeovimExt”
    EvalSafe = buildPerlPackage {
    pname = "Eval-Safe";
    version = "0.02";
    src = fetchurl {
    url = "mirror://cpan/authors/id/M/MA/MATHIAS/Eval-Safe/Eval-Safe-0.02.tar.gz";
    sha256 = "55a52c233e2dae86113f9f19b34f617edcfc8416f9bece671267bd1811b12111";
    };
    meta = {
    description = "Simplified safe evaluation of Perl code";
    license = lib.licenses.mit;
    };

    # Bug fix when “*-devdoc” package is not found
    outputs = [ "out" "dev" ];
    };

    # A dependency of “NeovimExt”
    MsgPackRaw = buildPerlPackage {
    pname = "MsgPack-Raw";
    version = "0.05";
    src = fetchurl {
    url = "mirror://cpan/authors/id/J/JA/JACQUESG/MsgPack-Raw-0.05.tar.gz";
    sha256 = "8559e2b64cd98d99abc666edf2a4c8724c9534612616af11f4eb0bbd0d422dac";
    };
    buildInputs = [ TestPod TestPodCoverage ];
    meta = {
    description = "Perl bindings to the msgpack C library";
    license = with lib.licenses; [ artistic1 gpl1Plus ];
    };
    };
    }
    46 changes: 46 additions & 0 deletions perl.nix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    # Author: Viacheslav Lotsmanov
    # License: MIT https://raw.githubusercontent.com/unclechu/neovimrc/master/LICENSE

    # This module is intended to be called with ‘nixpkgs.callPackage’
    { callPackage
    , makeWrapper
    , symlinkJoin
    , lib

    , perl
    , perlPackages

    # Overridable dependencies
    , localPerlDependencies ? callPackage ./perl-pependencies.nix {}

    # Build options
    , extraPerlDependencies ? []
    }:
    let
    perlDeps = [
    localPerlDependencies.NeovimExt
    perlPackages.Appcpanminus # Neovim :checkhealth reports it’s missing
    perlPackages.locallib
    ] ++ extraPerlDependencies;

    # This is a hack to have no warnings in “:checkhealth” in Neovim.
    # Obtained initially from “perl -I ~/perl5/lib/perl5/ -Mlocal::lib”.
    localLibVars = lib.splitString "\n" ''
    export PATH="''${HOME}/perl5/bin''${PATH:+:''${PATH}}"
    export PERL5LIB="''${HOME}/perl5/lib/perl5''${PERL5LIB:+:''${PERL5LIB}}"
    export PERL_LOCAL_LIB_ROOT="''${HOME}/perl5''${PERL_LOCAL_LIB_ROOT:+:''${PERL_LOCAL_LIB_ROOT}}"
    export PERL_MB_OPT="--install_base \"''${HOME}/perl5\""
    export PERL_MM_OPT="INSTALL_BASE=''${HOME}/perl5"
    '';
    in
    symlinkJoin {
    name = "perl-for-neovim";
    nativeBuildInputs = [ makeWrapper ];
    paths = [ perl ];
    postBuild = ''
    wrapProgram "$out"/bin/perl --prefix PERL5LIB : ${perlPackages.makeFullPerlPath perlDeps} ${
    builtins.concatStringsSep " "
    (map (x: "--run " + lib.escapeShellArg x) localLibVars)
    }
    '';
    }