Skip to content

Commit 516faea

Browse files
committed
feat(nix): add nix flake with dev shell
feat(nix): add nix run and build support chore: move vendor/ -> vendor_lg/ fix: revert vendor_lg -> vendor fix: fix vendor chore: set vendorHash to null docs: add local nix flake installation and contributing refactor(nix): use flake-parts, nix-systems, and flake-compat docs: remove nix profile installation section fix(nix): remove apps and hydraJobs fix: version info to match main chore: remove shellHook feat(nix): add treefmt-nix feat(nix): add gofmt to treefmt chore(nix): move version and gitCommit Apply suggestion from @Eveeifyeve Co-authored-by: Eveeifyeve <[email protected]> Apply suggestion from @Eveeifyeve Co-authored-by: Eveeifyeve <[email protected]> Apply suggestion from @Eveeifyeve Co-authored-by: Eveeifyeve <[email protected]> Apply suggestion from @Eveeifyeve Co-authored-by: Eveeifyeve <[email protected]> Update CONTRIBUTING.md Co-authored-by: Eveeifyeve <[email protected]> Update flake.nix Co-authored-by: Eveeifyeve <[email protected]> chore: change version to dev
1 parent 900d8be commit 516faea

File tree

7 files changed

+342
-5
lines changed

7 files changed

