From 6c3475d9036f671015d8b448df0644b60b681312 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sun, 14 Jan 2024 11:42:13 -0600 Subject: [PATCH] Add a Nix flake (take 2) (#210) * underpinnings of flake for LSP * use LSP-lib. specify the same ENV as the compiler is wrapped in for the LSP executable. * update Idris2 and LSP-lib submodules to latest commits --- .gitignore | 3 + Idris2 | 2 +- LSP-lib | 2 +- default.nix | 5 ++ flake.lock | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 83 ++++++++++++++++++++++++ 6 files changed, 276 insertions(+), 2 deletions(-) create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix 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/Idris2 b/Idris2 index 2778007..da6f0b0 160000 --- a/Idris2 +++ b/Idris2 @@ -1 +1 @@ -Subproject commit 27780073c8631826d846499840b3857d9b9a4fd5 +Subproject commit da6f0b0e4e99b398190deca2dfef6bec84f0062c diff --git a/LSP-lib b/LSP-lib index 6b79b66..5fa42e2 160000 --- a/LSP-lib +++ b/LSP-lib @@ -1 +1 @@ -Subproject commit 6b79b66f555c0130932bf8a50b959684aba073dc +Subproject commit 5fa42e295472abeb2dfe6a148ce2a66070075708 diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..87d1d29 --- /dev/null +++ b/default.nix @@ -0,0 +1,5 @@ +(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..487678b --- /dev/null +++ b/flake.lock @@ -0,0 +1,183 @@ +{ + "nodes": { + "alejandra": { + "inputs": { + "fenix": "fenix", + "flakeCompat": "flakeCompat", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660510326, + "narHash": "sha256-xFumnivtVwu5fFBOrTxrv6fv3geHKF04RGP23EsDVaI=", + "owner": "kamadorueda", + "repo": "alejandra", + "rev": "ef03f7ef74ec97fd91a016a51c9c9667fb315652", + "type": "github" + }, + "original": { + "owner": "kamadorueda", + "ref": "3.0.0", + "repo": "alejandra", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "alejandra", + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1657607339, + "narHash": "sha256-HaqoAwlbVVZH2n4P3jN2FFPMpVuhxDy1poNOR7kzODc=", + "owner": "nix-community", + "repo": "fenix", + "rev": "b814c83d9e6aa5a28d0cf356ecfdafb2505ad37d", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flakeCompat": { + "flake": false, + "locked": { + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "idris": { + "inputs": { + "flake-utils": "flake-utils", + "idris-emacs-src": "idris-emacs-src", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1704779897, + "narHash": "sha256-O8YioErELfZXHl5S3ju3BLqCqWjxtueRxc3zks0QNOU=", + "owner": "idris-lang", + "repo": "Idris2", + "rev": "da6f0b0e4e99b398190deca2dfef6bec84f0062c", + "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" + } + }, + "lsp-lib": { + "inputs": { + "idris": [ + "idris" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1704845948, + "narHash": "sha256-tlRZdUZQLwsPejW4rSjOeRLhofa9tT6kq6KLKW67Kus=", + "owner": "idris-community", + "repo": "LSP-lib", + "rev": "5fa42e295472abeb2dfe6a148ce2a66070075708", + "type": "github" + }, + "original": { + "owner": "idris-community", + "repo": "LSP-lib", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1704845540, + "narHash": "sha256-3+bxZTsRX0YCuqNjFDmm/EE761p5bP/gJlCXKRWQeqg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "c27ade81bfa02c5e2e792f1ff8d1d0b9e1288e0c", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "alejandra": "alejandra", + "idris": "idris", + "lsp-lib": "lsp-lib", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1657557289, + "narHash": "sha256-PRW+nUwuqNTRAEa83SfX+7g+g8nQ+2MMbasQ9nt6+UM=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "caf23f29144b371035b864a1017dbc32573ad56d", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..44ac13e --- /dev/null +++ b/flake.nix @@ -0,0 +1,83 @@ +{ + description = "Idris 2 Language Server"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs"; + + idris = { + url = "github:idris-lang/Idris2"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + lsp-lib = { + url = "github:idris-community/LSP-lib"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.idris.follows = "idris"; + }; + + alejandra = { + url = "github:kamadorueda/alejandra/3.0.0"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { + self, + nixpkgs, + alejandra, + idris, + lsp-lib, + }: let + lib = nixpkgs.lib; + # support the same systems as Idris2 + systems = builtins.attrNames idris.packages; + forEachSystem = with lib; + mkOutputs: let + outputsForSystem = system: + concatMapAttrs (k: v: {${k}.${system} = v;}) (mkOutputs system); + in + foldl' recursiveUpdate {} (map outputsForSystem systems); + in + forEachSystem ( + system: let + pkgs = nixpkgs.legacyPackages.${system}; + idrisPkgs = idris.packages.${system}; + buildIdris = idris.buildIdris.${system}; + lspLib = lsp-lib.packages.${system}.default; + supportLibrariesPath = lib.makeLibraryPath [idrisPkgs.support]; + supportSharePath = lib.makeSearchPath "share" [idrisPkgs.support]; + + globalLibraries = let + idrName = "idris2-${idris.version}"; + libSuffix = "lib/${idrName}"; + in [ + "\\$HOME/.nix-profile/lib/${idrName}" + "/run/current-system/sw/lib/${idrName}" + "${idrisPkgs.idris2}/${idrName}" + ]; + globalLibrariesPath = builtins.concatStringsSep ":" globalLibraries; + + lspPkg = buildIdris { + projectName = "idris2-lsp"; + src = ./.; + idrisLibraries = [idrisPkgs.idris2-api lspLib]; + buildInputs = [pkgs.makeWrapper]; + postInstall = '' + wrapProgram $out/bin/idris2-lsp \ + --run 'export IDRIS2_PREFIX=''${IDRIS2_PREFIX-"$HOME/.idris2"}' \ + --suffix IDRIS2_LIBS ':' "${supportLibrariesPath}" \ + --suffix IDRIS2_DATA ':' "${supportSharePath}" \ + --suffix IDRIS2_PACKAGE_PATH ':' "${globalLibrariesPath}" + ''; + }; + in rec { + packages = + idrisPkgs + // rec { + idris2-lsp = lspPkg.executable; + default = idris2-lsp; + }; + formatter = alejandra.packages.${system}.default; + } + ); +}