-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
173 lines (156 loc) · 6.28 KB
/
Copy pathflake.nix
File metadata and controls
173 lines (156 loc) · 6.28 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# aws-greengrass-system-log-forwarder - AWS Greengrass component for forwarding
# logs to CloudWatch.
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
{
description = "Chnage here: description here";
inputs.flakelight.url = "github:nix-community/flakelight";
outputs = { flakelight, ... }@inputs: flakelight ./.
({ lib, config, ... }:
let
inherit (builtins) fromJSON;
inherit (lib) mapAttrs readFile mapAttrsToList toUpper;
filteredSrc = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./CMakeLists.txt
./src
./include
./fc_deps.json
./.clang-tidy
./dep_modules
];
};
llvmStdenv = pkgs: pkgs.overrideCC pkgs.llvmPackages.stdenv
(pkgs.llvmPackages.stdenv.cc.override
{ inherit (pkgs.llvmPackages) bintools; });
deps = pkgs: mapAttrs (_: v: pkgs.fetchgit (v // { fetchSubmodules = true; }))
(fromJSON (readFile ./fc_deps.json));
fetchContentFlags = pkgs: mapAttrsToList
(n: v: "-DFETCHCONTENT_SOURCE_DIR_${toUpper n}=${v}")
(deps pkgs);
in
{
systems = lib.systems.flakeExposed;
inherit inputs;
devShell = pkgs: {
packages = with pkgs; [ clang-tools clangd-tidy git openssl.dev ];
env.NIX_HARDENING_ENABLE = "";
shellHook = ''
export MAKEFLAGS=-j
'';
};
devShells.clang = { lib, pkgs, ... }: {
imports = [ (config.devShell pkgs) ];
stdenv = lib.mkForce (llvmStdenv pkgs);
};
formatters = { llvmPackages, cmake-format, nodePackages, ... }:
let
fmt-c = "${llvmPackages.clang-unwrapped}/bin/clang-format -i";
fmt-cmake = "${cmake-format}/bin/cmake-format -i";
fmt-yaml =
"${nodePackages.prettier}/bin/prettier --write --parser yaml";
in
{
"*.c" = fmt-c;
"*.h" = fmt-c;
"CMakeLists.txt" = fmt-cmake;
".clang*" = fmt-yaml;
};
pname = "gg-sys-log-forwarder";
package = { pkgs, openssl, lib, stdenv, pkg-config, cmake, ninja, argp-standalone, systemdLibs, defaultMeta }:
stdenv.mkDerivation {
name = "gg-sys-log-forwarder";
src = filteredSrc;
nativeBuildInputs = [ pkg-config cmake ninja ];
buildInputs = [ openssl systemdLibs ] ++ lib.optional (!stdenv.hostPlatform.isGnu) argp-standalone;
cmakeBuildType = "MinSizeRel";
cmakeFlags = (fetchContentFlags pkgs) ++ [ "-DENABLE_WERROR=1" ];
dontStrip = true;
meta = defaultMeta;
};
checks =
let
clangBuildDir = { pkgs, pkg-config, clang-tools, openssl, systemd, cmake, ... }:
(llvmStdenv pkgs).mkDerivation {
name = "clang-cmake-build-dir";
nativeBuildInputs = [ pkg-config clang-tools ];
buildInputs = [ openssl systemd ];
buildPhase = ''
export PKG_CONFIG_PATH="${openssl.dev}/lib/pkgconfig:$PKG_CONFIG_PATH"
${cmake}/bin/cmake -B $out -S ${filteredSrc} \
-D CMAKE_BUILD_TYPE=Debug ${toString (fetchContentFlags pkgs)} \
-D CMAKE_C_FLAGS="-I${openssl.dev}/include -I${systemd.dev}/include"
rm $out/CMakeFiles/CMakeConfigureLog.yaml
'';
dontUnpack = true;
dontPatch = true;
dontConfigure = true;
dontInstall = true;
dontFixup = true;
allowSubstitutes = false;
};
in
{
build-clang = pkgs: pkgs.gg-sys-log-forwarder.override
{ stdenv = llvmStdenv pkgs; };
build-musl-pi = pkgs: pkgs.pkgsCross.muslpi.gg-sys-log-forwarder;
clang-tidy = pkgs: ''
set -eo pipefail
PATH=${lib.makeBinPath
(with pkgs; [clangd-tidy clang-tools fd])}:$PATH
clangd-tidy -j$(nproc) -p ${clangBuildDir pkgs} --color=always \
$(fd . ${filteredSrc}/src -e c -e h) |\
sed 's|\.\.${filteredSrc}/||'
'';
iwyu = pkgs: ''
set -eo pipefail
PATH=${lib.makeBinPath
(with pkgs; [include-what-you-use fd])}:$PATH
white=$(printf "\e[1;37m")
red=$(printf "\e[1;31m")
clear=$(printf "\e[0m")
iwyu_tool.py -o clang -j $(nproc) -p ${clangBuildDir pkgs} \
$(fd . ${filteredSrc}/ -e c) -- \
-Xiwyu --error -Xiwyu --check_also="${filteredSrc}/*" \
-Xiwyu --mapping_file=${./.}/misc/iwyu_mappings.yml \
-I${pkgs.openssl.dev}/include \
-I${pkgs.systemd.dev}/include |\
{ grep error: || true; } |\
sed 's|\(.*\)error:\(.*\)|'$white'\1'$red'error:'$white'\2'$clear'|' |\
sed 's|${filteredSrc}/||'
'';
cmake-lint = pkgs: ''
${pkgs.cmake-format}/bin/cmake-lint \
$(${pkgs.fd}/bin/fd '.*\.cmake|CMakeLists.txt') \
--suppress-decorations
'';
spelling = pkgs: ''
${pkgs.nodePackages.cspell}/bin/cspell "**" --quiet
${pkgs.coreutils}/bin/sort -cuf misc/dictionary.txt
'';
};
withOverlays = final: prev: {
clangd-tidy = final.callPackage
({ python3Packages }:
python3Packages.buildPythonPackage rec {
pname = "clangd_tidy";
version = "1.1.0.post1";
format = "pyproject";
src = final.fetchPypi {
inherit pname version;
hash = "sha256-wqwrdD+8kd2N0Ra82qHkA0T2LjlDdj4LbUuMkTfpBww=";
};
buildInputs = with python3Packages; [ setuptools-scm ];
propagatedBuildInputs = with python3Packages; [
attrs
cattrs
typing-extensions
];
})
{ };
};
});
}