aboutsummaryrefslogtreecommitdiff
path: root/devenv.nix
blob: b575b76bbb2ba46a34628bdac87e5847a4467808 (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
{
  pkgs,
  lib,
  config,
  inputs,
  ...
}:

{
  name = "ai-game";
  # https://devenv.sh/basics/
  env = {
    GREET = "🛠️ Let's hack ";
  };

  # https://devenv.sh/scripts/
  scripts = {
    hello.exec = "echo $GREET";
    cat.exec = "bat $@";
    build.exec = "go build -o ./bin/";
    show = {
      # Prints scripts that have a description
      # Adapted from https://github.com/cachix/devenv/blob/ef61728d91ad5eb91f86cdbcc16070602e7afa16/examples/scripts/devenv.nix#L34
      exec = ''
        GREEN="\033[0;32m";
        YELLOW="\033[33m";
        NC="\033[0m";
        echo
        echo -e "✨ Helper scripts you can run to make your development richer:"
        echo
        ${pkgs.gnused}/bin/sed -e 's| |••|g' -e 's|=| |' <<EOF | ${pkgs.util-linuxMinimal}/bin/column -t | ${pkgs.gnused}/bin/sed -e "s|^\([^ ]*\)|$(printf "$GREEN")\1$(printf "$NC"):    |" -e "s|^|$(printf "$YELLOW*$NC") |" -e 's|••| |g'
        ${lib.generators.toKeyValue { } (
          lib.mapAttrs (name: value: value.description) (
            lib.filterAttrs (_: value: value.description != "") config.scripts
          )
        )}
        EOF
        echo
      '';
      description = "Print this message and exit.";
    };

  };

  # https://devenv.sh/packages/
  packages = with pkgs; [
    nixfmt-rfc-style
    bat
    jq
    tealdeer
    gopls
    air
    ncurses
  ];

  languages = {
    go.enable = true;

  };

  enterShell = ''
    hello
    show'';

  # https://devenv.sh/pre-commit-hooks/
  pre-commit.hooks = {
    nixfmt-rfc-style = {
      enable = true;
      excludes = [ ".devenv.flake.nix" ];
    };
    yamllint = {
      enable = true;
      settings.preset = "relaxed";
    };
  };

  # Make diffs fantastic
  difftastic.enable = true;

  # https://devenv.sh/integrations/dotenv/
  dotenv.enable = true;

  # https://devenv.sh/integrations/codespaces-devcontainer/
  devcontainer.enable = true;
}