Skip to content

Commit f8ad5fc

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 chore: nix flake regex feat(nix): move go into overlay
1 parent 2bf2c38 commit f8ad5fc

File tree

7 files changed

+361
-5
lines changed

7 files changed

+361
-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
@@ -374,19 +374,65 @@ sudo zypper ar https://download.opensuse.org/repositories/devel:/languages:/go/$
374374
sudo zypper ref && sudo zypper in lazygit
375375
```
376376

377-
### NixOs
377+
### NixOS
378378

379-
On NixOs lazygit is packaged with nix and distributed via nixpkgs.
380-
You can try the lazygit without installing it with:
379+
#### Using lazygit from nixpkgs
380+
381+
On NixOS, lazygit is packaged with nix and distributed via nixpkgs.
382+
You can try lazygit without installing it with:
381383

382384
```sh
383385
nix-shell -p lazygit
384386
# or with flakes enabled
385387
nix run nixpkgs#lazygit
386388
```
389+
Or you can add lazygit to your `configuration.nix` using the `environment.systemPackages` option.
390+
More details can be found via NixOS search [page](https://search.nixos.org/).
391+
392+
#### Using the official lazygit flake
393+
394+
This repository includes a nix flake that provides the latest development version and additional development tools:
395+
396+
**Run lazygit directly from the repository:**
397+
```sh
398+
nix run github:jesseduffield/lazygit
399+
# or from a local clone
400+
nix run .
401+
```
402+
403+
**Build lazygit from source:**
404+
```sh
405+
nix build github:jesseduffield/lazygit
406+
# or from a local clone
407+
nix build .
408+
```
387409

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

391437
### Flox
392438

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: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
system,
24+
...
25+
}:
26+
let
27+
goMod = builtins.readFile ./go.mod;
28+
versionMatch = builtins.match ".*go[[:space:]]([0-9]+\\.[0-9]+)(\\.[0-9]+)?.*" goMod;
29+
30+
goVersion =
31+
if versionMatch != null then
32+
builtins.head versionMatch
33+
else
34+
throw "Could not extract Go version from go.mod";
35+
36+
goOverlay = final: prev: {
37+
go = prev."go_${builtins.replaceStrings [ "." ] [ "_" ] goVersion}";
38+
};
39+
40+
lazygit = pkgs.buildGoModule rec {
41+
pname = "lazygit";
42+
version = "dev";
43+
44+
gitCommit = inputs.self.rev or inputs.self.dirtyRev or "dev";
45+
46+
src = ./.;
47+
vendorHash = null;
48+
49+
# Disable integration tests that require specific environment
50+
doCheck = false;
51+
52+
nativeBuildInputs = with pkgs; [
53+
git
54+
makeWrapper
55+
];
56+
buildInputs = [ pkgs.git ];
57+
58+
ldflags = [
59+
"-s"
60+
"-w"
61+
"-X main.commit=${gitCommit}"
62+
"-X main.version=${version}"
63+
"-X main.buildSource=nix"
64+
];
65+
66+
postInstall = ''
67+
wrapProgram $out/bin/lazygit \
68+
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.git ]}
69+
'';
70+
71+
meta = {
72+
description = "A simple terminal UI for git commands";
73+
homepage = "https://github.com/jesseduffield/lazygit";
74+
license = pkgs.lib.licenses.mit;
75+
maintainers = [ "jesseduffield" ];
76+
platforms = pkgs.lib.platforms.unix;
77+
mainProgram = "lazygit";
78+
};
79+
};
80+
in
81+
{
82+
_module.args.pkgs = import inputs.nixpkgs {
83+
inherit system;
84+
overlays = [ goOverlay ];
85+
config = { };
86+
};
87+
88+
packages = {
89+
default = lazygit;
90+
inherit lazygit;
91+
};
92+
93+
devShells.default = pkgs.mkShell {
94+
name = "lazygit-dev";
95+
96+
buildInputs = with pkgs; [
97+
# Go toolchain
98+
go
99+
gotools
100+
101+
# Development tools
102+
git
103+
gnumake
104+
];
105+
106+
# Environment variables for development
107+
CGO_ENABLED = "0";
108+
};
109+
110+
treefmt = {
111+
programs.nixfmt.enable = pkgs.lib.meta.availableOn pkgs.stdenv.buildPlatform pkgs.nixfmt-rfc-style.compiler;
112+
programs.nixfmt.package = pkgs.nixfmt-rfc-style;
113+
programs.gofmt.enable = true;
114+
};
115+
116+
checks.build = lazygit;
117+
};
118+
119+
flake = {
120+
# Global overlay for other flakes to use
121+
overlays.default = final: prev: {
122+
lazygit = inputs.self.packages.${final.system}.lazygit;
123+
};
124+
};
125+
};
126+
}

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)