summaryrefslogtreecommitdiff
path: root/flake.nix
blob: cc729770b7796237c3552c88383a68f232fd0735 (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
{
  description = "getchoo's neovim config";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

    vim-tera = {
      url = "github:vkhitrin/vim-tera";
      flake = false;
    };
  };

  outputs =
    {
      self,
      nixpkgs,
      vim-tera,
    }:
    let
      inherit (nixpkgs) lib;

      systems = [
        "x86_64-linux"
        "aarch64-linux"
        "x86_64-darwin"
        "aarch64-darwin"
      ];

      forAllSystems = lib.genAttrs systems;
      nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system});
    in
    {
      checks = forAllSystems (
        system:
        let
          pkgs = nixpkgsFor.${system};
        in
        {
          check-format-and-lint =
            pkgs.runCommand "check-format-and-lint"
              {
                nativeBuildInputs = [
                  pkgs.actionlint
                  pkgs.nixfmt-rfc-style
                  pkgs.selene
                  pkgs.statix
                ];
              }
              ''
                cd ${self}

                echo "running actionlint..."
                actionlint ./.github/workflows/*

                echo "running nixfmt..."
                nixfmt --check .

                echo "running selene...."
                selene **/*.lua

                echo "running statix..."
                statix check .

                touch $out
              '';

        }
      );

      devShells = forAllSystems (
        system:
        let
          pkgs = nixpkgsFor.${system};
        in
        {
          default = pkgs.mkShellNoCC {
            packages = [
              pkgs.actionlint

              # lua
              pkgs.lua-language-server
              pkgs.selene
              pkgs.stylua

              # nix
              self.formatter.${system}
              pkgs.deadnix
              pkgs.nil
              pkgs.statix
            ];
          };
        }
      );

      formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style);

      packages = forAllSystems (
        system:
        let
          pkgs = nixpkgsFor.${system};

          dateFrom =
            flake:
            let
              # YYYYMMDD
              date = builtins.substring 0 8 flake.lastModifiedDate;
              # YYYY
              year = builtins.substring 0 4 date;
              # MM
              month = builtins.substring 4 2 date;
              # DD
              day = builtins.substring 6 2 date;
            in
            builtins.concatStringsSep "-" [
              year
              month
              day
            ];

        in
        {
          getchvim = pkgs.callPackage (self + "/neovim.nix") {
            inherit (self.packages.${system}) getchoo-neovim-config vim-tera;
          };

          getchoo-neovim-config = pkgs.vimUtils.buildVimPlugin {
            pname = "getchoo-neovim-config";
            version = "0-unstable-" + dateFrom self;

            src = self;
          };

          vim-tera = pkgs.vimUtils.buildVimPlugin {
            pname = "vim-tera";
            version = "0-unstable-" + dateFrom vim-tera;
            src = vim-tera;
          };

          default = self.packages.${system}.getchvim;
        }
      );
    };
}