-
Notifications
You must be signed in to change notification settings - Fork 8
/
flake.nix
106 lines (95 loc) · 2.57 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
pre-commit-hooks = {
url = "github:cachix/git-hooks.nix";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
};
outputs = {
self,
nixpkgs,
flake-utils,
pre-commit-hooks,
}:
flake-utils.lib.eachSystem [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
] (system: let
pkgs = nixpkgs.legacyPackages.${system};
in rec {
formatter = pkgs.alejandra;
checks = let
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
alejandra.enable = true;
clang-format.enable = true;
};
};
in
if (builtins.elem system flake-utils.lib.defaultSystems)
then {inherit pre-commit-check;}
else {};
devShells.default = pkgs.mkShell {
inherit (checks.pre-commit-check) shellHook;
hardeningDisable = ["fortify"];
inputsFrom = pkgs.lib.attrsets.attrValues packages;
packages = with pkgs; [
bear
python3Packages.compiledb
gcovr
clang-tools
];
};
packages = let
build-base = {
src = ./.;
nativeBuildInputs = with pkgs; [
gcc13
gnumake
# ↓ tput provider for colored makefile
ncurses
];
};
build-single-bin = name:
pkgs.stdenvNoCC.mkDerivation (build-base
// rec {
inherit name;
buildPhase = ''
make -C src/${name}
'';
installPhase = ''
mkdir -p $out/bin
install -D src/${name}/${name} $out/bin/${name} --mode 0755
'';
});
in
rec {
canoutils = default;
default = pkgs.stdenvNoCC.mkDerivation (build-base
// {
name = "canoutils";
installPhase = ''
mkdir -p $out/bin
find bin -type f | xargs -i install -D {} $out/{} --mode 0755
'';
});
}
// (with builtins;
listToAttrs (map
(name: {
inherit name;
value = build-single-bin name;
})
(attrNames (pkgs.lib.filterAttrs
(n: v: v == "directory" && n != "global")
(readDir ./src)))));
});
}