summaryrefslogtreecommitdiff
path: root/flake.nix
blob: d2def003267f26a88988dacfc48e2ef741eb608b (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
{
  description = "teawie moment";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    fenix = {
      url = "github:nix-community/fenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = {
    self,
    nixpkgs,
    ...
  } @ inputs: let
    systems = [
      "x86_64-linux"
      "aarch64-linux"
      "x86_64-darwin"
      "aarch64-darwin"
    ];

    forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system});
  in {
    checks = forAllSystems ({
      lib,
      pkgs,
      ...
    }: {
      actionlint = pkgs.runCommand "check-actionlint" {} ''
        ${lib.getExe pkgs.actionlint} ${./.github/workflows}/*
        touch $out
      '';

      deadnix = pkgs.runCommand "check-deadnix" {} ''
        ${lib.getExe pkgs.deadnix} --fail ${./.}
        touch $out
      '';

      editorconfig = pkgs.runCommand "check-editorconfig" {} ''
        cd ${./.}
        ${lib.getExe pkgs.editorconfig-checker} \
          -exclude '.git' .

        touch $out
      '';

      rustfmt = pkgs.runCommand "check-rustfmt" {nativeBuildInputs = [pkgs.cargo pkgs.rustfmt];} ''
        cd ${./.}
        cargo fmt -- --check
        touch $out
      '';

      statix = pkgs.runCommand "check-statix" {} ''
        ${lib.getExe pkgs.statix} check ${./.}
        touch $out
      '';
    });

    devShells = forAllSystems ({
      pkgs,
      system,
      ...
    }: {
      default = pkgs.mkShell {
        packages = [
          # rust tools
          pkgs.clippy
          pkgs.rustfmt
          pkgs.rust-analyzer

          # nix tools
          pkgs.deadnix
          pkgs.nil
          pkgs.statix

          # misc formatter/linters
          pkgs.actionlint
          self.formatter.${system}

          pkgs.redis
        ];

        inputsFrom = [self.packages.${system}.teawiebot];
        RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
      };

      ci = pkgs.mkShell {
        packages = [
          pkgs.clippy
          pkgs.rustfmt

          self.formatter.${system}
        ];

        inputsFrom = [self.packages.${system}.teawiebot];
      };
    });

    formatter = forAllSystems (pkgs: pkgs.alejandra);

    nixosModules.default = import ./nix/module.nix self;

    packages = forAllSystems ({
      pkgs,
      system,
      ...
    }: let
      crossBuildsFor = arch: import ./nix/docker.nix {inherit pkgs arch inputs;};
    in
      {
        teawiebot = pkgs.callPackage ./nix/derivation.nix {inherit self;};

        default = self.packages.${system}.teawiebot;
      }
      // crossBuildsFor "x86_64"
      // crossBuildsFor "aarch64");

    overlays.default = _: prev: {
      teawiebot = prev.callPackage ./nix/derivation.nix {inherit self;};
    };
  };
}