diff --git a/.gitignore b/.gitignore index 03115ff..73ba76e 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ /tests/**/output src/Server/Generated.idr + +#nix build output +/result diff --git a/README.md b/README.md index 8755bf1..5afb9d6 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,25 @@ Language Server for Idris2. pack install-app lsp ``` +## Installation with Nix Flakes +```bash +nix profile install github:idris-community/idris2-lsp +``` + +Alternatively, add `idris2-lsp` to your `devShell`: +```nix +devShell = npkgs.mkShell { + buildInputs = [ ... idris2-lsp.defaultPackage.${system} ]; + # ... +} +``` + +and idris2-lsp will be available in your development shell +```bash +nix develop +code # will connect to idris2-lsp +``` + ## Manual Installation ```bash # If you already have idris2, uninstall idris2 unless you installed it from source diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..1ef8a22 --- /dev/null +++ b/default.nix @@ -0,0 +1,4 @@ +(import (fetchTarball + "https://github.com/edolstra/flake-compat/archive/master.tar.gz") { + src = builtins.fetchGit ./.; + }).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ba0841f --- /dev/null +++ b/flake.lock @@ -0,0 +1,100 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1687709756, + "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "idris": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "idris-emacs-src": "idris-emacs-src", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1687937568, + "narHash": "sha256-vGMgXWaQVJTsc3YObHLccissay4GM5brJLcb2+dDzII=", + "owner": "idris-lang", + "repo": "Idris2", + "rev": "ecf4765c4beab2656d57ba4982f42427a40bc016", + "type": "github" + }, + "original": { + "owner": "idris-lang", + "repo": "Idris2", + "type": "github" + } + }, + "idris-emacs-src": { + "flake": false, + "locked": { + "lastModified": 1666078909, + "narHash": "sha256-oYNHFIpcrFfPb4sXJwEBFKeH+PB4AGCrAFrfBrSTCeo=", + "owner": "redfish64", + "repo": "idris2-mode", + "rev": "3bcb52a65c488f31c99d20f235f6050418a84c9d", + "type": "github" + }, + "original": { + "owner": "redfish64", + "repo": "idris2-mode", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1688465017, + "narHash": "sha256-xzFcCnzPOgQaX7Acprfqo+tqHJ2UKWC38pXrcqvdXHU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0d5682acc109add20f70440269587a1b169cc2fe", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "idris": "idris", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..207f608 --- /dev/null +++ b/flake.nix @@ -0,0 +1,85 @@ +{ + description = "Idris 2 Language Server"; + + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.idris = { + url = "github:idris-lang/Idris2"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; + }; + + outputs = { self, nixpkgs, idris, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + npkgs = import nixpkgs { inherit system; }; + idrisPkgs = idris.packages.${system}; + buildIdris = idris.buildIdris.${system}; + + #from https://github.com/claymager/idris2-pkgs/blob/main/packageSet.nix + #should probably be upstreamed to Idris + idris2-api = buildIdris { + projectName = "idris2api"; + src = idris; + idrisLibraries = [ ]; + buildInputs = [ npkgs.gmp ]; + postConfigure = + '' + LONG_VERSION=$(idris2 --version) + ARR=($(echo $LONG_VERSION | sed 's/-/ /g; s/\./,/g' )) + VERSION="((''${ARR[-2]}), \"${idris.shortRev or "dirty"}\")" + + echo "-- @""generated" > src/IdrisPaths.idr + echo 'module IdrisPaths' >> src/IdrisPaths.idr + echo "export idrisVersion : ((Nat,Nat,Nat), String); idrisVersion = $VERSION" >> src/IdrisPaths.idr + echo 'export yprefix : String; yprefix="~/.idris2"' >> src/IdrisPaths.idr + ''; + }; + + + contrib = buildIdris { + projectName = "contrib"; + src = idris + "/libs/contrib"; + idrisLibraries = [ ]; + }; + idris2-prelude = buildIdris { + projectName = "prelude"; + src = idris + "/libs/prelude"; + idrisLibraries = [ ]; + }; + idris2-base = buildIdris { + projectName = "base"; + src = idris + "/libs/base"; + idrisLibraries = [ ]; + }; + + # libs that are needed at runtime + # something like this should also probably be upstreamed to Idris + runtimeLibs = [ idris2-prelude.installLibrary idris2-base.installLibrary ]; + + lib-dirs = + let + idrName = "idris2-${idris.version}"; + libSuffix = "lib/${idrName}"; + in + nixpkgs.lib.strings.concatMapStringsSep ":" (p: "${p}/${libSuffix}") runtimeLibs; + + pkgs = buildIdris { + projectName = "lsp"; + src = ./.; + idrisLibraries = [ contrib.installLibrary idris2-api.installLibrary ]; + buildInputs = runtimeLibs ++ [ npkgs.makeWrapper ]; + postInstall = '' + wrapProgram $out/bin/idris2-lsp --prefix IDRIS2_PACKAGE_PATH : ${lib-dirs} + ''; + }; + in rec { + packages = pkgs // idrisPkgs; + defaultPackage = pkgs.build; + devShell = npkgs.mkShell { + buildInputs = [ idrisPkgs.idris2 npkgs.rlwrap ]; + shellHook = '' + alias idris2="rlwrap -s 1000 idris2 --no-banner" + ''; + }; + }); +}