-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
133 lines (114 loc) · 3.67 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
{
# mostly copied from jujutsu (https://github.com/martinvonz/jj)
description = "Mineclone - my minecraft clone with features I always wanted";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs = { self, nixpkgs, flake-utils, rust-overlay }: {
overlays.default = (final: prev: {
mineclone = self.packages.${final.system}.mineclone;
});
} //
(flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
rust-overlay.overlays.default
];
};
filterSrc = src: regexes:
pkgs.lib.cleanSourceWith {
inherit src;
filter = path: type:
let
relPath = pkgs.lib.removePrefix (toString src + "/") (toString path);
in
pkgs.lib.all (re: builtins.match re relPath == null) regexes;
};
rust-version = pkgs.rust-bin.stable."1.76.0".default;
ourRustPlatform = pkgs.makeRustPlatform {
rustc = rust-version;
cargo = rust-version;
};
# these are needed in both devShell and buildInputs
darwinDeps = with pkgs; lib.optionals stdenv.isDarwin [ ];
in
{
packages = {
mineclone = ourRustPlatform.buildRustPackage {
pname = "mineclone";
version = "unstable-${self.shortRev or "dirty"}";
src = filterSrc ./. [
".*\\.nix$"
"^.jj/"
"^flake\\.lock$"
"^target/"
];
cargoLock.lockFile = ./Cargo.lock;
useNextest = true;
nativeBuildInputs = [ ];
buildInputs = [ ] ++ darwinDeps;
# makes no sense in a nix package
CARGO_INCREMENTAL = "0";
preCheck = "export RUST_BACKTRACE=1";
# postInstall = ''
# tailwindcss -i styles/tailwind.css -o assets/main.css --minify
# '';
# for clap apps
# postInstall = ''
# $out/bin/mineclone util mangen > ./mineclone.1
# installManPage ./mineclone.1
#
# installShellCompletion --cmd mineclone \
# --bash <($out/bin/mineclone util completion --bash) \
# --fish <($out/bin/mineclone util completion --fish) \
# --zsh <($out/bin/mineclone util completion --zsh)
# '';
};
default = self.packages.${system}.mineclone;
};
apps.default = {
type = "app";
program = "${self.packages.${system}.mineclone}/bin/mineclone";
};
devShells.default = pkgs.mkShell rec {
buildInputs = with pkgs; [
# Should be before rust?.
(rust-bin.selectLatestNightlyWith (toolchain: toolchain.rustfmt))
# Using the minimal profile with explicit "clippy" extension to avoid
# two versions of rustfmt
(rust-version.override {
extensions = [
"rust-src" # for rust-analyzer
"clippy"
];
})
# Make sure rust-analyzer is present
rust-analyzer
cargo-nextest
cargo-watch
# cargo-insta
# cargo-deny
pkg-config
udev
alsa-lib
vulkan-loader
xorg.libXi
xorg.libXrandr
xorg.libXcursor
xorg.libX11
libxkbcommon
] ++ darwinDeps;
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
shellHook = ''
export RUST_BACKTRACE=1
'';
};
}));
}