Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nix flake support #199

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
/tests/**/output

src/Server/Generated.idr

#nix build output
/result
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.defaultPackages.${system} ];
mattpolzin marked this conversation as resolved.
Show resolved Hide resolved
# ...
}
```

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
Expand Down
4 changes: 4 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(import (fetchTarball
"https://github.com/edolstra/flake-compat/archive/master.tar.gz") {
src = builtins.fetchGit ./.;
}).defaultNix
100 changes: 100 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 85 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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"
'';
};
});
}