From 20fec64f76aec6ca5e2db7175ba02b9159d739a3 Mon Sep 17 00:00:00 2001 From: will Date: Fri, 29 May 2026 15:15:21 +0100 Subject: [PATCH] nix: add flake with a devShell --- .envrc | 1 + flake.lock | 27 ++++++++++++++++++++++++++ flake.nix | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 000000000000..3550a30f2de3 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000000..407024209a29 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1779560665, + "narHash": "sha256-tpyBcxPpcQb8ukyNF7DoCwfSY3VPsxHoYwj00Cayv5o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "64c08a7ca051951c8eae34e3e3cb1e202fe36786", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000000..5a22bdba46af --- /dev/null +++ b/flake.nix @@ -0,0 +1,56 @@ +{ + description = "2140 Bitcoin Core devShell"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = + { nixpkgs, ... }: + let + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + ]; + forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f (import nixpkgs { inherit system; })); + + mkDevShell = + pkgs: + let + inherit (pkgs) lib; + inherit (pkgs.stdenv) isLinux isDarwin; + + nativeBuildInputs = [ + pkgs.ccache + pkgs.cmakeCurses # cmakeCurses includes the ccmake tool + pkgs.ninja + pkgs.pkg-config + pkgs.python313 + ] + ++ lib.optionals isLinux [ + pkgs.libsystemtap + pkgs.linuxPackages.bcc + pkgs.linuxPackages.bpftrace + ]; + buildInputs = [ + pkgs.boost + pkgs.capnproto + ]; + in + pkgs.mkShell { + inherit nativeBuildInputs buildInputs; + hardeningDisable = lib.optionals isDarwin [ "stackclashprotection" ]; + CMAKE_GENERATOR = "Ninja"; + CMAKE_EXPORT_COMPILE_COMMANDS = 1; + LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.capnproto ]; + LOCALE_ARCHIVE = lib.optionalString isLinux "${pkgs.glibcLocales}/lib/locale/locale-archive"; + }; + in + { + devShells = forAllSystems (pkgs: { + default = mkDevShell pkgs; + }); + formatter = forAllSystems (pkgs: pkgs.nixfmt-tree); + }; +}