-
Notifications
You must be signed in to change notification settings - Fork 2
/
flake.nix
88 lines (78 loc) · 2.39 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
{
description = "A CLI batch downloader for your Bandcamp collection.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
fenix.url = "github:nix-community/fenix";
naersk.url = "github:nix-community/naersk/master";
};
outputs = {
fenix,
nixpkgs,
naersk,
...
}: let
buildTargets = {
"x86_64-linux" = "x86_64-unknown-linux-musl";
"aarch64-linux" = "aarch64-unknown-linux-musl";
"x86_64-darwin" = "x86_64-apple-darwin";
"aarch64-darwin" = "aarch64-apple-darwin";
};
systems = builtins.attrNames buildTargets;
# forSystems [...system] (system: ...)
forSystems = systems: fn:
nixpkgs.lib.genAttrs systems (system: fn system);
# crossForSystems [...system] (hostSystem: targetSystem: ...)
crossForSystems = systems: fn:
forSystems systems (
hostSystem:
builtins.foldl'
(acc: targetSystem:
acc
// {
"cross-${targetSystem}" = fn hostSystem targetSystem;
})
{default = fn hostSystem hostSystem;}
systems
);
mkBandsnatch = hostSystem: targetSystem: let
rustTarget = buildTargets.${targetSystem};
pkgs = import nixpkgs {system = hostSystem;};
pkgsCross = import nixpkgs {
system = hostSystem;
crossSystem.config = rustTarget;
};
fenixPkgs = fenix.packages.${hostSystem};
toolchain = fenixPkgs.combine [
fenixPkgs.stable.rustc
fenixPkgs.stable.cargo
fenixPkgs.targets.${rustTarget}.stable.rust-std
];
naersk-lib = pkgs.callPackage naersk {
cargo = toolchain;
rustc = toolchain;
};
TARGET_CC = "${pkgsCross.stdenv.cc}/bin/${pkgsCross.stdenv.cc.targetPrefix}cc";
in
naersk-lib.buildPackage {
src = ./.;
strictDeps = true;
doCheck = false;
inherit TARGET_CC;
CARGO_BUILD_TARGET = rustTarget;
CARGO_BUILD_RUSTFLAGS = [
"-C"
"target-feature=+crt-static"
"-C"
"linker=${TARGET_CC}"
];
};
in {
packages = crossForSystems systems mkBandsnatch;
devShells = forSystems systems (
system: let
pkgs = nixpkgs.legacyPackages.${system};
fenixPkgs = fenix.packages.${system};
in {default = pkgs.mkShell {nativeBuildInputs = [fenixPkgs.stable.toolchain];};}
);
};
}