+342
-5
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ __debug_bin*
2828
demo/output/*
2929

3030
coverage.out
31+
32+
# Ignore build outputs from performing a nix-build or `nix build` command
33+
result
34+
result-*
35+
36+
# Ignore automatically generated direnv output
37+
.direnv
38+
.envrc

CONTRIBUTING.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,31 @@ To run lazygit from within the integrated terminal just go `go run main.go`
6060

6161
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.
6262

63+
## Using Nix for development
64+
65+
If you use Nix, you can leverage the included flake to set up a complete development environment with all necessary dependencies:
66+
67+
```sh
68+
nix develop
69+
```
70+
71+
This will drop you into a development shell that includes:
72+
* Latest Go toolchain
73+
* golangci-lint for code linting
74+
* git and make
75+
76+
You can also build and run lazygit using nix:
77+
78+
```sh
79+
# Build lazygit
80+
nix build
81+
82+
# Run lazygit directly
83+
nix run
84+
```
85+
86+
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.
87+
6388
## Code of conduct
6489

6590
Please note by participating in this project, you agree to abide by the [code of conduct].

README.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,19 +379,65 @@ sudo zypper ar https://download.opensuse.org/repositories/devel:/languages:/go/$
379379
sudo zypper ref && sudo zypper in lazygit
380380
```
381381

382-
### NixOs
382+
### NixOS
383383

384-
On NixOs lazygit is packaged with nix and distributed via nixpkgs.
385-
You can try the lazygit without installing it with:
384+
#### Using lazygit from nixpkgs
385+
386+
On NixOS, lazygit is packaged with nix and distributed via nixpkgs.
387+
You can try lazygit without installing it with:
386388

387389
```sh
388390
nix-shell -p lazygit
389391
# or with flakes enabled
390392
nix run nixpkgs#lazygit
391393
```
394+
Or you can add lazygit to your `configuration.nix` using the `environment.systemPackages` option.
395+
More details can be found via NixOS search [page](https://search.nixos.org/).
396+
397+
#### Using the official lazygit flake
398+
399+
This repository includes a nix flake that provides the latest development version and additional development tools:
400+
401+
**Run lazygit directly from the repository:**
402+
```sh
403+
nix run github:jesseduffield/lazygit
404+
# or from a local clone
405+
nix run .
406+
```
407+
408+
**Build lazygit from source:**
409+
```sh
410+
nix build github:jesseduffield/lazygit
411+
# or from a local clone
412+
nix build .
413+
```
392414

393-
Or you can add lazygit to you `configuration.nix` using the `environment.systemPackages` option.
394-
More details can be found via NixOs search [page](https://search.nixos.org/).
415+
**Development environment:**
416+
For contributors, the flake provides a development shell with Go toolchain, development tools, and dependencies:
417+
```sh
418+
nix develop github:jesseduffield/lazygit
419+
# or from a local clone
420+
nix develop
421+
```
422+
423+
The development shell includes:
424+
- Go toolchain
425+
- golangci-lint for code linting
426+
- git and make
427+
- Proper environment variables for development
428+
429+
**Using in other flakes:**
430+
The flake also provides an overlay for easy integration into other flake-based projects:
431+
```nix
432+
{
433+
inputs.lazygit.url = "github:jesseduffield/lazygit";
434+
435+
outputs = { self, nixpkgs, lazygit }: {
436+
# Use the overlay
437+
nixpkgs.overlays = [ lazygit.overlays.default ];
438+
};
439+
}
440+
```
395441

396442
### Flox
397443

default.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(import (
2+
let
3+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
4+
nodeName = lock.nodes.root.inputs.flake-compat;
5+
in
6+
fetchTarball {
7+
url =
8+
lock.nodes.${nodeName}.locked.url
9+
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
10+
sha256 = lock.nodes.${nodeName}.locked.narHash;
11+
}
12+
) { src = ./.; }).defaultNix

flake.lock

Lines changed: 127 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{
2+
description = "A simple terminal UI for git commands";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
6+
systems.url = "github:nix-systems/default";
7+
flake-parts.url = "github:hercules-ci/flake-parts";
8+
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
9+
treefmt-nix.url = "github:numtide/treefmt-nix";
10+
};
11+
12+
outputs =
13+
inputs@{ flake-parts, systems, ... }:
14+
flake-parts.lib.mkFlake { inherit inputs; } {
15+
systems = import systems;
16+
imports = [
17+
inputs.treefmt-nix.flakeModule
18+
];
19+
20+
perSystem =
21+
{
22+
pkgs,
23+
...
24+
}:
25+
let
26+
lazygit = pkgs.buildGoModule rec {
27+
pname = "lazygit";
28+
version = "dev";
29+
30+
gitCommit = inputs.self.rev or inputs.self.dirtyRev or "dev";
31+
32+
src = ./.;
33+
vendorHash = null;
34+
35+
# Disable integration tests that require specific environment
36+
doCheck = false;
37+
38+
nativeBuildInputs = with pkgs; [
39+
git
40+
makeWrapper
41+
];
42+
buildInputs = [ pkgs.git ];
43+
44+
ldflags = [
45+
"-s"
46+
"-w"
47+
"-X main.commit=${gitCommit}"
48+
"-X main.version=${version}"
49+
"-X main.buildSource=nix"
50+
];
51+
52+
postInstall = ''
53+
wrapProgram $out/bin/lazygit \
54+
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.git ]}
55+
'';
56+
57+
meta = {
58+
description = "A simple terminal UI for git commands";
59+
homepage = "https://github.com/jesseduffield/lazygit";
60+
license = pkgs.lib.licenses.mit;
61+
maintainers = [ "jesseduffield" ];
62+
platforms = pkgs.lib.platforms.unix;
63+
mainProgram = "lazygit";
64+
};
65+
};
66+
in
67+
{
68+
packages = {
69+
default = lazygit;
70+
inherit lazygit;
71+
};
72+
73+
devShells.default = pkgs.mkShell {
74+
name = "lazygit-dev";
75+
76+
buildInputs = with pkgs; [
77+
# Go toolchain
78+
go
79+
gotools
80+
golangci-lint
81+
82+
# Development tools
83+
git
84+
gnumake
85+
];
86+
87+
# Environment variables for development
88+
CGO_ENABLED = "0";
89+
};
90+
91+
treefmt = {
92+
programs.nixfmt.enable = pkgs.lib.meta.availableOn pkgs.stdenv.buildPlatform pkgs.nixfmt-rfc-style.compiler;
93+
programs.nixfmt.package = pkgs.nixfmt-rfc-style;
94+
programs.gofmt.enable = true;
95+
};
96+
97+
checks.build = lazygit;
98+
};
99+
100+
flake = {
101+
# Global overlay for other flakes to use
102+
overlays.default = final: prev: {
103+
lazygit = inputs.self.packages.${final.system}.lazygit;
104+
};
105+
};
106+
};
107+
}

shell.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(import (
2+
let
3+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
4+
nodeName = lock.nodes.root.inputs.flake-compat;
5+
in
6+
fetchTarball {
7+
url =
8+
lock.nodes.${nodeName}.locked.url
9+
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
10+
sha256 = lock.nodes.${nodeName}.locked.narHash;
11+
}
12+
) { src = ./.; }).shellNix

0 commit comments

Comments
 (0)