build: Add simple flake

Changelog-Added: Nix users can now install CLN from the new flake.
This commit is contained in:
Joseph Goulden 2024-09-16 09:18:06 +01:00 committed by Vincenzo Palazzo
parent 3c3008c5cc
commit 2056478e56
6 changed files with 228 additions and 0 deletions

View File

@ -528,6 +528,25 @@ jobs:
cat config.vars
VALGRIND=0 poetry run pytest tests/ -vvv -n ${PYTEST_PAR} ${PYTEST_OPTS}
check-flake:
name: Check Nix Flake
runs-on: ubuntu-20.04
strategy:
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Check Nix flake inputs
uses: DeterminateSystems/flake-checker-action@v8
- name: Install Nix
uses: cachix/install-nix-action@V27
with:
nix_path: nixpkgs=channel:nixos-24.05
- name: Check flake
run: nix flake check .?submodules=1#
gather:
# A dummy task that depends on the full matrix of tests, and
# signals successful completion. Used for the PR status to pass
@ -540,6 +559,7 @@ jobs:
- integration-valgrind
- integration-sanitizers
- min-btc-support
- check-flake
steps:
- name: Complete
run: |

4
.gitignore vendored
View File

@ -93,3 +93,7 @@ release/
SHA256SUMS-*
doc/.doc_version
autogenerate-examples-status.log
# Ignore nix outputs
result
result-[0-9]*

1
.version Normal file
View File

@ -0,0 +1 @@
24.08

58
flake.lock Normal file
View File

@ -0,0 +1,58 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1726153070,
"narHash": "sha256-HO4zgY0ekfwO5bX0QH/3kJ/h4KvUDFZg8YpkNwIbg1U=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "bcef6817a8b2aa20a5a6dbb19b43e63c5bf8619a",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1725693463,
"narHash": "sha256-ZPzhebbWBOr0zRWW10FfqfbJlan3G96/h3uqhiFqmwg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "68e7dce0a6532e876980764167ad158174402c6f",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1725233747,
"narHash": "sha256-Ss8QWLXdr2JCBPcYChJhz4xJm+h/xjl4G0c0XlP6a74=",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/356624c12086a18f2ea2825fed34523d60ccc4e3.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/356624c12086a18f2ea2825fed34523d60ccc4e3.tar.gz"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

51
flake.nix Normal file
View File

@ -0,0 +1,51 @@
{
description = "Core Lightning (CLN): A specification compliant Lightning Network implementation in C";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs =
inputs@{
self,
nixpkgs,
flake-parts,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = nixpkgs.lib.systems.flakeExposed;
perSystem =
{
config,
pkgs,
self',
...
}:
{
packages = rec {
# This package depends on git submodules so use a shell command like 'nix build .?submodules=1'.
cln = pkgs.callPackage nix/pkgs/default.nix { inherit self pkgs; };
default = cln;
};
apps = {
lightningd = {
program = "${self'.packages.cln}/bin/lightningd";
};
lightning-cli = {
program = "${self'.packages.cln}/bin/lightning-cli";
};
lightning-hsmtool = {
program = "${self'.packages.cln}/bin/lightning-hsmtool";
};
reckless = {
program = "${self'.packages.cln}/bin/reckless";
};
};
checks = {
cln = self'.packages.cln;
};
formatter = pkgs.nixfmt-rfc-style;
};
};
}

94
nix/pkgs/default.nix Normal file
View File

@ -0,0 +1,94 @@
{
self,
lib,
pkgs,
}:
with pkgs;
let
version = builtins.readFile ../../.version;
py3 = python3.withPackages (p: [
p.mako
p.grpcio-tools
]);
in
stdenv.mkDerivation {
name = "cln";
src = ../../.;
inherit version;
makeFlags = [
"VERSION=${version}"
"MTIME=${self.lastModifiedDate}"
];
# when building on darwin we need cctools to provide the correct libtool
# as libwally-core detects the host as darwin and tries to add the -static
# option to libtool, also we have to add the modified gsed package.
nativeBuildInputs =
[
autoconf
autogen
automake
cargo
gettext
gitMinimal
libtool
lowdown
protobuf
py3
unzip
which
]
++ lib.optionals stdenv.isDarwin [
cctools
darwin.autoSignDarwinBinariesHook
];
buildInputs = [
gmp
jq
libsodium
sqlite
zlib
];
# this causes some python trouble on a darwin host so we skip this step.
# also we have to tell libwally-core to use sed instead of gsed.
postPatch =
if !stdenv.isDarwin then
''
patchShebangs \
tools/generate-wire.py \
tools/update-mocks.sh \
tools/mockup.sh \
tools/fromschema.py \
devtools/sql-rewrite.py
''
else
''
substituteInPlace external/libwally-core/tools/autogen.sh --replace gsed sed && \
substituteInPlace external/libwally-core/configure.ac --replace gsed sed
'';
configureFlags = [ "--disable-valgrind" ];
enableParallelBuilding = true;
# workaround for build issue, happens only x86_64-darwin, not aarch64-darwin
# ccan/ccan/fdpass/fdpass.c:16:8: error: variable length array folded to constant array as an extension [-Werror,-Wgnu-folding-constant]
# char buf[CMSG_SPACE(sizeof(fd))];
env.NIX_CFLAGS_COMPILE = lib.optionalString (
stdenv.isDarwin && stdenv.isx86_64
) "-Wno-error=gnu-folding-constant";
# The `clnrest` plugin requires a Python environment to run
postInstall = ''
rm -r $out/libexec/c-lightning/plugins/clnrest
'';
meta = with lib; {
description = "Core Lightning (CLN): A specification compliant Lightning Network implementation in C";
homepage = "https://github.com/ElementsProject/lightning";
license = licenses.mit;
platforms = platforms.linux ++ platforms.darwin;
};
}