From 5ca7b136e76bf235f8db897f3a0e286bcb29d788 Mon Sep 17 00:00:00 2001 From: "Michael A. Perlin" Date: Tue, 26 Sep 2023 20:52:19 -0500 Subject: [PATCH 1/4] add nix flake --- flake.lock | 26 ++++++++++++++++++++ flake.nix | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ff6e3c6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1642609835, + "narHash": "sha256-ZwJnV4mdis28u5vH240ec2mrApuEJYJekn23qlTwJ8c=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "77aa71f66fd05d9e7b7d1c084865d703a8008ab7", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-21.11", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..81f47ed --- /dev/null +++ b/flake.nix @@ -0,0 +1,71 @@ +{ + description = "A simple Go package"; + + # Nixpkgs / NixOS version to use. + inputs.nixpkgs.url = "nixpkgs/nixos-21.11"; + + outputs = { self, nixpkgs }: + let + + # to work with older version of flakes + lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; + + # Generate a user-friendly version number. + version = builtins.substring 0 8 lastModifiedDate; + + # System types to support. + supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + + # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + + # Nixpkgs instantiated for supported system types. + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); + + in + { + + # Provide some binary packages for selected system types. + packages = forAllSystems (system: + let + pkgs = nixpkgsFor.${system}; + in + { + snippets-ls = pkgs.buildGoModule { + pname = "snippets-ls"; + inherit version; + # In 'nix develop', we don't need a copy of the source tree + # in the Nix store. + src = ./.; + + # This hash locks the dependencies of this package. It is + # necessary because of how Go requires network access to resolve + # VCS. See https://www.tweag.io/blog/2021-03-04-gomod2nix/ for + # details. Normally one can build with a fake sha256 and rely on native Go + # mechanisms to tell you what the hash should be or determine what + # it should be "out-of-band" with other tooling (eg. gomod2nix). + # To begin with it is recommended to set this, but one must + # remeber to bump this hash when your dependencies change. + #vendorSha256 = pkgs.lib.fakeSha256; + + vendorSha256 = "sha256-zH8N6Bw1I+bFxBiXQtRL/Y2UyE4ix/kdlEsEuwPSZXs="; + }; + }); + + # Add dependencies that are only needed for development + devShells = forAllSystems (system: + let + pkgs = nixpkgsFor.${system}; + in + { + default = pkgs.mkShell { + buildInputs = with pkgs; [ go gopls gotools go-tools ]; + }; + }); + + # The default package for 'nix build'. This makes sense if the + # flake provides only one package or there is a clear "main" + # package. + defaultPackage = forAllSystems (system: self.packages.${system}.snippets-ls); + }; +} From 22d5095de1360e25b9ac04421a13cce64f27d9c4 Mon Sep 17 00:00:00 2001 From: "Michael A. Perlin" Date: Wed, 27 Sep 2023 02:37:25 -0500 Subject: [PATCH 2/4] nixfmt --- flake.nix | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/flake.nix b/flake.nix index 81f47ed..ba5160d 100644 --- a/flake.nix +++ b/flake.nix @@ -8,13 +8,15 @@ let # to work with older version of flakes - lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; + lastModifiedDate = + self.lastModifiedDate or self.lastModified or "19700101"; # Generate a user-friendly version number. version = builtins.substring 0 8 lastModifiedDate; # System types to support. - supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + supportedSystems = + [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. forAllSystems = nixpkgs.lib.genAttrs supportedSystems; @@ -22,15 +24,12 @@ # Nixpkgs instantiated for supported system types. nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); - in - { + in { # Provide some binary packages for selected system types. packages = forAllSystems (system: - let - pkgs = nixpkgsFor.${system}; - in - { + let pkgs = nixpkgsFor.${system}; + in { snippets-ls = pkgs.buildGoModule { pname = "snippets-ls"; inherit version; @@ -48,16 +47,15 @@ # remeber to bump this hash when your dependencies change. #vendorSha256 = pkgs.lib.fakeSha256; - vendorSha256 = "sha256-zH8N6Bw1I+bFxBiXQtRL/Y2UyE4ix/kdlEsEuwPSZXs="; + vendorSha256 = + "sha256-zH8N6Bw1I+bFxBiXQtRL/Y2UyE4ix/kdlEsEuwPSZXs="; }; }); - + # Add dependencies that are only needed for development devShells = forAllSystems (system: - let - pkgs = nixpkgsFor.${system}; - in - { + let pkgs = nixpkgsFor.${system}; + in { default = pkgs.mkShell { buildInputs = with pkgs; [ go gopls gotools go-tools ]; }; @@ -66,6 +64,7 @@ # The default package for 'nix build'. This makes sense if the # flake provides only one package or there is a clear "main" # package. - defaultPackage = forAllSystems (system: self.packages.${system}.snippets-ls); + defaultPackage = + forAllSystems (system: self.packages.${system}.snippets-ls); }; } From c62248f46327feaeffc0844642ddb5d69750eaf5 Mon Sep 17 00:00:00 2001 From: "Michael A. Perlin" Date: Wed, 27 Sep 2023 13:21:18 -0500 Subject: [PATCH 3/4] rename go-lsp --> snippets-ls --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index ba5160d..3e38e68 100644 --- a/flake.nix +++ b/flake.nix @@ -49,6 +49,8 @@ vendorSha256 = "sha256-zH8N6Bw1I+bFxBiXQtRL/Y2UyE4ix/kdlEsEuwPSZXs="; + + postInstall = "mv $out/bin/go-lsp $out/bin/snippets-ls"; }; }); From 9ade20aa5a5303d37716f8c18c7026b11280ec0f Mon Sep 17 00:00:00 2001 From: "Michael A. Perlin" Date: Wed, 27 Sep 2023 19:37:25 -0500 Subject: [PATCH 4/4] fix description --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 3e38e68..8e1fd51 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "A simple Go package"; + description = "Snippet LSP for helix"; # Nixpkgs / NixOS version to use. inputs.nixpkgs.url = "nixpkgs/nixos-21.11";