From 2084e19a0c267409ba41f4ba8b856dc653b5edcc Mon Sep 17 00:00:00 2001 From: rok Date: Wed, 22 May 2024 16:41:31 +0900 Subject: [PATCH] CI configs: add nix flake --- flake.lock | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 66 ++++++++++++++++++++++++++++++++++++++++ gomod2nix.toml | 27 +++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 gomod2nix.toml diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..75fb935e9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,82 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gomod2nix": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1716202913, + "narHash": "sha256-zjPNXI4DWBOrPsrK8u/XTsm5Q36quONQvz0jhAKHEeg=", + "owner": "nix-community", + "repo": "gomod2nix", + "rev": "4702caff8e201f4c98fe3583637a930d253447c8", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "gomod2nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1716218643, + "narHash": "sha256-i/E7gzQybvcGAYDRGDl39WL6yVk30Je/NXypBz6/nmM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a8695cbd09a7ecf3376bd62c798b9864d20f86ee", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "gomod2nix": "gomod2nix", + "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 000000000..09ab30259 --- /dev/null +++ b/flake.nix @@ -0,0 +1,66 @@ +{ + description = "elvish"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; + gomod2nix = { + url = "github:nix-community/gomod2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, gomod2nix }: + let + allSystems = [ + "x86_64-linux" # 64-bit Intel/AMD Linux + "aarch64-linux" # 64-bit ARM Linux + "x86_64-darwin" # 64-bit Intel macOS + "aarch64-darwin" # 64-bit ARM macOS + ]; + forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f { + inherit system; + pkgs = import nixpkgs { inherit system; }; + }); + in + { + packages = forAllSystems ({ system, pkgs, ... }: + let + buildGoApplication = gomod2nix.legacyPackages.${system}.buildGoApplication; + in + rec { + default = elvish; + + elvish = buildGoApplication { + name = "elvish"; + src = ./.; + go = pkgs.go_1_21; + pwd = ./.; + subPackages = [ "cmd/elvish" ]; + CGO_ENABLED = 0; + flags = [ + "-trimpath" + ]; + ldflags = [ + "-s" + "-w" + "-extldflags -static" + ]; + }; + }); + + # `nix develop` provides a shell containing development tools. + devShell = forAllSystems ({ system, pkgs }: + pkgs.mkShell { + buildInputs = with pkgs; [ + go_1_21 + gomod2nix.legacyPackages.${system}.gomod2nix + gopls + ]; + }); + + overlays.default = final: prev: { + elvish = self.packages.${final.stdenv.system}.elvish; + }; + }; +} + diff --git a/gomod2nix.toml b/gomod2nix.toml new file mode 100644 index 000000000..3209e340c --- /dev/null +++ b/gomod2nix.toml @@ -0,0 +1,27 @@ +schema = 3 + +[mod] + [mod."github.com/creack/pty"] + version = "v1.1.21" + hash = "sha256-pjGw6wQlrVhN65XaIxZueNJqnXThGu00u24rKOLzxS0=" + [mod."github.com/google/go-cmp"] + version = "v0.6.0" + hash = "sha256-qgra5jze4iPGP0JSTVeY5qV5AvEnEu39LYAuUCIkMtg=" + [mod."github.com/mattn/go-isatty"] + version = "v0.0.20" + hash = "sha256-qhw9hWtU5wnyFyuMbKx+7RB8ckQaFQ8D+8GKPkN3HHQ=" + [mod."github.com/sourcegraph/jsonrpc2"] + version = "v0.2.0" + hash = "sha256-UPJQN/TSg9CjRj0239EV9dbZTwe7grOCf8lFWMkqo8U=" + [mod."go.etcd.io/bbolt"] + version = "v1.3.9" + hash = "sha256-98cKiMZcxl11laO3IiRHnhSgh7mEjl0iKlPxsSPdbww=" + [mod."golang.org/x/sync"] + version = "v0.6.0" + hash = "sha256-LLims/wjDZtIqlYCVHREewcUOX4hwRwplEuZKPOJ/HI=" + [mod."golang.org/x/sys"] + version = "v0.17.0" + hash = "sha256-e0qnE+SitE02IzvnJKI4Uzpq9EOZY+zvE8Wf5b2e6Kg=" + [mod."pkg.nimblebun.works/go-lsp"] + version = "v1.1.0" + hash = "sha256-mJS7tsR4bPOIcHpvIsdKHQvZxpgFRm3hBSMVBMFcDZI="