Merge pull request #266 from hashrelay/flake

Add nix flake.

This allow to build the project executables with nix.
This commit is contained in:
Omer Yacine 2025-10-09 12:06:06 +02:00 committed by GitHub
commit be344ecc52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 246 additions and 2 deletions

View file

@ -66,4 +66,17 @@ jobs:
uses: psf/black@stable
with:
src: "./watchtower-plugin/tests"
options: "--check -l 120"
options: "--check -l 120"
check-flake:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Check Nix flake inputs
uses: DeterminateSystems/flake-checker-action@v12
- name: Install Nix
uses: cachix/install-nix-action@v31
- name: Check flake
run: nix flake check

3
.gitignore vendored
View file

@ -1,4 +1,5 @@
target
__pycache__
.vscode
.idea
.idea
result

116
flake.lock generated Normal file
View file

@ -0,0 +1,116 @@
{
"nodes": {
"crane": {
"locked": {
"lastModified": 1758758545,
"narHash": "sha256-NU5WaEdfwF6i8faJ2Yh+jcK9vVFrofLcwlD/mP65JrI=",
"owner": "ipetkov",
"repo": "crane",
"rev": "95d528a5f54eaba0d12102249ce42f4d01f4e364",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1758782550,
"narHash": "sha256-olCvyP5r6+HQTl2EUudtjlA5UammsBpkzAl0l9+utZc=",
"owner": "nix-community",
"repo": "fenix",
"rev": "32f4e350c03cc5762be811e9c700e8696cd13c02",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1758589230,
"narHash": "sha256-zMTCFGe8aVGTEr2RqUi/QzC1nOIQ0N1HRsbqB4f646k=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "d1d883129b193f0b495d75c148c2c3a7d95789a0",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-25.05",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"crane": "crane",
"fenix": "fenix",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1758620797,
"narHash": "sha256-Ly4rHgrixFMBnkbMursVt74mxnntnE6yVdF5QellJ+A=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "905641f3520230ad6ef421bcf5da9c6b49f2479b",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

114
flake.nix Normal file
View file

@ -0,0 +1,114 @@
{
description = "Build teos (The Eye of Satoshi) server and plugin";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
crane.url = "github:ipetkov/crane";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
nixpkgs,
crane,
fenix,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
craneLib = (crane.mkLib pkgs).overrideToolchain fenix.packages.${system}.stable.minimalToolchain;
env = {
PROTOC = "${pkgs.protobuf}/bin/protoc";
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.openssl.out ];
};
commonArgs = {
inherit env;
strictDeps = true;
nativeBuildInputs = [
pkgs.pkg-config
pkgs.rustfmt # needed for tonic build
pkgs.cacert
pkgs.openssl.dev
];
buildInputs =
[ ]
++ lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
};
fileSetForCrate =
crate:
lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
./teos-common
./teos
./watchtower-plugin
crate
];
};
plugin = craneLib.buildPackage (
commonArgs
// {
pname = "watchtower-plugin";
cargoExtraArgs = "-p watchtower-plugin";
src = fileSetForCrate ./watchtower-plugin;
inherit (craneLib.crateNameFromCargoToml { cargoToml = ./watchtower-plugin/Cargo.toml; }) version;
}
);
teos = craneLib.buildPackage (
commonArgs
// {
pname = "teos";
cargoExtraArgs = "-p teos";
src = fileSetForCrate ./teos;
inherit (craneLib.crateNameFromCargoToml { cargoToml = ./teos/Cargo.toml; }) version;
}
);
in
{
packages = {
inherit plugin teos;
default = teos;
};
apps = {
plugin = flake-utils.lib.mkApp { drv = plugin; };
teos = flake-utils.lib.mkApp { drv = teos; };
};
formatter = pkgs.nixfmt-tree;
checks = {
inherit teos plugin;
};
devShells.default = craneLib.devShell {
inherit env;
packages = commonArgs.buildInputs ++ commonArgs.nativeBuildInputs;
};
}
);
}