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. 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. 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 ```nix
{ fetchFromGitHub, idris2Packages }: { fetchFromGitHub, idris2Packages }:
let lspLibPkg = idris2Packages.buildIdris { let lspLibPkg = idris2Packages.buildIdris {
projectName = "lsp-lib"; ipkgName = "lsp-lib";
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "idris-community"; owner = "idris-community";
repo = "LSP-lib"; 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`: # Assuming the previous example lives in `lsp-lib.nix`:
let lspLib = callPackage ./lsp-lib.nix { }; let lspLib = callPackage ./lsp-lib.nix { };
lspPkg = idris2Packages.buildIdris { lspPkg = idris2Packages.buildIdris {
projectName = "idris2-lsp"; ipkgName = "idris2-lsp";
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "idris-community"; owner = "idris-community";
repo = "idris2-lsp"; repo = "idris2-lsp";

View File

@ -1,9 +1,9 @@
{ stdenv, lib, idris2 { stdenv, lib, idris2, makeWrapper
}: }:
# Usage: let # Usage: let
# pkg = idris2Packages.buildIdris { # pkg = idris2Packages.buildIdris {
# src = ...; # src = ...;
# projectName = "my-pkg"; # ipkgName = "my-pkg";
# idrisLibraries = [ ]; # idrisLibraries = [ ];
# }; # };
# in { # in {
@ -12,62 +12,75 @@
# } # }
# #
{ src { src
, projectName , ipkgName
, version ? "unversioned"
, idrisLibraries # Other libraries built with buildIdris , idrisLibraries # Other libraries built with buildIdris
, ... }@attrs: , ... }@attrs:
let let
ipkgName = projectName + ".ipkg"; ipkgFileName = ipkgName + ".ipkg";
idrName = "idris2-${idris2.version}"; idrName = "idris2-${idris2.version}";
libSuffix = "lib/${idrName}"; libSuffix = "lib/${idrName}";
libDirs = libDirs =
lib.makeSearchPath libSuffix idrisLibraries; (lib.makeSearchPath libSuffix idrisLibraries) +
drvAttrs = builtins.removeAttrs attrs [ "idrisLibraries" ]; ":${idris2}/${idrName}";
supportDir = "${idris2}/${idrName}/lib";
drvAttrs = builtins.removeAttrs attrs [
"ipkgName"
"idrisLibraries"
];
sharedAttrs = { sharedAttrs = drvAttrs // {
name = projectName; pname = ipkgName;
inherit version;
src = src; src = src;
nativeBuildInputs = [ idris2 ]; nativeBuildInputs = [ idris2 makeWrapper ] ++ attrs.nativeBuildInputs or [];
buildInputs = idrisLibraries ++ attrs.buildInputs or [];
IDRIS2_PACKAGE_PATH = libDirs; IDRIS2_PACKAGE_PATH = libDirs;
configurePhase = ''
runHook preConfigure
runHook postConfigure
'';
buildPhase = '' buildPhase = ''
runHook preBuild runHook preBuild
idris2 --build ${ipkgName} idris2 --build ${ipkgFileName}
runHook postBuild runHook postBuild
''; '';
}; };
in { in {
executable = stdenv.mkDerivation (lib.attrsets.mergeAttrsList [ executable = stdenv.mkDerivation (sharedAttrs // {
sharedAttrs installPhase = ''
{ installPhase = '' runHook preInstall
runHook preInstall mkdir -p $out/bin
mkdir -p $out/bin scheme_app="$(find ./build/exec -name '*_app')"
mv build/exec/* $out/bin if [ "$scheme_app" = ''' ]; then
runHook postInstall mv -- build/exec/* $out/bin/
''; chmod +x $out/bin/*
} # ^ remove after Idris2 0.8.0 is released. will be superfluous:
drvAttrs # 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 }: library = { withSource ? false }:
let installCmd = if withSource then "--install-with-src" else "--install"; let installCmd = if withSource then "--install-with-src" else "--install";
in stdenv.mkDerivation (lib.attrsets.mergeAttrsList [ in stdenv.mkDerivation (sharedAttrs // {
sharedAttrs installPhase = ''
{ runHook preInstall
installPhase = '' mkdir -p $out/${libSuffix}
runHook preInstall export IDRIS2_PREFIX=$out/lib
mkdir -p $out/${libSuffix} idris2 ${installCmd} ${ipkgFileName}
export IDRIS2_PREFIX=$out/lib runHook postInstall
idris2 ${installCmd} ${ipkgName} '';
runHook postInstall });
'';
}
drvAttrs
]);
} }

View File

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