-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(nix): add comprehensive Nix flake #4826
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
Conversation
I know next to nothing about Nix, and in particular I don't know what Nix flakes are. I don't really want to spend time on learning more about that, either. However, I would have to understand things a little better in order to judge if the PR is good and can be merged. So what can we do? I see that our current README.md already says something about flakes (here), but I don't understand what it means. Would this have to be changed with your PR? Any people reading here who are more familiar with Nix and can help review this? |
It seems that someone has already uploaded I will update the README.md to include information about the local nix flake. In summary this will allow people that use nix to run your project in an ephemeral shell, install it, and even have a fully setup dev env with go and other dependencies managed by nix. This will be an official flake that is fully featured while the one on nixpkgs is maintained by others and will either follow the 20.05 or unstable channel. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like what you are doing, but a lot of changes needed.
@Eveeifyeve thank you for the feedback! |
I really wonder if this thing should be maintained in our repo at all. It sounds similar to an rpm spec file, a deb file, or a homebrew formula, and we don't maintain those here either; we let people who are packaging experts do it wherever it makes sense to them. I'd feel better about this if we took the same approach for this flake thing too. (Happy to link to it from the readme though, of course.) Or am I missing something about why it conceptionally makes sense to maintain this here, unlike those other ones? |
The main difference is that this will let developers load up a dev environment provided by nix which includes all the necessary dependencies, env vars, and build tools/checks setup. I've also added the ability to build from source using nix while the unofficial one on nixpkgs is currently pinned at v0.53.0. The nix configuration doesn't require constant maintenance and will only be updated when NixOS reaches a next major version as the packages follow that or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good now, but one change needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only two more changes needed. Before I consider this LGTM.
Thank you for your feedback @Eveeifyeve on this PR! It's been very helpful to learn best practices. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nit picks, real issue is the with pkgs.lib
else it's LGTM.
Thank you @Eveeifyeve! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stefanhaller bump |
7dc0e36
to
e357f68
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things.
- The branch is totally unreviewable with all the merges from master, and all the fine-grained commits that change things back and forth. I rebased onto master to get rid of the merge commits and force-pushed, this makes it a little bit reviewable at least. In the end I suppose all commits need to be squashed into one. We don't do this by default here, it's the contributor's job to provide a commit sequence that makes sense. In the future, please look into working with
fixup!
commits, and never merge master into your branch; always rebase onto master instead. - As for maintaining it here vs. elsewhere: your explanation above still didn't make it very clear to me what the benefit is of maintaining the flake in this repo vs. somewhere else. I now saw that we have an issue for this (#3474), this explains it a little bit better. But still, there are also things like flakehub, would it be an option to use that instead?
The reason why I'm still hesitant to host the flake here is that this PR has shown that it needs expertise to get this right. @Eveeifyeve seems to have done a great job at helping with this, but if they are not around next time we need to make a change to this, who else will be able to do that? I won't, because I totally lack the expertise, and I don't intend to acquire it. @Eveeifyeve What's your take on this?
I agree to most of this this pr is at the point where you need to squash the commits. Second Maintaining the flake should be left up to the nix contributors and not the main program maintainers it should be in the official repo because packages take a few days before they reach unstable but have a way of getting the package early before unstable releases/updates. |
That alone is not a reason to host them here though, is it? The same can be said about any distribution or package manager. Look at this table, where most table cells need a few days to become green after a new release. We are not going to start hosting deb files, rpm spec files, or homebrew formula files in this repo to avoid that. |
Homebrew it's instant after pr release idk about others probably the same, but nixpkgs you have something called channels (stable and unstable) and channels get merged every couple of days so you have the time of the pr created till merged + time for channels which can equate to about two weeks. Which for many people you don't want to be waiting for the channel to have the change so many people upstream flakes to get the change instantly while also providing a development shell for those who use nix and want to develop they can. |
2f2e918
to
293b5a7
Compare
This configuration is at the point where it should not require any major changes or foreseeable maintenance to it. The main purpose of this PR was to allow nix users to have a development shell with all of the required deps and tools to start developing and using The original commit I made worked albeit not using best practices as I wasn't aware of things such as ![]() The PR is not about replacing the "unofficial" nix flake or adding distribution/package management files to the lazygit repo. It's about allowing nix users to have a declarative and reproducible dev environment to allow them to contribute to lazygit. All they have to do is cd into the repo and load up the dev shell or build lazygit via nix or with make. It's a quality of life PR at it's core. |
293b5a7
to
516faea
Compare
so its like a dev container? but for nix users? am i understanding this correctly? |
please just take a look at https://nixos.org |
@doprz Are you waiting for any more input? I thought there's consensus about the way forward for the two open issues. |
516faea
to
2dbbe4f
Compare
I've pushed the changes to resolve those two issues and rebased + squashed my commits. |
flake.nix
Outdated
else | ||
throw "Could not extract Go version from go.mod"; | ||
|
||
go = pkgs."go_${builtins.replaceStrings [ "." ] [ "_" ] goVersion}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this into an overlay to define go to use the exact version of go. If #4826 (comment) is true
buildInputs = with pkgs; [ | ||
# Go toolchain | ||
go | ||
gotools |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you suggest?
There was a problem hiding this comment.
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"
823f775
to
f8ad5fc
Compare
a8e9968
to
642bb9b
Compare
@Eveeifyeve I've addressed all PR comments and feedback and I think that this PR is now ready for a final review before @stefanhaller's review. Thank you once again for all of your help! |
642bb9b
to
bae4aac
Compare
I rebased on master, cleaned up the commit message of all the squash junk, and added one more fixup commit for the readme. @Eveeifyeve Is this good to go from your side? I see that @doprz asked you for one final review, but I didn't see any response to that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix some nitpicking. Before it looks good to me.
.gitignore
Outdated
# Ignore build outputs from performing a nix-build or `nix build` command | ||
result | ||
result-* | ||
|
||
# Ignore automatically generated direnv output | ||
.direnv | ||
.envrc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit picking, Remove the comments and make a global comment # Nix
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 3db5e14
flake.nix
Outdated
}; | ||
|
||
flake = { | ||
# Global overlay for other flakes to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nix pick, A nix user knows this is an overlay that they could use as it's included as documentation. Please remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in 56e7a17
Since everything seems addressed now, I'm going to merge this. Thanks again @doprz for the contribution, and @Eveeifyeve for the reviews. |
Co-authored-by: Eveeifyeve
56e7a17
to
6b8853c
Compare
i encountered error when nix log output> nix log --repair --debug --print-build-logs --verbose -- github:jesseduffield/lazygit |& wl-copy
evaluating file '<nix/derivation-internal.nix>'
evaluating derivation 'github:jesseduffield/lazygit#packages.x86_64-linux.default'...
using cache entry 'file:{"name":"source","store":"/nix/store","url":"https://api.github.com/repos/jesseduffield/lazygit/commits/HEAD"}' -> '{"etag":"W/\"8a72f43b339b5f39823e3e3e7ddae4066bc9b407fa09a00674a21978f44dec3c\"","storePath":"c8w5brrgl00jq9gjgvyj8f9i78z52z3m-source","url":"https://api.github.com/repos/jesseduffield/lazygit/commits/HEAD"}'
performing daemon worker op: 11
acquiring write lock on '/nix/var/nix/temproots/319196'
performing daemon worker op: 1
using cache entry 'file:{"name":"source","store":"/nix/store","url":"https://api.github.com/repos/jesseduffield/lazygit/commits/HEAD"}' -> '{"etag":"W/\"8a72f43b339b5f39823e3e3e7ddae4066bc9b407fa09a00674a21978f44dec3c\"","url":"https://api.github.com/repos/jesseduffield/lazygit/commits/HEAD"}', '/nix/store/c8w5brrgl00jq9gjgvyj8f9i78z52z3m-source'
HEAD revision for 'github:jesseduffield/lazygit/HEAD' is 60a7d6ac573fc5e102f5b8975fa9064560f2aee7
using cache entry 'gitRevToTreeHash:{"rev":"60a7d6ac573fc5e102f5b8975fa9064560f2aee7"}' -> '{"treeHash":"fa3e587f81fc897ebf46da7052c1224ca96692d8"}'
using cache entry 'gitRevToLastModified:{"rev":"60a7d6ac573fc5e102f5b8975fa9064560f2aee7"}' -> '{"lastModified":1759929123}'
got tree '«github:jesseduffield/lazygit/60a7d6ac573fc5e102f5b8975fa9064560f2aee7»/' from 'github:jesseduffield/lazygit/60a7d6ac573fc5e102f5b8975fa9064560f2aee7'
evaluating file '«github:jesseduffield/lazygit/60a7d6ac573fc5e102f5b8975fa9064560f2aee7»/flake.nix'
using cache entry 'fetchToStore:{"fingerprint":"60a7d6ac573fc5e102f5b8975fa9064560f2aee7","method":"nar","name":"source","path":"/","store":"/nix/store"}' -> '{"storePath":"p6142g3sm3rvsw0bx345nj2ymy2mp5nh-source"}'
performing daemon worker op: 11
performing daemon worker op: 1
using cache entry 'fetchToStore:{"fingerprint":"60a7d6ac573fc5e102f5b8975fa9064560f2aee7","method":"nar","name":"source","path":"/","store":"/nix/store"}' -> 'null', '/nix/store/p6142g3sm3rvsw0bx345nj2ymy2mp5nh-source'
store path cache hit for '«github:jesseduffield/lazygit/60a7d6ac573fc5e102f5b8975fa9064560f2aee7»/'
performing daemon worker op: 26
evaluating file '/nix/store/p6142g3sm3rvsw0bx345nj2ymy2mp5nh-source/flake.nix'
performing daemon worker op: 19
old lock file: {
"nodes": {
"flake-compat": {
"locked": {
"lastModified": 1733328505,
"narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
"revCount": 69,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.1.0/01948eb7-9cba-704f-bbf3-3fa956735b52/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1754487366,
"narHash": "sha256-pHYj8gUBapuUzKV/kN/tR3Zvqc7o6gdFB9XKXIp1SQ8=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "af66ad14b28a127c5c0f3bbb298218fc63528a18",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1756217674,
"narHash": "sha256-TH1SfSP523QI7kcPiNtMAEuwZR3Jdz0MCDXPs7TS8uo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "4e7667a90c167f7a81d906e5a75cba4ad8bee620",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-25.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1753579242,
"narHash": "sha256-zvaMGVn14/Zz8hnp4VWT9xVnhc8vuL3TStRqwk22biA=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "0f36c44e01a6129be94e3ade315a5883f0228a6e",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1754340878,
"narHash": "sha256-lgmUyVQL9tSnvvIvBp7x1euhkkCho7n3TMzgjdvgPoU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "cab778239e705082fe97bb4990e0d24c50924c04",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"systems": "systems",
"treefmt-nix": "treefmt-nix"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1755934250,
"narHash": "sha256-CsDojnMgYsfshQw3t4zjRUkmMmUdZGthl16bXVWgRYU=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "74e1a52d5bd9430312f8d1b8b0354c92c17453e5",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}
computing lock file node ''
computing input 'flake-compat'
keeping existing input 'flake-compat'
computing lock file node 'flake-compat'
computing input 'flake-parts'
keeping existing input 'flake-parts'
computing lock file node 'flake-parts'
computing input 'flake-parts/nixpkgs-lib'
keeping existing input 'flake-parts/nixpkgs-lib'
computing lock file node 'flake-parts/nixpkgs-lib'
computing input 'nixpkgs'
keeping existing input 'nixpkgs'
computing lock file node 'nixpkgs'
computing input 'systems'
keeping existing input 'systems'
computing lock file node 'systems'
computing input 'treefmt-nix'
keeping existing input 'treefmt-nix'
computing lock file node 'treefmt-nix'
computing input 'treefmt-nix/nixpkgs'
keeping existing input 'treefmt-nix/nixpkgs'
computing lock file node 'treefmt-nix/nixpkgs'
new lock file: {
"nodes": {
"flake-compat": {
"locked": {
"lastModified": 1733328505,
"narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
"revCount": 69,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.1.0/01948eb7-9cba-704f-bbf3-3fa956735b52/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1754487366,
"narHash": "sha256-pHYj8gUBapuUzKV/kN/tR3Zvqc7o6gdFB9XKXIp1SQ8=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "af66ad14b28a127c5c0f3bbb298218fc63528a18",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1756217674,
"narHash": "sha256-TH1SfSP523QI7kcPiNtMAEuwZR3Jdz0MCDXPs7TS8uo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "4e7667a90c167f7a81d906e5a75cba4ad8bee620",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-25.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1753579242,
"narHash": "sha256-zvaMGVn14/Zz8hnp4VWT9xVnhc8vuL3TStRqwk22biA=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "0f36c44e01a6129be94e3ade315a5883f0228a6e",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1754340878,
"narHash": "sha256-lgmUyVQL9tSnvvIvBp7x1euhkkCho7n3TMzgjdvgPoU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "cab778239e705082fe97bb4990e0d24c50924c04",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"systems": "systems",
"treefmt-nix": "treefmt-nix"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1755934250,
"narHash": "sha256-CsDojnMgYsfshQw3t4zjRUkmMmUdZGthl16bXVWgRYU=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "74e1a52d5bd9430312f8d1b8b0354c92c17453e5",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}
trying flake output attribute 'packages.x86_64-linux.default'
trying flake output attribute 'defaultPackage.x86_64-linux'
using cached attrset attribute ''
using cached string attribute 'packages.x86_64-linux.default.type'
using cached string attribute 'packages.x86_64-linux.default.drvPath'
performing daemon worker op: 1
using cached list of strings attribute 'packages.x86_64-linux.default.meta.outputsToInstall'
got build log for 'github:jesseduffield/lazygit#packages.x86_64-linux.default' from 'daemon'
Running phase: unpackPhase
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking source archive /nix/store/j7pdzc5z4xf4yvm10bwn9immcfi6zbhr-p6142g3sm3rvsw0bx345nj2ymy2mp5nh-source
source root is p6142g3sm3rvsw0bx345nj2ymy2mp5nh-source
Running phase: patchPhase
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: configurePhase
@nix { "action": "setPhase", "phase": "configurePhase" }
Running phase: buildPhase
@nix { "action": "setPhase", "phase": "buildPhase" }
Building subPackage .
go: go.mod requires go >= 1.25.0 (running go 1.24.5; GOTOOLCHAIN=local)
|
@doprz @Eveeifyeve Can one of you please have a look? We just recently bumped our go requirement to 1.25. I was assuming that this |
@stefanhaller A bit of oversight on our end. I've resolved this in #4948. |
Thank you once again @Eveeifyeve and @stefanhaller for the reviews and feedback! |
PR Description
This PR adds Nix flake support to provide a reproducible development environment and build process for
lazygit
contributors, devs, and users.Features:
nix develop
,nix run
, andnix build
Closes #3474.
Please check if the PR fulfills these requirements
n/a as this PR doesn't modify go files.
go generate ./...
)