Skip to content

Commit

Permalink
feat: added nix flake (#10934)
Browse files Browse the repository at this point in the history
Adding a Nix flake for a deterministic development environment.

This currently provides only a development shell. To use it, ensure you have Nix installed with experimental features enabled and the nix command available. Then, run nix develop to enter a shell with all OS dependencies needed for development.

Future improvements may include automating build steps as well.






closes: #XXXX
refs: #XXXX

## Description


### Security Considerations


### Scaling Considerations


### Documentation Considerations


### Testing Considerations


### Upgrade Considerations
  • Loading branch information
mergify[bot] authored Feb 19, 2025
2 parents f2f2ac5 + a33cd79 commit 5d2b5c1
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/nix-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Nix Flake Check

on:
pull_request:
push:
branches:
- master
- 'release-*'
- 'dev-*'
permissions:
contents: read

jobs:
flake-check:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v9

- name: Enable flakes
uses: DeterminateSystems/magic-nix-cache-action@v2

- name: Check Nix flake inputs
run: nix flake check

- name: Show flake metadata
if: always() # Run even if previous step fails
run: nix flake metadata

- name: Validate flake outputs
if: always() # Run even if previous step fails
run: nix flake show

- name: Check build in Nix dev shell
run: |
# Enter nix develop and run build commands
nix develop --command bash -c '
# Install dependencies
yarn install
# Build the project
yarn build
# Build cosmic-swingset
cd packages/cosmic-swingset && make
'
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
description = "Agoric SDK Development Environment";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
# Custom Node.js 20.9.0 package
custom_node_20_9 = pkgs.stdenv.mkDerivation {
pname = "nodejs";
version = "20.9.0";

src = pkgs.fetchurl {
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";
sha256 = if pkgs.stdenv.isDarwin && pkgs.stdenv.isAarch64 then
"0snfsz2mmjdavi38nglayw5yia74q9h1xzz2ahpri8yqx1md9lii" # darwin-arm64
else if pkgs.stdenv.isDarwin then
"1j6cw6i3hjqv8zk1nbsqg560k7rgcmyl9cfd4vlvn5wclzr76nzw" # darwin-x64
else if pkgs.stdenv.isAarch64 then
"0skah3bal5irvramnfn86vgi0c375ywsyb4xaxmx3gvlnbpdp9yj" # linux-arm64
else if (pkgs.stdenv.isLinux && !pkgs.stdenv.isAarch64) then
"0q3gy4z5b8dd0w37ya5wlkbv4xhyqa1s0zwh71258x5z5w4rz4gh" # linux-x64
else
throw "Unsupported system: This derivation only supports Linux (x64/arm64) and Darwin (x64/arm64) systems";
};

installPhase = ''
echo "installing nodejs"
mkdir -p $out
cp -r ./ $out/
'';


# Meta information for the package
meta = with pkgs.lib; {
description = "Node.js 20.9.0 JavaScript runtime";
homepage = "https://nodejs.org";
license = licenses.mit;
platforms = platforms.unix;
};
};
in
{
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
custom_node_20_9
(yarn.override { nodejs = custom_node_20_9; })
(python3.withPackages (ps: [ ps.distutils ]))
pkg-config
go_1_23
gopls
delve
gcc
gnumake
protobuf
buf
git
];

shellHook = ''
export PATH=$PATH:$HOME/go/bin
echo "Node.js $(node --version)"
echo "NPM $(npm --version)"
echo "Yarn using Node.js $(yarn node -v)"
'';
};
}
);
}

0 comments on commit 5d2b5c1

Please sign in to comment.