-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
149 lines (132 loc) · 4.15 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
144
145
146
147
148
149
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs @ { self, ... }:
(inputs.flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ inputs.rust-overlay.overlays.default ];
};
rust = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain).override {
extensions = [
"rust-src"
];
};
# rustfmt from rust-nightly used for advanced options in rustfmt
rustfmt-nightly = pkgs.rust-bin.nightly.latest.rustfmt;
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rust;
commonBuildInputs = [
rust
] ++ (with pkgs; [
openssl
]);
commonNativeBuildInputs = with pkgs; [
pkg-config
];
shellPkgs = [
# this needs to come first in list to override the default rustfmt
rustfmt-nightly
] ++ (with pkgs; [
ets
gnumake
just
nixpkgs-fmt
perl
present-cli
])
++ commonBuildInputs
++ commonNativeBuildInputs;
cargo-workspace = craneLib.buildPackage {
pname = "cargo-workspace";
src = craneLib.cleanCargoSource (craneLib.path ./.);
strictDeps = true;
buildInputs = commonBuildInputs;
nativeBuildInputs = commonNativeBuildInputs;
};
buildWorkspaceBinary = src:
pkgs.stdenv.mkDerivation rec {
inherit (craneLib.crateNameFromCargoToml { inherit src; })
pname
version
;
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out/bin
cp -r ${cargo-workspace}/bin/${pname} $out/bin/
'';
};
cid-router = buildWorkspaceBinary ./cid-router;
azure-blob-storage-crp = buildWorkspaceBinary ./external-crps/azure-blob-storage-crp;
github-crp = buildWorkspaceBinary ./external-crps/github-crp;
imageBase =
pkgs.dockerTools.buildLayeredImage {
name = "docker-service-image-base";
# 1 layer holds customizations and packages are distributed among other layers
# for maxLayers=2 all packages go in one layer
maxLayers = 2;
contents = with pkgs; [
bashInteractive
dockerTools.binSh
dockerTools.usrBinEnv
coreutils
which
];
config = {
Env = [
"USER=root"
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
];
};
};
buildImage = binary-pkg:
pkgs.dockerTools.buildLayeredImage {
name = binary-pkg.pname;
tag = "dev";
fromImage = imageBase;
maxLayers = 4; # base image uses 2 layers, this uses 2 layers
contents = [
binary-pkg
];
config = {
ExposedPorts = { "80/tcp" = { }; };
EntryPoint = [
"${binary-pkg}/bin/${binary-pkg.pname}"
];
};
};
cid-router-image = buildImage cid-router;
azure-blob-storage-crp-image = buildImage azure-blob-storage-crp;
github-crp-image = buildImage github-crp;
in
rec {
devShells = {
default = pkgs.mkShell {
buildInputs = shellPkgs;
shellHook = ''
export PATH="$(pwd)/_build/bin/:$PATH"
'';
};
};
packages = {
inherit
cid-router
cid-router-image
azure-blob-storage-crp
azure-blob-storage-crp-image
github-crp
github-crp-image
;
};
}));
}