-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
137 lines (134 loc) · 4.12 KB
/
Copy pathflake.nix
File metadata and controls
137 lines (134 loc) · 4.12 KB
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
128
129
130
131
132
133
134
135
136
137
{
description = "Rust development environment";
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
git-hooks.url = "github:cachix/git-hooks.nix";
git-hooks.inputs.nixpkgs.follows = "nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs@{ self, ... }:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.git-hooks.flakeModule
inputs.treefmt-nix.flakeModule
];
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
perSystem =
{
config,
lib,
pkgs,
system,
...
}:
let
pname = "graylog-cli";
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.version;
commonArgs = {
inherit pname version;
src = self;
cargoLock.lockFile = ./Cargo.lock;
};
nativePackage = pkgs.rustPlatform.buildRustPackage (
commonArgs
// {
# On Darwin, Nix embeds its own store path for libiconv into the
# binary. Rewrite it to the system path so the binary runs on
# machines without Nix installed.
postInstall = lib.optionalString pkgs.stdenv.isDarwin ''
install_name_tool \
-change "$(otool -L $out/bin/graylog-cli \
| awk '/libiconv/{print $1}')" \
/usr/lib/libiconv.2.dylib \
$out/bin/graylog-cli
'';
}
);
windowsTarget = "x86_64-pc-windows-gnu";
windowsPkgs = pkgs.pkgsCross.mingwW64;
windowsToolchain =
with inputs.fenix.packages.${system};
combine [
stable.cargo
stable.rustc
targets.${windowsTarget}.stable.rust-std
];
windowsRustPlatform = windowsPkgs.makeRustPlatform {
cargo = windowsToolchain;
rustc = windowsToolchain;
};
windowsPackage = windowsRustPlatform.buildRustPackage (
commonArgs
// {
cargoBuildTarget = windowsTarget;
depsBuildBuild = lib.optionals pkgs.stdenv.isDarwin [
pkgs.libiconv
];
NIX_LDFLAGS = lib.optionalString pkgs.stdenv.isDarwin "-L${pkgs.libiconv}/lib";
stdenv = windowsPkgs.stdenv;
}
);
in
{
packages = {
default = nativePackage;
graylog-cli-windows = windowsPackage;
};
treefmt = {
programs.nixfmt.enable = true;
programs.nixfmt.package = pkgs.nixfmt;
programs.rustfmt.enable = true;
};
pre-commit.settings.hooks = {
treefmt.enable = true;
};
devShells.default = pkgs.mkShell {
inherit (config.pre-commit) shellHook;
packages =
with pkgs;
[
rustToolchain
cargo-deny
cargo-edit
cargo-watch
cargo-wizard
cargo-nextest
rust-analyzer
]
++ config.pre-commit.settings.enabledPackages;
env = {
RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library";
};
};
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = lib.attrValues self.overlays;
};
};
flake.overlays.default = final: prev: {
rustToolchain =
with inputs.fenix.packages.${prev.stdenv.hostPlatform.system};
combine (
with stable;
[
clippy
rustc
cargo
rustfmt
rust-src
]
);
};
};
}