-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflake.nix
143 lines (138 loc) · 4.46 KB
/
flake.nix
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
{
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
crane.url = "github:ipetkov/crane";
crane.inputs.nixpkgs.follows = "nixpkgs";
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
};
outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;}
({
self,
inputs,
lib,
...
}: {
systems = [
"x86_64-linux"
"aarch64-linux"
];
imports = [
inputs.flake-parts.flakeModules.easyOverlay
inputs.treefmt-nix.flakeModule
];
flake = {
nixosModules.oranc = ./nixos/module.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
installShellFiles
];
buildInputs = with pkgs; [
openssl
sqlite
];
# TODO https://github.com/ipetkov/crane/issues/385
doNotLinkInheritedArtifacts = true;
};
cargoArtifacts = craneLib.buildDepsOnly bareCommonArgs;
commonArgs = bareCommonArgs // {inherit cargoArtifacts;};
in {
packages = {
oranc = craneLib.buildPackage (commonArgs
// {
postInstall = ''
installShellCompletion --cmd oranc \
--bash <($out/bin/oranc completion bash) \
--fish <($out/bin/oranc completion fish) \
--zsh <($out/bin/oranc completion zsh)
'';
});
default = config.packages.oranc;
dockerImage = pkgs.dockerTools.buildImage {
name = "oranc";
tag = self.sourceInfo.rev or null;
copyToRoot = pkgs.buildEnv {
name = "oranc-env";
paths = [
pkgs.dockerTools.caCertificates
];
};
config = {
Entrypoint = ["${pkgs.tini}/bin/tini" "--"];
Cmd = let
start = pkgs.writeShellScript "start-oranc" ''
exec ${config.packages.oranc}/bin/oranc server \
--listen "[::]:80" \
$EXTRA_ARGS "$@"
'';
in ["${start}"];
Env = [
"RUST_LOG=oranc=info"
"EXTRA_ARGS="
];
ExposedPorts = {
"80/tcp" = {};
};
Labels =
{
"org.opencontainers.image.title" = "oranc";
"org.opencontainers.image.description" = "OCI Registry As Nix Cache";
"org.opencontainers.image.url" = "https://github.com/linyinfeng/oranc";
"org.opencontainers.image.source" = "https://github.com/linyinfeng/oranc";
"org.opencontainers.image.licenses" = "MIT";
}
// lib.optionalAttrs (self.sourceInfo ? rev) {
"org.opencontainers.image.revision" = self.sourceInfo.rev;
};
};
};
integrationTestScript = pkgs.callPackage ./integration-test {
inherit (config.packages) dockerImage oranc;
};
};
overlayAttrs.oranc = config.packages.oranc;
checks = {
inherit (self'.packages) oranc 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
rust-analyzer
];
};
};
});
}