-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
127 lines (118 loc) · 3.72 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
devshell.url = "github:numtide/devshell/main";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
flake-utils,
devshell,
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [devshell.overlays.default];
};
libraries = with pkgs; [
libjpeg_original
ncurses
libpng12
zlib
];
compiler = pkgs.gcc;
dev-deps = with pkgs; [glibc libcxx doxygen graphviz];
package-config = rec {
pname = "ascii-art";
packages-name = pname;
version = "v0.0.0";
src = pkgs.fetchFromGitHub {
owner = "dev-null-undefined";
repo = pname;
rev = version;
sha256 = "sha256-dQJjBH0gxn8FBMyyC9DRYOergOUzns/+jUNJ1KSVTtk=";
};
};
packages = {
${package-config.packages-name} = pkgs.stdenv.mkDerivation rec {
inherit (package-config) pname version src;
buildInputs = libraries ++ [pkgs.doxygen];
installPhase = ''
mkdir -p $out/bin
mv bin/${pname} $out/bin/
'';
meta = with pkgs.lib; {
homepage = "";
description = "";
longDescription = "";
platforms = platforms.linux;
};
};
default = self.packages.${system}.${package-config.packages-name};
};
default-app = {
type = "app";
program = self.packages.${system}.default + "/bin/${package-config.pname}";
};
in {
apps.default = default-app;
devShell = pkgs.devshell.mkShell {
name = package-config.pname;
imports = ["${devshell}/extra/language/c.nix"];
packages = dev-deps;
language.c = {
inherit compiler libraries;
includes = libraries;
};
commands = [
{
name = "compile";
category = "c++";
help = "Optimized compilation with nearly non logging";
command = "${pkgs.gnumake}/bin/make fast";
}
{
name = "debug";
category = "c++";
help = "Faster compilation with more debug info and logging";
command = "${pkgs.gnumake}/bin/make fast-debug";
}
{
name = "clean";
category = "c++";
help = "Clean binaries (Run this between all debug and release versions)";
command = "${pkgs.gnumake}/bin/make clean";
}
{
name = "run";
category = "testing";
command = "${pkgs.gnumake}/bin/make run";
}
{
name = "docs";
category = "c++";
help = "Generate documentation";
command = "${pkgs.gnumake}/bin/make docs";
}
];
bash = {
extra = ''
export CPLUS_INCLUDE_PATH="$C_INCLUDE_PATH"
export LIBRARY_PATH="$LD_LIBRARY_PATH"
'';
};
};
defaultPackage = self.packages.${system}.default;
inherit packages;
formatter = pkgs.alejandra;
cmake-helper = rec {
libs = builtins.map builtins.toString (builtins.map pkgs.lib.getLib libraries);
includes = builtins.map builtins.toString (builtins.map pkgs.lib.getDev libraries);
cmake-file = pkgs.writeText "CMakeList.txt" (pkgs.lib.strings.concatLines (
(builtins.map (lib: ''target_link_directories(''${CMAKE_PROJECT_NAME} PUBLIC ${lib}/lib)'') libs)
++ (builtins.map (include: ''include_directories(${include}/include)'') includes)
));
};
});
}