Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added nix flake #10934

Merged
merged 12 commits into from
Feb 19, 2025
49 changes: 49 additions & 0 deletions .github/workflows/nix-check.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad there's CI for this feature! That should prevent accidental breakage.

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 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this flake depend on configuration from your system wide flake? Because when I try to build it I get the following error.

nix build
error: flake 'git+file:///Users/touseefliaqat/code/agoric-sdk' does not provide attribute 'packages.aarch64-darwin.default' or 'defaultPackage.aarch64-darwin'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm it should not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should not, how did you installed nix? make sure flakes are enable to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh oh, actually here you only need to run nix develop not nix build, I have only define a devshell I have not define a build shell yet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember how i installed nix.
how to check if it has flakes enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in your nix config file generally: ~/.config/nix/nix.conf
ensure this configuration is set: experimental-features = nix-command flakes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@toliaqat lmk if it worked for you, remember to just run nix develop

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)"
'';
};
}
);
}
Loading