-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
200 lines (177 loc) · 6.74 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
{
description = "A collection of memory-reading utilities for the game Noita";
nixConfig = {
extra-substituters = [ "https://necauqua.cachix.org" ];
extra-trusted-public-keys = [ "necauqua.cachix.org-1:XG5McOG0XwQ9kayUuEiEn0cPoLAMvc2TVs3fXqv/7Uc=" ];
};
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
# I usually go with oxalica + nixpkkgs rust builder,
# but fenix + naersk seem to be more convenient for the
# windows cross-compilation
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
build-env = {
url = "file+file:///dev/null";
flake = false;
};
};
outputs = { self, nixpkgs, naersk, flake-utils, fenix, build-env }:
let
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
inherit (cargoToml.package) name version description;
in
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ fenix.overlays.default ];
};
toolchain = with pkgs.fenix;
combine [
(stable.withComponents [
"cargo"
"clippy"
"rust-src"
"rustc"
])
targets.x86_64-pc-windows-gnu.stable.rust-std
];
naersk-lib = naersk.lib.${system}.override {
cargo = toolchain;
rustc = toolchain;
};
dynamicDeps = with pkgs; lib.makeLibraryPath [
vulkan-loader
# It's annoying that you need either wayland or the xorg stuff,
# but never both - idk how to make this better, and having to have
# an LD_LIBRARY_PATH wrapper thing is cringe on its own
wayland
libxkbcommon
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libXrandr
];
buildPackage = attrs: naersk-lib.buildPackage (
{
inherit name version;
src = ./.;
strictDeps = true;
doCheck = true;
NIX_REV = self.rev or "dirty";
} // attrs // builtins.fromTOML (builtins.readFile "${build-env}")
);
wineWrap = name: cmd: pkgs.writeShellScript "${name}-in-wine" ''
export WINEPREFIX="$(mktemp -dt ${name}-wineprefix-XXXXXX)"
trap "rm -rf \"$WINEPREFIX\"" EXIT
exec ${pkgs.wineWowPackages.staging}/bin/wine64 ${cmd}
'';
in
rec {
packages = {
default = buildPackage {
nativeBuildInputs = with pkgs; [ makeWrapper copyDesktopItems pkg-config ];
buildInputs = [ pkgs.openssl ];
postInstall = ''
wrapProgram $out/bin/${name} --prefix LD_LIBRARY_PATH : ${dynamicDeps}
mkdir -p $out/share/icons/hicolor/256x256/apps
cp ${./res/icon.png} $out/share/icons/hicolor/256x256/apps/${name}.png
'';
desktopItems = [
(pkgs.makeDesktopItem {
inherit name;
exec = name;
icon = name;
desktopName = "Noita Utility Box";
comment = description;
categories = [ "System" "Utility" "Debugger" "Amusement" ];
})
];
};
# my bad, "unpatches your nix executable"
# this still depends on like glibc 2.39 so gl running this on ubuntu that's not the newest
linux = pkgs.stdenv.mkDerivation {
inherit name version;
src = packages.default;
phases = [ "installPhase" ];
installPhase = ''
cp -r $src $out
chmod -R +w $out
mv $out/bin/{.${name}-wrapped,${name}}
${pkgs.patchelf}/bin/patchelf $out/bin/${name} \
--set-interpreter "/lib64/ld-linux-x86-64.so.2" \
--set-rpath ""
'';
};
# idk lol, build all the things through nix
deb = pkgs.stdenv.mkDerivation {
inherit version;
name = "${name}.deb";
src = packages.linux;
phases = [ "installPhase" ];
installPhase = ''
mkdir -p package/{usr,DEBIAN}
cp -r $src/* package/usr
cat > package/DEBIAN/control <<EOF
Package: ${name}
Version: ${version}
Architecture: amd64
Maintainer: necauqua <him@necauq.ua>
Description: ${description}
Depends: openssl
EOF
${pkgs.dpkg}/bin/dpkg-deb --build package
mv package.deb $out
'';
};
windows = buildPackage {
depsBuildBuild = with pkgs.pkgsCross.mingwW64; [
stdenv.cc
windows.pthreads
];
nativeBuildInputs = [ pkgs.imagemagick ];
doCheck = false;
CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu";
# can run the tests in wine
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER = wineWrap "${name}-tests" "$@";
};
};
apps.default = {
type = "app";
program = "${packages.default}/bin/${name}";
};
# This is for testing only lul
# `nix run .#windows-with-wine` (or github:necauqua/noita-utility-box#windows-with-wine if not in the repo)
# Didn't find a way to run it in the Noita proton prefix in a way that allows sysinfo to find the noita process yet
apps.windows-with-wine = {
type = "app";
program = "${wineWrap name "${packages.windows}/bin/${name}.exe"}";
};
devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues packages;
nativeBuildInputs = with pkgs; [
# # inputsFrom does not seem to include the depsBuildBuild thing
# pkgsCross.mingwW64.stdenv.cc
# pkgsCross.mingwW64.windows.pthreads
rust-analyzer-nightly
pkgs.fenix.default.rustfmt-preview
cargo-nextest
p7zip
];
LD_LIBRARY_PATH = dynamicDeps;
RUSTDOCFLAGS = "-D warnings";
RUST_BACKTRACE = "full";
RUST_LOG = "info,wgpu_core=warn,wgpu_hal=warn,zbus=warn,noita_utility_box=trace";
};
}
);
}