forked from DioxusLabs/dioxus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
131 lines (123 loc) · 4 KB
/
flake.nix
File metadata and controls
131 lines (123 loc) · 4 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
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
rust-overlay.url = "github:oxalica/rust-overlay";
crane.url = "github:ipetkov/crane";
};
outputs =
inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
perSystem =
{
self',
system,
...
}:
let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
inputs.rust-overlay.overlays.default
];
};
lib = pkgs.lib;
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [
"rust-src"
"rust-analyzer"
"clippy"
];
};
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain;
rustBuildInputs = [
pkgs.openssl
pkgs.libiconv
pkgs.pkg-config
]
++ lib.optionals pkgs.stdenv.isLinux [
pkgs.glib
pkgs.gtk3
pkgs.libsoup_3
pkgs.webkitgtk_4_1
pkgs.xdotool
]
++ lib.optionals pkgs.stdenv.isDarwin [
pkgs.apple-sdk
pkgs.libiconv
];
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
fullSrc = pkgs.lib.cleanSource ./.;
cargoSrc = craneLib.cleanCargoSource fullSrc;
commonArgs = {
src = fullSrc;
strictDeps = true;
buildInputs = rustBuildInputs;
nativeBuildInputs = [
pkgs.pkg-config
];
};
cargoArtifacts = craneLib.buildDepsOnly (
commonArgs
// {
src = cargoSrc;
pname = "dioxus-deps";
version = cargoToml.package.version;
}
);
rustPackage =
package:
{
binary ? package,
features ? [ ],
}:
craneLib.buildPackage (
commonArgs
// {
pname = package;
version = cargoToml.package.version;
inherit cargoArtifacts;
cargoExtraArgs = "--locked --package ${package} ${
lib.concatStringsSep " " (map (f: "--features ${f}") features)
}";
doCheck = false; # Disable tests to avoid building deps for them
installPhaseCommand = ''
mkdir -p $out/bin
cp target/release/${binary} $out/bin/
'';
}
);
in
{
packages.dioxus-cli =
(rustPackage "dioxus-cli" {
binary = "dx";
features = [ "no-downloads" ];
}).overrideAttrs
(_: {
# The nix sandbox has no .git and no .cargo_vcs_info.json, so
# build.rs has nothing to derive the commit from. Pass the
# flake's own input rev through the env-var override path.
# `self.rev` is set on a clean tree; `dirtyRev` on a dirty one
# (and includes a `-dirty` suffix, which build.rs accepts).
DIOXUS_CLI_GIT_SHA = inputs.self.rev or inputs.self.dirtyRev or "";
});
packages.default = self'.packages.dioxus-cli;
checks.dioxus-cli = self'.packages.dioxus-cli;
devShells.default = pkgs.mkShell {
name = "dioxus-dev";
buildInputs = rustBuildInputs;
nativeBuildInputs = [
# Add shell dependencies here
rustToolchain
];
shellHook = ''
# For rust-analyzer 'hover' tooltips to work.
export RUST_SRC_PATH="${rustToolchain}/lib/rustlib/src/rust/library";
'';
};
};
};
}