-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
93 lines (86 loc) · 2.55 KB
/
flake.nix
File metadata and controls
93 lines (86 loc) · 2.55 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
{
description = "A basic Rust project";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
rust-overlay,
flake-utils,
...
}: let
systems = flake-utils.lib.defaultSystems ++ ["riscv64-linux"];
in
flake-utils.lib.eachSystem systems (
system: let
overlays = [(import rust-overlay)];
pkgs = import nixpkgs {
inherit system overlays;
};
rustVersion = pkgs.rust-bin.stable.latest.default;
packageMetadata = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package;
pname = packageMetadata.name;
inherit (packageMetadata) version;
nodeDependencies = pkgs.buildNpmPackage {
inherit version;
pname = "${pname}-node-deps";
src = ./.;
npmDepsHash = "sha256-78WzgrRJ7lSQSFb1NDTpNsz7sPsjh+M8qxxwoSz9fXc=";
installPhase = ''
runHook preInstall
mkdir -p $out/dist
cp -r dist/* $out/dist
cp -r node_modules $out
runHook postInstall
'';
};
rustPackageOptions = {
inherit pname version;
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
allowBuiltinFetchGit = true;
};
BAYBRIDGE_DIST_PATH = "${nodeDependencies}/dist";
BAYBRIDGE_CHARTJS_DIST_PATH = "${nodeDependencies}/node_modules/chart.js/dist";
buildInputs = [
nodeDependencies
];
};
in {
devShells.default = pkgs.mkShell {
buildInputs = [
rustVersion
pkgs.cargo-watch
pkgs.just
pkgs.nodejs
pkgs.rust-analyzer
pkgs.pkg-config
];
};
packages = {
inherit nodeDependencies;
default = pkgs.rustPlatform.buildRustPackage rustPackageOptions;
static = pkgs.pkgsStatic.rustPlatform.buildRustPackage rustPackageOptions;
docker = pkgs.dockerTools.buildLayeredImage {
name = pname;
tag = version;
extraCommands = ''
mkdir -p -m 1777 .local
'';
config = {
Entrypoint = ["${self.packages.${system}.default}/bin/${pname}"];
Cmd = ["serve"];
User = "100";
};
};
};
}
);
}