blob: 0e86328140a6b3cbe42d46ba4e9d0d8dfc02ac76 (
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
144
145
146
147
|
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs =
{
self,
nixpkgs,
}:
let
inherit (nixpkgs) lib;
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = lib.genAttrs systems;
in
{
checks = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
mkCheck =
name: nativeBuildInputs: script:
pkgs.runCommand "check-${name}" { inherit nativeBuildInputs; } ''
${script} | tee $out
'';
in
{
clippy-sarif = pkgs.stdenv.mkDerivation {
name = "check-clippy-sarif";
inherit (self.packages.${system}.chill-discord-bot) src cargoDeps;
nativeBuildInputs = [
pkgs.cargo
pkgs.clippy
pkgs.clippy-sarif
pkgs.rustPlatform.cargoSetupHook
pkgs.rustc
pkgs.sarif-fmt
];
buildPhase = ''
runHook preBuild
cargo clippy \
--all-features \
--all-targets \
--tests \
--message-format=json \
| clippy-sarif | tee $out | sarif-fmt
runHook postBuild
'';
};
actionlint = mkCheck "actionlint" [ pkgs.actionlint ] "actionlint ${self}/.github/workflows/*";
deadnix = mkCheck "deadnix" [ pkgs.deadnix ] "deadnix check ${self}";
nixfmt = mkCheck "nixfmt" [
pkgs.nixfmt-rfc-style
] "find ${self} -type f -name '*.nix' | xargs nixfmt --check";
rustfmt = mkCheck "rustfmt" [ pkgs.cargo pkgs.rustfmt ] "cd ${self} && cargo fmt -- --check";
statix = mkCheck "statix" [ pkgs.statix ] "statix check ${self}";
}
);
devShells = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
default = pkgs.mkShell {
packages = [
# rust tools
pkgs.clippy
pkgs.rustfmt
pkgs.rust-analyzer
# nix tools
pkgs.nil
pkgs.statix
# misc formatter/linters
pkgs.actionlint
self.formatter.${system}
pkgs.redis
];
inputsFrom = [ self.packages.${system}.chill-discord-bot ];
RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
};
ci = pkgs.mkShell {
packages = [
pkgs.clippy
pkgs.rustfmt
self.formatter.${system}
];
inputsFrom = [ self.packages.${system}.chill-discord-bot ];
};
}
);
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);
nixosModules.default = lib.modules.importApply ./nix/module.nix { inherit self; };
packages = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
packages' = self.packages.${system};
staticWith = pkgs.callPackage ./nix/static.nix { inherit self; };
containerize = pkgs.callPackage ./nix/containerize.nix { };
in
{
container-amd64 = containerize packages'.static-x86_64;
container-arm64 = containerize packages'.static-aarch64;
static-x86_64 = staticWith { arch = "x86_64"; };
static-aarch64 = staticWith { arch = "aarch64"; };
chill-discord-bot = pkgs.callPackage ./nix/package.nix { inherit self; };
default = self.packages.${system}.chill-discord-bot;
}
);
};
}
|