-
Notifications
You must be signed in to change notification settings - Fork 162
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
ci: nix flake #5267
Draft
lemmih
wants to merge
18
commits into
main
Choose a base branch
from
lemmih/nix-flake
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+382
−0
Draft
ci: nix flake #5267
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
58d9688
basic nix build script
lemmih 22ce89e
go is not a runtime dependency
lemmih 98ebdba
expose individual binaries, include README.nix.md
lemmih b0e1db1
Add installation instructions with nix
lemmih 44a7132
Add nix instructions to the users' guide
lemmih 122f08c
Explicitly set go cache locations
lemmih 1ad8c9e
add nix github workflow
lemmih ca58efb
disable f3-sidecar in nix build
lemmih 11c3123
vendor go dependencies
lemmih bbadfe6
forest depends on clang
lemmih a46c905
clean up nix flake
lemmih 2079940
add nix dry run to debug caching
lemmih 9760a90
bump checkout version
lemmih 460e38b
Only run on non-draft PRs
lemmih db90557
update with notice about flakehub warning.
lemmih 79d6679
only compile dependencies on github
lemmih 5c3f8c1
ubuntu-24.04-arm migth be slightly broken
lemmih 85f9985
Merge branch 'main' into lemmih/nix-flake
lemmih File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: nix | ||
on: | ||
workflow_dispatch: | ||
merge_group: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
LesnyRumcajs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
jobs: | ||
build-nix-package: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-14] | ||
lemmih marked this conversation as resolved.
Show resolved
Hide resolved
LesnyRumcajs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
runs-on: ${{ matrix.os }} | ||
permissions: | ||
contents: read | ||
id-token: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: DeterminateSystems/nix-installer-action@main | ||
with: | ||
determinate: true | ||
- uses: DeterminateSystems/flakehub-cache-action@main | ||
- run: nix build --dry-run | ||
- run: nix build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lemmih marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Using Nix with Forest | ||
|
||
This guide will help you get started with building and installing Forest using | ||
Nix. | ||
|
||
## Installing Nix | ||
|
||
The recommended way to install Nix is using Determinate Systems' Nix installer: | ||
|
||
1. Run the following command in your terminal: | ||
```bash | ||
curl -fsSL https://install.determinate.systems/nix | sh -s -- install --determinate | ||
``` | ||
|
||
2. After installation, restart your shell or run: | ||
```bash | ||
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh | ||
``` | ||
|
||
See [Determinate Systems' Nix installation | ||
guide](https://docs.determinate.systems/getting-started/individuals) for more | ||
information. | ||
|
||
## Building Forest with Flakes | ||
|
||
Forest uses Nix flakes for reproducible builds. To build Forest: | ||
|
||
1. Clone the Forest repository | ||
2. Run the following command in the repository root: | ||
```bash | ||
nix build | ||
lemmih marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
This will build Forest and all its dependencies in a reproducible environment. | ||
|
||
## Installing Forest | ||
|
||
To install Forest directly from the repository: | ||
|
||
```bash | ||
nix profile install . | ||
``` | ||
|
||
This will make the following Forest commands available in your shell: | ||
- `forest` - The main Forest daemon | ||
- `forest-cli` - Command line interface for interacting with Forest | ||
- `forest-tool` - Utility tools for Forest | ||
- `forest-wallet` - Forest wallet management | ||
|
||
You can now run any of these commands directly from your shell. | ||
|
||
## Upgrading Forest | ||
|
||
To upgrade Forest to the latest version: | ||
|
||
```bash | ||
nix profile upgrade forest | ||
``` | ||
|
||
## Removing Forest | ||
|
||
To remove Forest from your system: | ||
|
||
```bash | ||
nix profile remove forest | ||
``` | ||
|
||
You can also list your current profile installations using: | ||
|
||
```bash | ||
nix profile list | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
If you encounter any issues with Nix: | ||
- Make sure you have the latest version of Nix installed | ||
- Try running `nix-collect-garbage` if you're running low on disk space | ||
|
||
### Build Environment Limitations | ||
|
||
- Nix builds occur in a read-only environment. This means that build scripts | ||
cannot generate or modify source files during the build process | ||
- If your build requires non-Rust files (e.g., JSON, proto files, or other | ||
assets), they must be explicitly listed in the flake.nix file | ||
- If you see errors about missing files during the build, check that they are | ||
properly included in the flake's source inputs | ||
|
||
Example error messages you might encounter: | ||
- "Permission denied" when trying to write files during build | ||
- "File not found" for non-Rust files that aren't explicitly included in the | ||
flake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
{ | ||
description = "Forest - A Rust implementation of Filecoin"; | ||
|
||
inputs = { | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; | ||
crane.url = "github:ipetkov/crane"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
rust-overlay = { | ||
url = "github:oxalica/rust-overlay"; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
}; | ||
|
||
outputs = { | ||
self, | ||
nixpkgs, | ||
crane, | ||
flake-utils, | ||
rust-overlay, | ||
... | ||
}: | ||
flake-utils.lib.eachDefaultSystem (system: let | ||
pkgs = import nixpkgs { | ||
inherit system; | ||
overlays = [(import rust-overlay)]; | ||
}; | ||
|
||
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; | ||
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; | ||
|
||
# This is a hack to get the f3-sidecar vendor files into the build directory | ||
f3-sidecar-files = pkgs.buildGoModule { | ||
pname = "f3-sidecar-files"; | ||
version = "0.1.0"; | ||
src = pkgs.lib.cleanSourceWith { | ||
src = ./f3-sidecar; | ||
}; | ||
buildPhase = '' | ||
mkdir -p $out | ||
cp -r . $out | ||
''; | ||
vendorHash = "sha256-Pe3bgBZr8pdn2XVOQRvEjvnXldw7N1ehv0zY51kGSSk="; | ||
}; | ||
|
||
src = pkgs.lib.cleanSourceWith { | ||
src = ./.; | ||
filter = path: type: | ||
(craneLib.filterCargoSources path type) | ||
|| (type == "regular" && pkgs.lib.hasSuffix ".stpl" path) | ||
|| (type == "regular" && pkgs.lib.hasSuffix ".json" path) | ||
|| (type == "regular" && pkgs.lib.hasSuffix ".car" path) | ||
|| (type == "regular" && pkgs.lib.hasSuffix ".txt" path) | ||
|| (pkgs.lib.hasInfix "/build/" path) | ||
|| (pkgs.lib.hasInfix "/f3-sidecar/" path) | ||
|| (pkgs.lib.hasInfix "/test-snapshots/" path); | ||
}; | ||
|
||
# Common arguments can be set here to avoid repeating them later | ||
commonArgs = { | ||
inherit src; | ||
|
||
buildInputs = with pkgs; [ | ||
# Add runtime dependencies here | ||
]; | ||
|
||
nativeBuildInputs = with pkgs; [ | ||
# Add build-time dependencies here | ||
go # For rust2go compilation | ||
clang # For C/C++ compilation | ||
]; | ||
|
||
doCheck = false; | ||
}; | ||
|
||
# Build *just* the cargo dependencies, so we can reuse | ||
# all of that work (e.g. via cachix) when running in CI | ||
cargoArtifacts = craneLib.buildDepsOnly commonArgs; | ||
|
||
# Build the actual crate itself, reusing the dependency | ||
# artifacts from above. | ||
forest = craneLib.buildPackage (commonArgs | ||
// { | ||
inherit cargoArtifacts; | ||
preConfigure = '' | ||
export GOCACHE=$(mktemp -d) | ||
export GOMODCACHE=$(mktemp -d) | ||
''; | ||
preBuild = '' | ||
# Copy f3-sidecar files into the build directory | ||
cp -r ${f3-sidecar-files}/vendor f3-sidecar/ | ||
''; | ||
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; | ||
# Environment variables needed for the build | ||
# FOREST_F3_SIDECAR_FFI_BUILD_OPT_OUT = "1"; | ||
}); | ||
in { | ||
checks = { | ||
# Build the crate as part of `nix flake check` for convenience | ||
inherit forest; | ||
}; | ||
|
||
packages.default = forest; | ||
|
||
apps = let | ||
binaries = ["forest" "forest-cli" "forest-tool" "forest-wallet"]; | ||
mkBinApp = name: | ||
flake-utils.lib.mkApp { | ||
drv = forest; | ||
inherit name; | ||
}; | ||
in | ||
{ | ||
default = mkBinApp "forest"; | ||
} | ||
// builtins.listToAttrs (map (name: { | ||
inherit name; | ||
value = mkBinApp name; | ||
}) | ||
binaries); | ||
|
||
devShells.default = pkgs.mkShell { | ||
inputsFrom = builtins.attrValues self.checks.${system}; | ||
|
||
# Additional dev-shell environment variables can be set directly | ||
shellHook = '' | ||
echo "Forest development shell" | ||
''; | ||
}; | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lemmih what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update PR in a bit.