File: flake.nix

package info (click to toggle)
lazygit 0.56.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 7,196 kB
  • sloc: sh: 131; makefile: 76
file content (125 lines) | stat: -rw-r--r-- 3,470 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{
  description = "A simple terminal UI for git commands";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    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

              # 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;
        };
      };
    };
}