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

add flake.nix #262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target
__pycache__
.vscode
.idea
.idea
result
104 changes: 104 additions & 0 deletions flake.lock

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

124 changes: 124 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
description = "Build teos (The Eye of Satoshi) server and plugin";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

Choose a reason for hiding this comment

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

I prefer stability so better to point at nixos-24.05.


crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};

fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-analyzer-src.follows = "";
};

flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, crane, fenix, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};

inherit (pkgs) lib;

craneLib = crane.mkLib pkgs;
src = craneLib.cleanCargoSource ./.;

# Common arguments can be set here to avoid repeating them later
commonArgs = {
inherit src;
strictDeps = true;

nativeBuildInputs = [
pkgs.pkg-config
pkgs.openssl
pkgs.rustfmt # needed for tonic build
];

buildInputs = [
# Add additional build inputs here
pkgs.pkg-config
] ++ lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];

# TODO: hack but without there are warnings and I can't make other method work
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 curious about what the issue with this is. I'm not familiar with Nix so just wondering

Copy link
Author

@RCasatta RCasatta Jul 29, 2024

Choose a reason for hiding this comment

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

The issue is that changing the released version in Cargo.toml require changing the version here, while instead the value should be read from the Cargo.toml thus not requiring to keep this file in sync.

Choose a reason for hiding this comment

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

Crane is expecting a version in the workspace Cargo.toml. So either you can add one or it won't be possible to build just the dependencies (without warnings).

pname = "teos";
version = "0.2.0";

PROTOC = "${pkgs.protobuf}/bin/protoc";
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
};

craneLibLLvmTools = craneLib.overrideToolchain
(fenix.packages.${system}.complete.withComponents [
"cargo"
"llvm-tools"
"rustc"
]);

# Build *just* the cargo dependencies (of the entire workspace),
# so we can reuse all of that work (e.g. via cachix) when running in CI
# It is *highly* recommended to use something like cargo-hakari to avoid
# cache misses when building individual top-level-crates
cargoArtifacts = craneLib.buildDepsOnly commonArgs;

individualCrateArgs = commonArgs // {
inherit cargoArtifacts;
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
# NB: we disable tests since we'll run them all via cargo-nextest
doCheck = false;

Choose a reason for hiding this comment

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

No cargo-nextest check configured in the flake so remove this I think.

};

fileSetForCrate = crate: lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
./teos-common
./watchtower-plugin
./teos
crate
];
};

# Build the top-level crates of the workspace as individual derivations.
# This allows consumers to only depend on (and build) only what they need.
# Though it is possible to build the entire workspace as a single derivation,
# so this is left up to you on how to organize things
plugin = craneLib.buildPackage (individualCrateArgs // {
pname = "watchtower-plugin";
version = "0.2.0"; # TODO: hack but without there are warnings and I can't make other method work
cargoExtraArgs = "-p watchtower-plugin";
src = fileSetForCrate ./watchtower-plugin;
});
teos = craneLib.buildPackage (individualCrateArgs // {
pname = "teos";
version = "0.2.0"; # TODO: hack but without there are warnings and I can't make other method work
cargoExtraArgs = "-p teos";
src = fileSetForCrate ./teos;
});
in
{
packages = {
inherit plugin teos;
default = teos;
};

apps = {
plugin = flake-utils.lib.mkApp {
drv = plugin;
};
teos = flake-utils.lib.mkApp {
drv = teos;
};
};

});
}