-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
141 lines (123 loc) · 3.96 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
{
description = "Syslog utilities for troubleshooting & testing";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
naersk.url = "github:nix-community/naersk";
fenix.url = "github:nix-community/fenix";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, naersk, fenix, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
# Toolchain for use in development shell
toolchainFull = with fenix.packages.${system}; combine [
complete.rustc
complete.cargo
complete.clippy
complete.rustfmt
targets.x86_64-unknown-linux-musl.latest.rust-std
];
# Toolchain to build static binaries
toolchainStatic = with fenix.packages.${system}; combine [
minimal.rustc
minimal.cargo
targets.x86_64-unknown-linux-musl.latest.rust-std
];
naersk' = pkgs.callPackage naersk {};
naerskStatic = naersk.lib.${system}.override {
cargo = toolchainStatic;
rustc = toolchainStatic;
};
naerskDev = naersk.lib.${system}.override {
cargo = toolchainFull;
rustc = toolchainFull;
clippy = toolchainFull;
};
staticPackage = naerskStatic.buildPackage {
src = ./.;
nativeBuildInputs = with pkgs; [
pkgsStatic.stdenv.cc
pkgsStatic.openssl
];
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
# Tell Cargo to enable static compilation.
# (https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags)
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
};
nativePackage = naersk'.buildPackage {
src = ./.;
nativeBuildInputs = with pkgs; [
stdenv.cc
openssl
];
};
devPackage = naerskDev.buildPackage {
src = ./.;
nativeBuildInputs = with pkgs; [
stdenv.cc
openssl
];
};
# With explicit binary name for `nix run` (all packages contain both
# binaries)
client = naersk'.buildPackage {
src = ./.;
name = "syslog-client";
nativeBuildInputs = with pkgs; [
pkgsStatic.stdenv.cc
pkgsStatic.openssl
];
};
# With explicit binary name for `nix run` (all packages contain both
# binaries)
server = naersk'.buildPackage {
src = ./.;
name = "syslog-server";
nativeBuildInputs = with pkgs; [
pkgsStatic.stdenv.cc
pkgsStatic.openssl
];
};
dockerImage = pkgs.dockerTools.buildImage {
name = "syslog-utils";
tag = "latest";
config = {
Env = [
"PATH=${staticPackage}/bin"
];
};
};
in rec {
packages = {
# Statically linked
static = staticPackage;
# Dynamically linked
native = nativePackage;
# For `nix run '.#client'`
client = client;
syslog-client = client;
# For `nix run '.#server'`
server = server;
syslog-server = server;
# For `nix run` or `nix run .`
default = client;
# The docker image contains both binaries
docker = dockerImage;
};
devShells.default = pkgs.mkShell {
inputsFrom = with packages; [ devPackage ];
buildInputs = with pkgs; [
just
];
shellHook = ''
user_shell=$(getent passwd "$(whoami)" |cut -d: -f 7)
just --color=always -l |awk '/^Available recipes:/ gsub(/^Available recipes:/, "The Following `just` commands are available:")'
exec "$user_shell"
'';
};
}
);
}