Skip to content

Commit 1ea0d4b

Browse files
feat: nix improvements for modularity (#11032)
This PR improves the flake stack to be more modular, and easy to read, getting ready for a proto tooling inclution
1 parent 252b405 commit 1ea0d4b

File tree

4 files changed

+125
-87
lines changed

4 files changed

+125
-87
lines changed

flake.lock

+43-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+28-65
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,38 @@
11
{
2-
description = "Agoric SDK Development Environment";
2+
description = "Agoric SDK";
33

44
inputs = {
55
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6-
flake-utils.url = "github:numtide/flake-utils";
6+
unstable-nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
7+
# Track a separate nixpkgs for JS/TS toolchains
8+
nixpkgs-js.url = "github:NixOS/nixpkgs/nixos-unstable";
9+
flake-parts = {
10+
url = "github:hercules-ci/flake-parts";
11+
inputs.nixpkgs-lib.follows = "nixpkgs";
12+
};
713
};
814

9-
outputs = { self, nixpkgs, flake-utils }:
10-
flake-utils.lib.eachDefaultSystem (system:
11-
let
12-
pkgs = nixpkgs.legacyPackages.${system};
13-
# Custom Node.js 20.9.0 package
14-
custom_node_20_9 = pkgs.stdenv.mkDerivation {
15-
pname = "nodejs";
16-
version = "20.9.0";
17-
18-
src = pkgs.fetchurl {
19-
url = "https://nodejs.org/dist/v20.9.0/node-v20.9.0-${if pkgs.stdenv.isDarwin then "darwin" else "linux"}-${if pkgs.stdenv.isAarch64 then "arm64" else "x64"}.tar.gz";
20-
sha256 = if pkgs.stdenv.isDarwin && pkgs.stdenv.isAarch64 then
21-
"0snfsz2mmjdavi38nglayw5yia74q9h1xzz2ahpri8yqx1md9lii" # darwin-arm64
22-
else if pkgs.stdenv.isDarwin then
23-
"1j6cw6i3hjqv8zk1nbsqg560k7rgcmyl9cfd4vlvn5wclzr76nzw" # darwin-x64
24-
else if pkgs.stdenv.isAarch64 then
25-
"0skah3bal5irvramnfn86vgi0c375ywsyb4xaxmx3gvlnbpdp9yj" # linux-arm64
26-
else if (pkgs.stdenv.isLinux && !pkgs.stdenv.isAarch64) then
27-
"0q3gy4z5b8dd0w37ya5wlkbv4xhyqa1s0zwh71258x5z5w4rz4gh" # linux-x64
28-
else
29-
throw "Unsupported system: This derivation only supports Linux (x64/arm64) and Darwin (x64/arm64) systems";
30-
};
15+
outputs = inputs @ { self, nixpkgs, flake-parts, ... }:
16+
flake-parts.lib.mkFlake { inherit inputs; } {
17+
systems = [
18+
"x86_64-linux"
19+
"aarch64-linux"
20+
"aarch64-darwin"
21+
"x86_64-darwin"
22+
];
23+
24+
imports = [
25+
./nix/nodejs.nix
26+
./nix/devShell.nix
27+
];
3128

32-
installPhase = ''
33-
echo "installing nodejs"
34-
mkdir -p $out
35-
cp -r ./ $out/
36-
'';
37-
38-
39-
# Meta information for the package
40-
meta = with pkgs.lib; {
41-
description = "Node.js 20.9.0 JavaScript runtime";
42-
homepage = "https://nodejs.org";
43-
license = licenses.mit;
44-
platforms = platforms.unix;
45-
};
29+
perSystem = { self', pkgs, system, ... }:
30+
let
31+
unstablePkgs = import inputs.nixpkgs-unstable { inherit system; };
32+
in
33+
{
34+
# Your minimal perSystem config
4635
};
47-
in
48-
{
49-
devShells.default = pkgs.mkShell {
50-
buildInputs = with pkgs; [
51-
custom_node_20_9
52-
(yarn.override { nodejs = custom_node_20_9; })
53-
(python3.withPackages (ps: [ ps.distutils ]))
54-
pkg-config
55-
go_1_23
56-
gopls
57-
delve
58-
gcc
59-
gnumake
60-
protobuf
61-
buf
62-
git
63-
];
36+
};
6437

65-
shellHook = ''
66-
export PATH=$PATH:$HOME/go/bin
67-
68-
echo "Node.js $(node --version)"
69-
echo "NPM $(npm --version)"
70-
echo "Yarn using Node.js $(yarn node -v)"
71-
'';
72-
};
73-
}
74-
);
7538
}

nix/devShell.nix

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{ self', inputs, ... }: {
2+
perSystem = { system, pkgs, nodePkgs, ... }:
3+
let
4+
unstablePkgs = import inputs.unstable-nixpkgs { inherit system; };
5+
in
6+
{
7+
devShells.default = pkgs.mkShell {
8+
name = "agoric-devShell";
9+
buildInputs = with unstablePkgs; [
10+
git
11+
go_1_23
12+
gopls
13+
(python3.withPackages (ps: [ ps.distutils ]))
14+
pkg-config
15+
go-tools
16+
gotools
17+
delve
18+
gcc
19+
gnumake
20+
protobuf
21+
buf
22+
] ++ (with nodePkgs; [
23+
nodejs
24+
yarn
25+
]);
26+
27+
shellHook = ''
28+
export PATH=$PATH:$HOME/go/bin
29+
30+
echo "Node.js $(node --version)"
31+
echo "NPM $(npm --version)"
32+
echo "Yarn using Node.js $(yarn node -v)"
33+
'';
34+
};
35+
};
36+
}

nix/nodejs.nix

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{ self', inputs, ... }: {
2+
perSystem = { system, ... }: {
3+
# Define a new module argument that other modules can use
4+
_module.args.nodePkgs = import inputs.nixpkgs-js {
5+
inherit system;
6+
7+
# Add custom overlay for Node.js
8+
overlays = [
9+
(final: prev: {
10+
nodejs = prev.nodejs_20;
11+
yarn = prev.yarn.override {
12+
nodejs = prev.nodejs_20;
13+
};
14+
})
15+
];
16+
};
17+
};
18+
}

0 commit comments

Comments
 (0)