/
flake.nix
executable file
·118 lines (102 loc) · 3.78 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
# SPDX-FileCopyrightText: 2016-2022 by pi-lar GmbH
# SPDX-License-Identifier: OSL-3.0
{
description =
"neuropil is a secure messaging library for IoT, robotics and more.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?release-20.09";
msgpack-cmp = {
url = "github:camgunz/cmp/9fc01ddf";
flake = false;
};
parson = {
url = "github:kgabis/parson/302fba9";
flake = false;
}; # default = true
};
outputs = { self, nixpkgs, msgpack-cmp, parson, ... }:
let
# Generate a user-friendly version numer.
version = builtins.substring 0 8 (./.).lastModifiedDate;
# System types to support.
supportedSystems = [ "x86_64-linux" "x86_64-darwin" ];
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = f:
nixpkgs.lib.genAttrs supportedSystems (system: f system);
# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system:
import nixpkgs {
inherit system;
overlays = [ self.overlay ];
});
in {
overlay = final: prev:
with final; rec {
libneuropil = callPackage ./scripts/nix/neuropil.nix {
pkgs = final;
version = "prod";
ext = { inherit msgpack-cmp parson; };
};
neuropil_luajit = callPackage ./scripts/nix/neuropil-luajit.nix {
neuropil = libneuropil;
pkgs = final;
};
neuropil_python = callPackage ./scripts/nix/neuropil-python.nix {
neuropil = libneuropil;
pkgs = final;
};
neuropil_shell =
callPackage ./scripts/nix/shell.nix { pkgs = final; };
};
packages = forAllSystems (system: {
libneuropil = nixpkgsFor.${system}.libneuropil;
shell = nixpkgsFor.${system}.neuropil_shell;
neuropil_luajit = nixpkgsFor.${system}.neuropil_luajit;
neuropil_python = nixpkgsFor.${system}.neuropil_python;
});
defaultPackage =
forAllSystems (system: self.packages.${system}.libneuropil);
devShell = forAllSystems (system: self.packages.${system}.shell);
checks = forAllSystems (system: {
inherit (self.packages.${system}) libneuropil;
# Additional tests, if applicable.
test-import-lib = with nixpkgsFor.${system};
pkgs.runCommandCC "test-import-lib" {
buildInputs = [ libneuropil ];
} ''
echo 'try building with library'
$CC -lneuropil ${./examples/neuropil_receiver.c}
touch $out
'';
test-import-python = with nixpkgsFor.${system};
pkgs.runCommand "test-import-python" {
buildInputs = [ neuropil_python ];
} ''
echo 'try importing python module'
python -c 'import neuropil'
touch $out
'';
test-import-lua = with nixpkgsFor.${system};
pkgs.runCommand "test-import-lua" {
buildInputs = [ neuropil_luajit libneuropil ];
} ''
export LD_LIBRARY_PATH="${lib.makeLibraryPath [ libneuropil ]}"
echo 'try importing lua module'
luajit <(echo 'require("neuropil")')
touch $out
'';
# test-scons = with nixpkgsFor.${system};
# stdenv.mkDerivation {
# name = "test-scons";
# src = libneuropil.src;
# buildInputs = [ scons libsodium sqlite ncurses criterion (python3.withPackages (p: [p.requests])) ];
# buildPhase = ''
# ln -s ${msgpack-cmp} ext_tools/msgpack
# ln -s ${parson} ext_tools/parson
# scons --RELEASE tests
# '';
# installPhase = "touch $out";
# };
});
};
}