-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,9 @@ __debug_bin* | |
demo/output/* | ||
|
||
coverage.out | ||
|
||
# Nix | ||
result | ||
result-* | ||
.direnv | ||
.envrc |
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
{ | ||
description = "A simple terminal UI for git commands"; | ||
|
||
inputs = { | ||
doprz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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; | ||
}; | ||
}; | ||
}; | ||
} |
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 |
Uh oh!
There was an error while loading. Please reload this page.