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

CI configs: add nix flake #1815

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
82 changes: 82 additions & 0 deletions flake.lock

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

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

27 changes: 27 additions & 0 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
schema = 3

[mod]
[mod."github.com/creack/pty"]
version = "v1.1.21"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will this dependency data be kept in sync with the go.mod file? If someone submits a change that updates the version of any of these packages (which I have done more than once) do they also have to update this file or is file somehow automatically kept in sync with the go.mod file for the project?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be updated together with the command
nix develop --command gomod2nix.

If adding flake is OK, I'll try to add workflow that generates automatic PR when dependancy changes.

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="
Loading