-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
123 lines (117 loc) · 4.1 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
{
description = "midi_mapper";
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
my-lib.url = "github:zmrocze/nix-lib";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
};
outputs = inputs@{ self, nixpkgs, flake-parts, my-lib, crane, flake-utils, ... }:
let
myLib = my-lib.lib;
in
flake-parts.lib.mkFlake { inherit inputs; }
{
imports = [
inputs.my-lib.flakeModules.pkgs
];
pkgsConfig = {
overlays = [
inputs.my-lib.overlays.default
];
# systems = [ "x86_64-linux" ];
};
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
perSystem = { pkgs, lib, system, ... }: let
craneLib = crane.mkLib pkgs;
src = craneLib.cleanCargoSource (craneLib.path ./.);
commonArgs = {
inherit src;
strictDeps = true;
cargoExtraArgs = "--profile release";
nativeBuildInputs = with pkgs; [
# alsa
# alsa-lib
pkg-config
];
# todo: check order if changes sth inside single *inputs, gh issue add this
buildInputs = with pkgs; [
alsa-lib
];
PKG_CONFIG_PATH = "${pkgs.alsa-lib}/lib/pkgconfig";
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
individualCrateArgs = commonArgs // {
inherit cargoArtifacts;
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
doCheck = false;
};
fileSetForCrate = crate: lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
./utils
./lib
crate
];
};
# Build the top-level crates of the workspace as individual derivations.
# This allows consumers to only depend on (and build) only what they need.
# Though it is possible to build the entire workspace as a single derivation,
# so this is left up to you on how to organize things
midi_mapper = craneLib.buildPackage (myLib.recursiveUpdateConcat individualCrateArgs {
pname = "midi_mapper";
src = fileSetForCrate ./exe;
cargoExtraArgs = "--profile release --bin midi_mapper";
runtimeInputs = with pkgs; [
dhall-yaml
];
nativeBuildInputs = with pkgs; [
dhall-yaml
];
buildInputs = with pkgs; [
dhall-yaml
];
});
midi_printer = craneLib.buildPackage (individualCrateArgs // {
pname = "midi_printer";
src = fileSetForCrate ./exe;
cargoExtraArgs = "--profile release --bin midi_printer";
});
midi_mapper-wrapped = pkgs.writeShellApplication {
name = "midi_mapper";
runtimeInputs = [ pkgs.dhall-yaml midi_mapper ];
text = ''
midi_mapper "$@"
'';
};
in {
packages = {
inherit midi_printer;
midi_mapper = midi_mapper-wrapped;
};
apps = {
midi_mapper = flake-utils.lib.mkApp {
drv = midi_mapper-wrapped;
};
midi_printer = flake-utils.lib.mkApp {
drv = midi_printer;
};
};
devShells.default = craneLib.devShell {
# Inherit inputs from checks.
checks = self.checks.${system};
# Additional dev-shell environment variables can be set directly
# MY_CUSTOM_DEVELOPMENT_VAR = "something else";
# Extra inputs can be added here; cargo and rustc are provided by default.
packages = [
];
};
};
};
}