Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ __debug_bin*
demo/output/*

coverage.out

# Nix
result
result-*
.direnv
.envrc
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,31 @@ To run lazygit from within the integrated terminal just go `go run main.go`

This allows you to contribute to Lazygit without needing to install anything on your local machine. The Codespace has all the necessary tools and extensions pre-installed.

## Using Nix for development

If you use Nix, you can leverage the included flake to set up a complete development environment with all necessary dependencies:

```sh
nix develop
```

This will drop you into a development shell that includes:
* Latest Go toolchain
* golangci-lint for code linting
* git and make

You can also build and run lazygit using nix:

```sh
# Build lazygit
nix build

# Run lazygit directly
nix run
```

The nix flake supports multiple architectures (x86_64-linux, aarch64-linux, x86_64-darwin, aarch64-darwin) and provides a consistent development environment across different systems.

## Code of conduct

Please note by participating in this project, you agree to abide by the [code of conduct].
Expand Down
55 changes: 50 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,19 +388,64 @@ sudo zypper ar https://download.opensuse.org/repositories/devel:/languages:/go/$
sudo zypper ref && sudo zypper in lazygit
```

### NixOs
### NixOS

On NixOs lazygit is packaged with nix and distributed via nixpkgs.
You can try the lazygit without installing it with:
#### Using lazygit from nixpkgs

On NixOS, lazygit is packaged with nix and distributed via nixpkgs.
You can try lazygit without installing it with:

```sh
nix-shell -p lazygit
# or with flakes enabled
nix run nixpkgs#lazygit
```
Or you can add lazygit to your `configuration.nix` using the `environment.systemPackages` option.
More details can be found via NixOS search [page](https://search.nixos.org/).

#### Using the official lazygit flake

This repository includes a nix flake that provides the latest development version and additional development tools:

**Run lazygit directly from the repository:**
```sh
nix run github:jesseduffield/lazygit
# or from a local clone
nix run .
```

**Build lazygit from source:**
```sh
nix build github:jesseduffield/lazygit
# or from a local clone
nix build .
```

Or you can add lazygit to you `configuration.nix` using the `environment.systemPackages` option.
More details can be found via NixOs search [page](https://search.nixos.org/).
**Development environment:**
For contributors, the flake provides a development shell with Go toolchain, development tools, and dependencies:
```sh
nix develop github:jesseduffield/lazygit
# or from a local clone
nix develop
```

The development shell includes:
- Go toolchain
- git and make
- Proper environment variables for development

**Using in other flakes:**
The flake also provides an overlay for easy integration into other flake-based projects:
```nix
{
inputs.lazygit.url = "github:jesseduffield/lazygit";

outputs = { self, nixpkgs, lazygit }: {
# Use the overlay
nixpkgs.overlays = [ lazygit.overlays.default ];
};
}
```

### Flox

Expand Down
12 changes: 12 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
nodeName = lock.nodes.root.inputs.flake-compat;
in
fetchTarball {
url =
lock.nodes.${nodeName}.locked.url
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
sha256 = lock.nodes.${nodeName}.locked.narHash;
}
) { src = ./.; }).defaultNix
127 changes: 127 additions & 0 deletions flake.lock

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

125 changes: 125 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
description = "A simple terminal UI for git commands";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
systems.url = "github:nix-systems/default";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
treefmt-nix.url = "github:numtide/treefmt-nix";
};

outputs =
inputs@{ flake-parts, systems, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = import systems;
imports = [
inputs.treefmt-nix.flakeModule
];

perSystem =
{
pkgs,
system,
...
}:
let
goMod = builtins.readFile ./go.mod;
versionMatch = builtins.match ".*go[[:space:]]([0-9]+\\.[0-9]+)(\\.[0-9]+)?.*" goMod;

goVersion =
if versionMatch != null then
builtins.head versionMatch
else
throw "Could not extract Go version from go.mod";

goOverlay = final: prev: {
go = prev."go_${builtins.replaceStrings [ "." ] [ "_" ] goVersion}";
};

lazygit = pkgs.buildGoModule rec {
pname = "lazygit";
version = "dev";

gitCommit = inputs.self.rev or inputs.self.dirtyRev or "dev";

src = ./.;
vendorHash = null;

# Disable integration tests that require specific environment
doCheck = false;

nativeBuildInputs = with pkgs; [
git
makeWrapper
];
buildInputs = [ pkgs.git ];

ldflags = [
"-s"
"-w"
"-X main.commit=${gitCommit}"
"-X main.version=${version}"
"-X main.buildSource=nix"
];

postInstall = ''
wrapProgram $out/bin/lazygit \
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.git ]}
'';

meta = {
description = "A simple terminal UI for git commands";
homepage = "https://github.com/jesseduffield/lazygit";
license = pkgs.lib.licenses.mit;
maintainers = [ "jesseduffield" ];
platforms = pkgs.lib.platforms.unix;
mainProgram = "lazygit";
};
};
in
{
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ goOverlay ];
config = { };
};

packages = {
default = lazygit;
inherit lazygit;
};

devShells.default = pkgs.mkShell {
name = "lazygit-dev";

buildInputs = with pkgs; [
# Go toolchain
go
gotools

Choose a reason for hiding this comment

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

Does this get the version of go that is packaged via nixpkgs or would this use the local version of go defined above?

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 uses the version of go that is defined via the regex.

Choose a reason for hiding this comment

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

Yes, but the gotools I know go tools defines a specific version of go inside of its package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you suggest?

Choose a reason for hiding this comment

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

What do you suggest?

#4826 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've also double checked this by running:

nix derivation show .#devShells.<system>.default

and checking inputDrvs.

or

nix derivation show .#devShells.<system>.default | jq '.[].inputDrvs | keys[]' | grep -e "go-.*drv"


# Development tools
git
gnumake
];

# Environment variables for development
CGO_ENABLED = "0";
};

treefmt = {
programs.nixfmt.enable = pkgs.lib.meta.availableOn pkgs.stdenv.buildPlatform pkgs.nixfmt-rfc-style.compiler;
programs.nixfmt.package = pkgs.nixfmt-rfc-style;
programs.gofmt.enable = true;
};

checks.build = lazygit;
};

flake = {
overlays.default = final: prev: {
lazygit = inputs.self.packages.${final.system}.lazygit;
};
};
};
}
12 changes: 12 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
nodeName = lock.nodes.root.inputs.flake-compat;
in
fetchTarball {
url =
lock.nodes.${nodeName}.locked.url
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
sha256 = lock.nodes.${nodeName}.locked.narHash;
}
) { src = ./.; }).shellNix