-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
145 lines (138 loc) · 4.57 KB
/
flake.nix
File metadata and controls
145 lines (138 loc) · 4.57 KB
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
{
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-utils.inputs.systems.follows = "systems";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
crane.url = "github:ipetkov/crane";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
systems.url = "github:nix-systems/default";
};
outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;}
({
config,
self,
inputs,
lib,
getSystem,
...
}: {
systems = import inputs.systems;
imports = [
inputs.flake-parts.flakeModules.easyOverlay
inputs.treefmt-nix.flakeModule
];
flake = {
nixosModules.commit-notifier = ./nixos/commit-notifier.nix;
};
perSystem = {
config,
self',
pkgs,
system,
...
}: let
craneLib = inputs.crane.mkLib pkgs;
src = craneLib.cleanCargoSource (craneLib.path ./.);
bareCommonArgs = {
inherit src;
nativeBuildInputs = with pkgs; [
pkg-config
];
buildInputs = with pkgs; [
sqlite
libgit2
openssl
];
};
cargoArtifacts = craneLib.buildDepsOnly bareCommonArgs;
commonArgs = bareCommonArgs // {inherit cargoArtifacts;};
in {
packages = {
default = config.packages.commit-notifier;
commit-notifier = craneLib.buildPackage commonArgs;
dockerImage = pkgs.dockerTools.buildImage {
name = "commit-notifier";
tag = self.sourceInfo.rev or null;
copyToRoot = pkgs.buildEnv {
name = "commit-notifier-env";
paths =
(with pkgs; [
git
coreutils # for manual operations
])
++ (with pkgs.dockerTools; [
usrBinEnv
binSh
caCertificates
]);
};
config = {
Entrypoint = ["${pkgs.tini}/bin/tini" "--"];
Cmd = let
start = pkgs.writeShellScript "start-commit-notifier" ''
exec ${config.packages.commit-notifier}/bin/commit-notifier \
--working-dir "/data" \
--cron "$COMMIT_NOTIFIER_CRON" \
$EXTRA_ARGS "$@"
'';
in ["${start}"];
Env = [
"TELOXIDE_TOKEN="
"GITHUB_TOKEN="
"RUST_LOG=commit_notifier=info"
"COMMIT_NOTIFIER_CRON=0 */5 * * * *"
"EXTRA_ARGS="
];
WorkingDirectory = "/data";
Volumes = {"/data" = {};};
Labels =
{
"org.opencontainers.image.title" = "commit-notifier";
"org.opencontainers.image.description" = "A simple telegram bot monitoring commit status";
"org.opencontainers.image.url" = "https://github.com/linyinfeng/commit-notifier";
"org.opencontainers.image.source" = "https://github.com/linyinfeng/commit-notifier";
"org.opencontainers.image.licenses" = "MIT";
}
// lib.optionalAttrs (self.sourceInfo ? rev) {
"org.opencontainers.image.revision" = self.sourceInfo.rev;
};
};
};
};
overlayAttrs = {
inherit (config.packages) commit-notifier;
};
checks = {
inherit (self'.packages) commit-notifier dockerImage;
doc = craneLib.cargoDoc commonArgs;
fmt = craneLib.cargoFmt {inherit src;};
nextest = craneLib.cargoNextest commonArgs;
clippy = craneLib.cargoClippy (commonArgs
// {
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
};
treefmt = {
projectRootFile = "flake.nix";
programs = {
alejandra.enable = true;
rustfmt.enable = true;
shfmt.enable = true;
};
};
devShells.default = pkgs.mkShell {
inputsFrom = lib.attrValues self'.checks;
packages = with pkgs; [
rustup
nil
];
};
};
});
}