DEVELOPMENT ENVIRONMENT

~liljamo/felu

ref: 35a4f2467581d4e308486f0eb27c9bcf8d1525e4 felu/flake.nix -rw-r--r-- 2.7 KiB
35a4f246Jonni Liljamo feat: justfile and include a few tools in devshell a month ago
                                                                                
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
{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    flake-parts = {
      url = "github:hercules-ci/flake-parts";
      inputs.nixpkgs-lib.follows = "nixpkgs";
    };

    pre-commit-hooks = {
      url = "github:cachix/git-hooks.nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    devshell = {
      url = "github:numtide/devshell";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    templ = {
      url = "github:a-h/templ?ref=tags/v0.2.778";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = inputs @ {self, ...}:
    inputs.flake-parts.lib.mkFlake {inherit inputs;} {
      imports = [
        inputs.devshell.flakeModule
      ];

      systems = ["x86_64-linux"];
      perSystem = {
        pkgs,
        system,
        ...
      }: {
        checks.pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
          src = ./.;
          hooks = {
            # Nix formatting
            alejandra.enable = true;

            # Go formatting, linting, static checking
            gofmt.enable = true;
            govet.enable = true;
            revive.enable = true;
          };
        };

        devshells.default = {
          env = [
            {
              name = "FELU_LOG_LEVEL";
              value = "debug";
            }
            {
              name = "GIN_MODE";
              value = "release";
            }
            {
              name = "FELU_DB_PATH";
              value = "tmp/";
            }
            {
              name = "FELU_DNS_PATTERN";
              value = "ddns.feludns.arpa.";
            }
            {
              name = "FELU_DNS_BIND_PORT";
              value = "8053";
            }
          ];
          commands = [
            {
              help = "run felu";
              name = "felu-dev-run";
              command = "go run cmd/felu/main.go";
            }
            {
              help = "generate templ templates (watch)";
              name = "felu-dev-templ";
              command = "templ generate --watch";
            }
            {
              help = "generate tailwindcss (watch)";
              name = "felu-dev-tailwindcss";
              command = "tailwindcss -i input.css -o ./static/styles.css --watch";
            }
          ];
          packages = with pkgs;
            [
              gcc

              go
              gopls

              tailwindcss
              tailwindcss-language-server

              just

              bind
              dig
            ]
            ++ [
              inputs.templ.packages.${system}.default
            ];

          devshell.startup.pre-commit.text = self.checks.${system}.pre-commit-check.shellHook;
        };
      };
    };
}