summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 1ced9654c58a46318c0b04df1851f808f44c5349 (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
{
  description = "A Discord app for tracking nixpkgs PRs";

  inputs = {
    nixpkgs.url = "nixpkgs/nixpkgs-unstable";
    fenix = {
      url = "github:nix-community/fenix";
      inputs = {
        nixpkgs.follows = "nixpkgs";
        rust-analyzer-src.follows = "";
      };
    };
    flake-checks.url = "github:getchoo/flake-checks";
  };

  outputs = {
    self,
    nixpkgs,
    fenix,
    flake-checks,
  }: let
    systems = [
      "x86_64-linux"
      "aarch64-linux"
      "x86_64-darwin"
      "aarch64-darwin"
    ];

    forAllSystems = function: nixpkgs.lib.genAttrs systems (system: function nixpkgs.legacyPackages.${system});
  in {
    checks = forAllSystems ({
      lib,
      pkgs,
      ...
    }: {
      inherit
        (flake-checks.lib.mkChecks {
          inherit pkgs;
          root = lib.fileset.toSource {
            root = ./.;
            fileset = lib.fileset.gitTracked ./.;
          };
        })
        actionlint
        deadnix
        rustfmt
        statix
        ;
    });

    devShells = forAllSystems ({
      pkgs,
      system,
      ...
    }: let
      inputsFrom = [self.packages.${system}.nixpkgs-tracker-bot];
      RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
    in {
      default = pkgs.mkShell {
        inherit inputsFrom RUST_SRC_PATH;
      };

      full = pkgs.mkShell {
        inherit inputsFrom RUST_SRC_PATH;
        packages = [
          pkgs.clippy
          pkgs.rustfmt
          pkgs.rust-analyzer

          pkgs.actionlint
          pkgs.deadnix
          pkgs.nil
          pkgs.statix

          self.formatter.${system}
        ];
      };
    });

    formatter = forAllSystems (pkgs: pkgs.alejandra);

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

    packages = forAllSystems ({
      lib,
      pkgs,
      system,
      ...
    }: let
      packages = self.packages.${system};

      mkStaticForArch = arch:
        pkgs.callPackage ./nix/static.nix {
          inherit arch;
          inherit (packages) nixpkgs-tracker-bot;
          fenix = fenix.packages.${system};
        };

      containerWith = nixpkgs-tracker-bot: let
        arch = nixpkgs-tracker-bot.stdenv.hostPlatform.ubootArch;
      in
        pkgs.dockerTools.buildLayeredImage {
          name = "nixpkgs-tracker-bot";
          tag = "latest-${arch}";
          config.Cmd = [(lib.getExe nixpkgs-tracker-bot)];
          architecture = arch;
        };
    in {
      nixpkgs-tracker-bot = pkgs.callPackage ./nix/package.nix {
        version = self.shortRev or self.dirtyShortRev or "unknown";
      };

      default = packages.nixpkgs-tracker-bot;

      static-x86_64 = mkStaticForArch "x86_64";
      static-arm64 = mkStaticForArch "aarch64";

      container-x86_64 = containerWith packages.static-x86_64;
      container-arm64 = containerWith packages.static-arm64;
    });
  };
}