Merge pull request #283648 from mattpolzin/idris2-lsp

idris2Packages.idris2Lsp: init at 2024-01-21
This commit is contained in:
Fabián Heredia Montiel 2024-01-25 19:21:38 -06:00 committed by GitHub
commit b975d1413e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 102 additions and 44 deletions

View File

@ -2,7 +2,7 @@
In addition to exposing the Idris2 compiler itself, Nixpkgs exposes an `idris2Packages.buildIdris` helper to make it a bit more ergonomic to build Idris2 executables or libraries.
The `buildIdris` function takes a package set that defines at a minimum the `src` and `projectName` of the package to be built and any `idrisLibraries` required to build it. The `src` is the same source you're familiar with but the `projectName` must be the name of the `ipkg` file for the project (omitting the `.ipkg` extension). The `idrisLibraries` is a list of other library derivations created with `buildIdris`. You can optionally specify other derivation properties as needed but sensible defaults for `configurePhase`, `buildPhase`, and `installPhase` are provided.
The `buildIdris` function takes an attribute set that defines at a minimum the `src` and `ipkgName` of the package to be built and any `idrisLibraries` required to build it. The `src` is the same source you're familiar with and the `ipkgName` must be the name of the `ipkg` file for the project (omitting the `.ipkg` extension). The `idrisLibraries` is a list of other library derivations created with `buildIdris`. You can optionally specify other derivation properties as needed but sensible defaults for `configurePhase`, `buildPhase`, and `installPhase` are provided.
Importantly, `buildIdris` does not create a single derivation but rather an attribute set with two properties: `executable` and `library`. The `executable` property is a derivation and the `library` property is a function that will return a derivation for the library with or without source code included. Source code need not be included unless you are aiming to use IDE or LSP features that are able to jump to definitions within an editor.
@ -10,7 +10,7 @@ A simple example of a fully packaged library would be the [`LSP-lib`](https://gi
```nix
{ fetchFromGitHub, idris2Packages }:
let lspLibPkg = idris2Packages.buildIdris {
projectName = "lsp-lib";
ipkgName = "lsp-lib";
src = fetchFromGitHub {
owner = "idris-community";
repo = "LSP-lib";
@ -31,7 +31,7 @@ A slightly more involved example of a fully packaged executable would be the [`i
# Assuming the previous example lives in `lsp-lib.nix`:
let lspLib = callPackage ./lsp-lib.nix { };
lspPkg = idris2Packages.buildIdris {
projectName = "idris2-lsp";
ipkgName = "idris2-lsp";
src = fetchFromGitHub {
owner = "idris-community";
repo = "idris2-lsp";

View File

@ -1,9 +1,9 @@
{ stdenv, lib, idris2
{ stdenv, lib, idris2, makeWrapper
}:
# Usage: let
# pkg = idris2Packages.buildIdris {
# src = ...;
# projectName = "my-pkg";
# ipkgName = "my-pkg";
# idrisLibraries = [ ];
# };
# in {
@ -12,62 +12,75 @@
# }
#
{ src
, projectName
, ipkgName
, version ? "unversioned"
, idrisLibraries # Other libraries built with buildIdris
, ... }@attrs:
let
ipkgName = projectName + ".ipkg";
ipkgFileName = ipkgName + ".ipkg";
idrName = "idris2-${idris2.version}";
libSuffix = "lib/${idrName}";
libDirs =
lib.makeSearchPath libSuffix idrisLibraries;
drvAttrs = builtins.removeAttrs attrs [ "idrisLibraries" ];
(lib.makeSearchPath libSuffix idrisLibraries) +
":${idris2}/${idrName}";
supportDir = "${idris2}/${idrName}/lib";
drvAttrs = builtins.removeAttrs attrs [
"ipkgName"
"idrisLibraries"
];
sharedAttrs = {
name = projectName;
sharedAttrs = drvAttrs // {
pname = ipkgName;
inherit version;
src = src;
nativeBuildInputs = [ idris2 ];
nativeBuildInputs = [ idris2 makeWrapper ] ++ attrs.nativeBuildInputs or [];
buildInputs = idrisLibraries ++ attrs.buildInputs or [];
IDRIS2_PACKAGE_PATH = libDirs;
configurePhase = ''
runHook preConfigure
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
idris2 --build ${ipkgName}
idris2 --build ${ipkgFileName}
runHook postBuild
'';
};
in {
executable = stdenv.mkDerivation (lib.attrsets.mergeAttrsList [
sharedAttrs
{ installPhase = ''
runHook preInstall
mkdir -p $out/bin
mv build/exec/* $out/bin
runHook postInstall
'';
}
drvAttrs
]);
executable = stdenv.mkDerivation (sharedAttrs // {
installPhase = ''
runHook preInstall
mkdir -p $out/bin
scheme_app="$(find ./build/exec -name '*_app')"
if [ "$scheme_app" = ''' ]; then
mv -- build/exec/* $out/bin/
chmod +x $out/bin/*
# ^ remove after Idris2 0.8.0 is released. will be superfluous:
# https://github.com/idris-lang/Idris2/pull/3189
else
cd build/exec/*_app
rm -f ./libidris2_support.so
for file in *.so; do
bin_name="''${file%.so}"
mv -- "$file" "$out/bin/$bin_name"
wrapProgram "$out/bin/$bin_name" \
--prefix LD_LIBRARY_PATH : ${supportDir} \
--prefix DYLD_LIBRARY_PATH : ${supportDir}
done
fi
runHook postInstall
'';
});
library = { withSource ? false }:
let installCmd = if withSource then "--install-with-src" else "--install";
in stdenv.mkDerivation (lib.attrsets.mergeAttrsList [
sharedAttrs
{
installPhase = ''
runHook preInstall
mkdir -p $out/${libSuffix}
export IDRIS2_PREFIX=$out/lib
idris2 ${installCmd} ${ipkgName}
runHook postInstall
'';
}
drvAttrs
]);
in stdenv.mkDerivation (sharedAttrs // {
installPhase = ''
runHook preInstall
mkdir -p $out/${libSuffix}
export IDRIS2_PREFIX=$out/lib
idris2 ${installCmd} ${ipkgFileName}
runHook postInstall
'';
});
}

View File

@ -5,12 +5,13 @@
let
in {
idris2 = callPackage ./idris2.nix { };
idris2Lsp = callPackage ./idris2-lsp.nix { };
buildIdris = callPackage ./build-idris.nix { };
idris2Api = (idris2Packages.buildIdris {
inherit (idris2Packages.idris2) src;
projectName = "idris2api";
inherit (idris2Packages.idris2) src version;
ipkgName = "idris2api";
idrisLibraries = [ ];
preBuild = ''
export IDRIS2_PREFIX=$out/lib

View File

@ -0,0 +1,44 @@
{ fetchFromGitHub, idris2Packages, makeWrapper }:
let
globalLibraries = let
idrName = "idris2-${idris2Packages.idris2.version}";
libSuffix = "lib/${idrName}";
in [
"\\$HOME/.nix-profile/lib/${idrName}"
"/run/current-system/sw/lib/${idrName}"
"${idris2Packages.idris2}/${idrName}"
];
globalLibrariesPath = builtins.concatStringsSep ":" globalLibraries;
idris2Api = idris2Packages.idris2Api { };
lspLib = (idris2Packages.buildIdris {
ipkgName = "lsp-lib";
version = "2024-01-21";
src = fetchFromGitHub {
owner = "idris-community";
repo = "LSP-lib";
rev = "03851daae0c0274a02d94663d8f53143a94640da";
hash = "sha256-ICW9oOOP70hXneJFYInuPY68SZTDw10dSxSPTW4WwWM=";
};
idrisLibraries = [ ];
}).library { };
lspPkg = idris2Packages.buildIdris {
ipkgName = "idris2-lsp";
version = "2024-01-21";
src = fetchFromGitHub {
owner = "idris-community";
repo = "idris2-lsp";
rev = "a77ef2d563418925aa274fa29f06880dde43f4ec";
hash = "sha256-zjfVfkpiQS9AdmTfq0hYRSelJq5Caa9VGTuFLtSvl5o=";
};
idrisLibraries = [idris2Api lspLib];
buildInputs = [makeWrapper];
postInstall = ''
wrapProgram $out/bin/idris2-lsp \
--suffix IDRIS2_PACKAGE_PATH ':' "${globalLibrariesPath}"
'';
};
in lspPkg.executable