From 5fe69cb9cfd7006023194473392961c35e1dd2fb Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Tue, 23 Jan 2024 23:05:29 -0600 Subject: [PATCH 1/3] idris2Packages.buildIdris: better packaging ergonomics, better executable support --- .../compilers/idris2/build-idris.nix | 91 +++++++++++-------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/pkgs/development/compilers/idris2/build-idris.nix b/pkgs/development/compilers/idris2/build-idris.nix index c299128aa526..3ad0956e3a08 100644 --- a/pkgs/development/compilers/idris2/build-idris.nix +++ b/pkgs/development/compilers/idris2/build-idris.nix @@ -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 + ''; + }); } From e9fa40dccda643e1c53a967cba8ed5077b916206 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Tue, 23 Jan 2024 23:18:34 -0600 Subject: [PATCH 2/3] idris2Packages.idris2Lsp: init at 2024-01-21 --- pkgs/development/compilers/idris2/default.nix | 5 ++- .../compilers/idris2/idris2-lsp.nix | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 pkgs/development/compilers/idris2/idris2-lsp.nix diff --git a/pkgs/development/compilers/idris2/default.nix b/pkgs/development/compilers/idris2/default.nix index 8a2d28eb1ce0..79a90cbee0f3 100644 --- a/pkgs/development/compilers/idris2/default.nix +++ b/pkgs/development/compilers/idris2/default.nix @@ -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 diff --git a/pkgs/development/compilers/idris2/idris2-lsp.nix b/pkgs/development/compilers/idris2/idris2-lsp.nix new file mode 100644 index 000000000000..d73f2d70d6d0 --- /dev/null +++ b/pkgs/development/compilers/idris2/idris2-lsp.nix @@ -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 From dfe61cf96a544345fad6357f68cf7149ded9e596 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Tue, 23 Jan 2024 23:35:17 -0600 Subject: [PATCH 3/3] doc: update idris2 documentation on buildIdris --- doc/languages-frameworks/idris2.section.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/languages-frameworks/idris2.section.md b/doc/languages-frameworks/idris2.section.md index 47bcbf46aee9..f1f0277cc609 100644 --- a/doc/languages-frameworks/idris2.section.md +++ b/doc/languages-frameworks/idris2.section.md @@ -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";