diff --git a/.gitignore b/.gitignore index 1952b4b..9761b94 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .cache -bazel-* .output-bazelrc +bazel-* +nix/bzl/nix-file-deps.bzl diff --git a/example_project_bzl_4/WORKSPACE b/example_project_bzl_4/WORKSPACE index ba90bc4..83bf256 100644 --- a/example_project_bzl_4/WORKSPACE +++ b/example_project_bzl_4/WORKSPACE @@ -20,18 +20,22 @@ http_archive( sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241", ) -http_archive( - name = "io_tweag_rules_nixpkgs", - sha256 = "7efb0f82cda5cdaa8e96b687734c5704b91353561d7889e5d84a13b6d30f4cb8", - strip_prefix = "rules_nixpkgs-05a445575de51872f528c537cc7ff3ab11114f21", - urls = ["https://github.com/tweag/rules_nixpkgs/archive/05a445575de51872f528c537cc7ff3ab11114f21.tar.gz"], +local_repository( + name = "distruptor_nix", + path = "../nix", ) -load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies") -rules_nixpkgs_dependencies() +load("@distruptor_nix//bzl:deps.bzl", "distruptor_deps") +distruptor_deps() + +load("@distruptor_nix//bzl:deps_init.bzl", "deps_init") +deps_init() + +load("@distruptor_nix//bzl:defs.bzl", "nix_repositories_init") +nix_repositories_init() -load("//third_party/nix:defs.bzl", "NIX_REPOSITORIES", "nix_repositories") -nix_repositories() +load("@distruptor_nix//bzl:pkgs.bzl", "nix_packages_init") +nix_packages_init() load("//third_party/cpp_toolchains:defs.bzl", "cpp_toolchains") cpp_toolchains() diff --git a/example_project_bzl_4/hello_world/BUILD.bazel b/example_project_bzl_4/hello_world/BUILD.bazel index 35b4302..794bc4f 100644 --- a/example_project_bzl_4/hello_world/BUILD.bazel +++ b/example_project_bzl_4/hello_world/BUILD.bazel @@ -8,6 +8,6 @@ cc_binary( "*.cpp" ]), deps = [ - "//third_party/xz" + "@distruptor_nix//bzl/packages:xz" ] ) diff --git a/example_project_bzl_4/readline_example_c/BUILD.bazel b/example_project_bzl_4/readline_example_c/BUILD.bazel index 733fb9e..b4bdc6d 100644 --- a/example_project_bzl_4/readline_example_c/BUILD.bazel +++ b/example_project_bzl_4/readline_example_c/BUILD.bazel @@ -8,6 +8,6 @@ cc_binary( "*.c" ]), deps = [ - "//third_party/readline", + "@distruptor_nix//bzl/packages:readline" ] ) diff --git a/example_project_bzl_4/server_c/BUILD.bazel b/example_project_bzl_4/server_c/BUILD.bazel index ad74e82..4496ef0 100644 --- a/example_project_bzl_4/server_c/BUILD.bazel +++ b/example_project_bzl_4/server_c/BUILD.bazel @@ -8,6 +8,6 @@ cc_binary( "*.c" ]), deps = [ - "//third_party/libuv", + "@distruptor_nix//bzl/packages:libuv" ] ) diff --git a/example_project_bzl_4/shell.nix b/example_project_bzl_4/shell.nix index 598e59c..d1eb3c1 100644 --- a/example_project_bzl_4/shell.nix +++ b/example_project_bzl_4/shell.nix @@ -29,6 +29,7 @@ in pkgs.stdenv.mkDerivation { export TERM=xterm # readlink as absolute path is needed echo "startup --output_base $(readlink -f ./bazel-output)" > "$(pwd)"/.output-bazelrc + echo "build --disk_cache=$(readlink -f $(pwd))/bazel-disk-cache" >> "$(pwd)"/.output-bazelrc ''; TMPDIR = "/tmp"; } diff --git a/example_project_bzl_4/third_party/BUILD.bazel b/example_project_bzl_4/third_party/BUILD.bazel index 84d6279..2258adb 100644 --- a/example_project_bzl_4/third_party/BUILD.bazel +++ b/example_project_bzl_4/third_party/BUILD.bazel @@ -1,4 +1,5 @@ """ This packages contains thrid party dependencies. """ +load("@distruptor_nix//bzl:defs.bzl", "nix_package") exports_files([ "dependencies.bzl" diff --git a/example_project_bzl_4/third_party/cpp_toolchains/defs.bzl b/example_project_bzl_4/third_party/cpp_toolchains/defs.bzl index f2360ee..0852258 100644 --- a/example_project_bzl_4/third_party/cpp_toolchains/defs.bzl +++ b/example_project_bzl_4/third_party/cpp_toolchains/defs.bzl @@ -1,6 +1,5 @@ +load("@distruptor_nix//bzl:defs.bzl", "NIX_REPOSITORIES") load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_cc_configure") -load("//third_party/nix:defs.bzl", "NIX_REPOSITORIES") - def cpp_toolchains(): # Naming convention (after nixpkgs) diff --git a/example_project_bzl_4/third_party/dependencies.bzl b/example_project_bzl_4/third_party/dependencies.bzl index 3e4ca64..a0cfec1 100644 --- a/example_project_bzl_4/third_party/dependencies.bzl +++ b/example_project_bzl_4/third_party/dependencies.bzl @@ -1,15 +1,2 @@ -load("@//third_party/libuv:defs.bzl", "libuv") -load("@//third_party/ncurses:defs.bzl", "ncurses") -load("@//third_party/readline:defs.bzl", "readline") -load("@//third_party/xorg.libX11:defs.bzl", "libX11") -load("@//third_party/xorg.xorgproto:defs.bzl", "xorgproto") -load("@//third_party/xz:defs.bzl", "xz") - def third_party_deps(): """Load 3rd party dependencies""" - libuv() - libX11() - ncurses() - readline() - xorgproto() - xz() diff --git a/example_project_bzl_4/third_party/libuv/BUILD.bazel b/example_project_bzl_4/third_party/libuv/BUILD.bazel deleted file mode 100644 index bcd0793..0000000 --- a/example_project_bzl_4/third_party/libuv/BUILD.bazel +++ /dev/null @@ -1,15 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -alias( - name = "libuv", - actual = select({ - "@bazel_tools//src/conditions:linux_x86_64": "@libuv.x86_64_linux//:all", - "@bazel_tools//src/conditions:linux_aarch64": "@libuv.aarch64_linux//:all", - "@bazel_tools//src/conditions:linux_ppc64le": "@libuv.ppc64_linux//:all", - }), -) - -exports_files([ - "defs.bzl", - "BUILD.bazel.tmpl" -]) diff --git a/example_project_bzl_4/third_party/libuv/BUILD.bazel.tmpl b/example_project_bzl_4/third_party/libuv/BUILD.bazel.tmpl deleted file mode 100644 index 5a322bc..0000000 --- a/example_project_bzl_4/third_party/libuv/BUILD.bazel.tmpl +++ /dev/null @@ -1,18 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - -package(default_visibility = ["//visibility:public"]) - -cc_library( - name = "all", - srcs = glob([ - "lib/*.a", - "lib/*.so*", - ]), - hdrs = glob([ - "include/**/*.h", - "include/**/*.hpp", - ]), - includes = [ - "include", - ], -) diff --git a/example_project_bzl_4/third_party/libuv/defs.bzl b/example_project_bzl_4/third_party/libuv/defs.bzl deleted file mode 100644 index ec05104..0000000 --- a/example_project_bzl_4/third_party/libuv/defs.bzl +++ /dev/null @@ -1,31 +0,0 @@ -load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_package") -load("//third_party/nix:defs.bzl", "NIX_REPOSITORIES") - -def libuv(): - nixpkgs_package( - name = "libuv.x86_64_linux", - attribute_path = "libuv", - build_file = "//third_party/libuv:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) - - nixpkgs_package( - name = "libuv.aarch64_linux", - attribute_path = "pkgsCross.aarch64-multiplatform.libuv", - build_file = "//third_party/libuv:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) - - nixpkgs_package( - name = "libuv.ppc64_linux", - attribute_path = "pkgsCross.ppc64.libuv", - build_file = "//third_party/libuv:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) - - nixpkgs_package( - name = "libuv.riscv32_none", - attribute_path = "pkgsCross.riscv32_embedded.libuv", - build_file = "//third_party/libuv:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) diff --git a/example_project_bzl_4/third_party/ncurses/BUILD.bazel b/example_project_bzl_4/third_party/ncurses/BUILD.bazel deleted file mode 100644 index 4c87ae3..0000000 --- a/example_project_bzl_4/third_party/ncurses/BUILD.bazel +++ /dev/null @@ -1,21 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -alias( - name = "ncurses", - actual = select({ - "@bazel_tools//src/conditions:linux_x86_64": "@ncurses.x86_64_linux//:ncurses", - "@bazel_tools//src/conditions:linux_aarch64": "@ncurses.aarch64_linux//:ncurses", - "@bazel_tools//src/conditions:linux_ppc64le": "@ncurses.ppc64_linux//:ncurses", - "@bazel_tools//src/conditions:darwin_x86_64": "@ncurses.x86_64_darwin//:ncurses", - }), -) - -exports_files([ - "BUILD.bazel.tmpl", - "common.nix", - "defs.bzl", - "ncurses-aarch64-linux.nix", - "ncurses-ppc64-linux.nix", - "ncurses-x86_64-linux.nix", - "ncurses-x86_64-darwin.nix", -]) diff --git a/example_project_bzl_4/third_party/ncurses/BUILD.bazel.tmpl b/example_project_bzl_4/third_party/ncurses/BUILD.bazel.tmpl deleted file mode 100644 index 047bce4..0000000 --- a/example_project_bzl_4/third_party/ncurses/BUILD.bazel.tmpl +++ /dev/null @@ -1,18 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - -package(default_visibility = ["//visibility:public"]) - -cc_library( - name = "ncurses", - srcs = glob([ - "lib/*.a", - "lib/*.so*", - ]), - hdrs = glob([ - "include/**/*.h", - "include/**/*.hpp", - ]), - includes = [ - "include", - ], -) diff --git a/example_project_bzl_4/third_party/ncurses/common.nix b/example_project_bzl_4/third_party/ncurses/common.nix deleted file mode 100644 index 8434e54..0000000 --- a/example_project_bzl_4/third_party/ncurses/common.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ pkgs, lib, stdenv, ... }: - -let - ncursesStatic = pkgs.ncurses.overrideAttrs (oldAttrs: rec { - enableStatic = true; - - configureFlags = [ - (lib.withFeature (!enableStatic) "shared") - "--without-debug" - "--enable-pc-files" - "--enable-symlinks" - "--with-manpage-format=normal" - "--disable-stripping" - ] ++ lib.optionals stdenv.hostPlatform.isWindows [ - "--enable-sp-funcs" - "--enable-term-driver" - ]; - - preFixup = ""; - postFixup = ""; -}); -in pkgs.symlinkJoin { - name = "ncurses"; - paths = [ ncursesStatic.out ncursesStatic.dev ]; -} diff --git a/example_project_bzl_4/third_party/ncurses/defs.bzl b/example_project_bzl_4/third_party/ncurses/defs.bzl deleted file mode 100644 index 9e48efa..0000000 --- a/example_project_bzl_4/third_party/ncurses/defs.bzl +++ /dev/null @@ -1,35 +0,0 @@ -load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_package") -load("//third_party/nix:defs.bzl", "NIX_REPOSITORIES") - -def ncurses(): - nixpkgs_package( - name = "ncurses.x86_64_linux", - nix_file = "//third_party/ncurses:ncurses-x86_64-linux.nix", - nix_file_deps = [ "//third_party/ncurses:common.nix" ], - build_file = "//third_party/ncurses:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) - - nixpkgs_package( - name = "ncurses.aarch64_linux", - nix_file = "//third_party/ncurses:ncurses-aarch64-linux.nix", - nix_file_deps = [ "//third_party/ncurses:common.nix" ], - build_file = "//third_party/ncurses:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) - - nixpkgs_package( - name = "ncurses.ppc64_linux", - nix_file = "//third_party/ncurses:ncurses-ppc64-linux.nix", - nix_file_deps = [ "//third_party/ncurses:common.nix" ], - build_file = "//third_party/ncurses:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) - - nixpkgs_package( - name = "ncurses.x86_64_darwin", - nix_file = "//third_party/ncurses:ncurses-x86_64-darwin.nix", - nix_file_deps = [ "//third_party/ncurses:common.nix" ], - build_file = "//third_party/ncurses:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) diff --git a/example_project_bzl_4/third_party/ncurses/ncurses-aarch64-linux.nix b/example_project_bzl_4/third_party/ncurses/ncurses-aarch64-linux.nix deleted file mode 100644 index d3fcd06..0000000 --- a/example_project_bzl_4/third_party/ncurses/ncurses-aarch64-linux.nix +++ /dev/null @@ -1 +0,0 @@ -(import {}).pkgsCross.aarch64-multiplatform.callPackage ./common.nix {} diff --git a/example_project_bzl_4/third_party/ncurses/ncurses-ppc64-linux.nix b/example_project_bzl_4/third_party/ncurses/ncurses-ppc64-linux.nix deleted file mode 100644 index b3a9e8e..0000000 --- a/example_project_bzl_4/third_party/ncurses/ncurses-ppc64-linux.nix +++ /dev/null @@ -1 +0,0 @@ -(import {}).pkgs.pkgsCross.ppc64.callPackage ./common.nix {} diff --git a/example_project_bzl_4/third_party/ncurses/ncurses-x86_64-darwin.nix b/example_project_bzl_4/third_party/ncurses/ncurses-x86_64-darwin.nix deleted file mode 100644 index bead4fb..0000000 --- a/example_project_bzl_4/third_party/ncurses/ncurses-x86_64-darwin.nix +++ /dev/null @@ -1 +0,0 @@ -(import {}).callPackage ./common.nix {} diff --git a/example_project_bzl_4/third_party/ncurses/ncurses-x86_64-linux.nix b/example_project_bzl_4/third_party/ncurses/ncurses-x86_64-linux.nix deleted file mode 100644 index bead4fb..0000000 --- a/example_project_bzl_4/third_party/ncurses/ncurses-x86_64-linux.nix +++ /dev/null @@ -1 +0,0 @@ -(import {}).callPackage ./common.nix {} diff --git a/example_project_bzl_4/third_party/nix/BUILD.bazel b/example_project_bzl_4/third_party/nix/BUILD.bazel deleted file mode 100644 index 1ef8680..0000000 --- a/example_project_bzl_4/third_party/nix/BUILD.bazel +++ /dev/null @@ -1,3 +0,0 @@ -exports_files([ - "defs.bzl" -]) diff --git a/example_project_bzl_4/third_party/nix/defs.bzl b/example_project_bzl_4/third_party/nix/defs.bzl deleted file mode 100644 index 8ed29cf..0000000 --- a/example_project_bzl_4/third_party/nix/defs.bzl +++ /dev/null @@ -1,13 +0,0 @@ -load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_git_repository") - -NIX_REPOSITORIES = { - "nixpkgs": "@nixpkgs", -} - -def nix_repositories(): - """ Define nix repositories being used. """ - nixpkgs_git_repository( - name = "nixpkgs", - revision = "21.11", - sha256 = "c77bb41cf5dd82f4718fa789d49363f512bb6fa6bc25f8d60902fe2d698ed7cc", - ) diff --git a/example_project_bzl_4/third_party/readline/BUILD.bazel b/example_project_bzl_4/third_party/readline/BUILD.bazel deleted file mode 100644 index bb7645a..0000000 --- a/example_project_bzl_4/third_party/readline/BUILD.bazel +++ /dev/null @@ -1,22 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -alias( - name = "readline", - actual = select({ - "@bazel_tools//src/conditions:linux_x86_64": "@readline.x86_64_linux//:readline", - "@bazel_tools//src/conditions:linux_aarch64": "@readline.aarch64_linux//:readline", - "@bazel_tools//src/conditions:linux_ppc64le": "@readline.ppc64_linux//:readline", - "@bazel_tools//src/conditions:darwin_x86_64": "@readline.x86_64_darwin//:readline", - }), -) - -exports_files([ - "BUILD.bazel.tmpl", - "defs.bzl", - "no-arch_only.patch", - "common.nix", - "readline-x86_64-linux.nix", - "readline-aarch64-linux.nix", - "readline-ppc64-linux.nix", - "readline-x86_64-darwin.nix", -]) diff --git a/example_project_bzl_4/third_party/readline/BUILD.bazel.tmpl b/example_project_bzl_4/third_party/readline/BUILD.bazel.tmpl deleted file mode 100644 index 833802f..0000000 --- a/example_project_bzl_4/third_party/readline/BUILD.bazel.tmpl +++ /dev/null @@ -1,21 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - -package(default_visibility = ["//visibility:public"]) - -cc_library( - name = "readline", - srcs = glob([ - "lib/*.a", - "lib/*.so*", - ]), - hdrs = glob([ - "include/**/*.h", - "include/**/*.hpp", - ]), - includes = [ - "include", - ], - deps = [ - "@example_project_bzl_4//third_party/ncurses", - ] -) diff --git a/example_project_bzl_4/third_party/readline/common.nix b/example_project_bzl_4/third_party/readline/common.nix deleted file mode 100644 index 95f0c7c..0000000 --- a/example_project_bzl_4/third_party/readline/common.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ pkgs, lib, stdenv, ... }: - -let - readlineStatic = pkgs.readline81.overrideAttrs (oldAttrs: rec { - configureFlags = [ - "--enable-static" - "--disable-shared" - ]; - - # static build, so don't need ncurses - # (we also let Bazel handle the dependency) - propagateBuildInputs = []; - - patches = [ - ./no-arch_only.patch - ] ++ oldAttrs.upstreamPatches; - }); -in pkgs.symlinkJoin { - name = "readline"; - paths = [ readlineStatic.out readlineStatic.dev ]; -} diff --git a/example_project_bzl_4/third_party/readline/defs.bzl b/example_project_bzl_4/third_party/readline/defs.bzl deleted file mode 100644 index 46bdae0..0000000 --- a/example_project_bzl_4/third_party/readline/defs.bzl +++ /dev/null @@ -1,47 +0,0 @@ -load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_package") -load("//third_party/nix:defs.bzl", "NIX_REPOSITORIES") - -def readline(): - nixpkgs_package( - name = "readline.x86_64_linux", - nix_file = "//third_party/readline:readline-x86_64-linux.nix", - nix_file_deps = [ - "//third_party/readline:common.nix", - "//third_party/readline:no-arch_only.patch", - ], - build_file = "//third_party/readline:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) - - nixpkgs_package( - name = "readline.aarch64_linux", - nix_file = "//third_party/readline:readline-aarch64-linux.nix", - nix_file_deps = [ - "//third_party/readline:common.nix", - "//third_party/readline:no-arch_only.patch", - ], - build_file = "//third_party/readline:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) - - nixpkgs_package( - name = "readline.ppc64_linux", - nix_file = "//third_party/readline:readline-ppc64-linux.nix", - nix_file_deps = [ - "//third_party/readline:common.nix", - "//third_party/readline:no-arch_only.patch", - ], - build_file = "//third_party/readline:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) - - nixpkgs_package( - name = "readline.x86_64_darwin", - nix_file = "//third_party/readline:readline-x86_64-darwin.nix", - nix_file_deps = [ - "//third_party/readline:common.nix", - "//third_party/readline:no-arch_only.patch", - ], - build_file = "//third_party/readline:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) diff --git a/example_project_bzl_4/third_party/readline/readline-aarch64-linux.nix b/example_project_bzl_4/third_party/readline/readline-aarch64-linux.nix deleted file mode 100644 index d3fcd06..0000000 --- a/example_project_bzl_4/third_party/readline/readline-aarch64-linux.nix +++ /dev/null @@ -1 +0,0 @@ -(import {}).pkgsCross.aarch64-multiplatform.callPackage ./common.nix {} diff --git a/example_project_bzl_4/third_party/readline/readline-ppc64-linux.nix b/example_project_bzl_4/third_party/readline/readline-ppc64-linux.nix deleted file mode 100644 index b3a9e8e..0000000 --- a/example_project_bzl_4/third_party/readline/readline-ppc64-linux.nix +++ /dev/null @@ -1 +0,0 @@ -(import {}).pkgs.pkgsCross.ppc64.callPackage ./common.nix {} diff --git a/example_project_bzl_4/third_party/readline/readline-x86_64-darwin.nix b/example_project_bzl_4/third_party/readline/readline-x86_64-darwin.nix deleted file mode 100644 index bead4fb..0000000 --- a/example_project_bzl_4/third_party/readline/readline-x86_64-darwin.nix +++ /dev/null @@ -1 +0,0 @@ -(import {}).callPackage ./common.nix {} diff --git a/example_project_bzl_4/third_party/readline/readline-x86_64-linux.nix b/example_project_bzl_4/third_party/readline/readline-x86_64-linux.nix deleted file mode 100644 index bead4fb..0000000 --- a/example_project_bzl_4/third_party/readline/readline-x86_64-linux.nix +++ /dev/null @@ -1 +0,0 @@ -(import {}).callPackage ./common.nix {} diff --git a/example_project_bzl_4/third_party/xorg.libX11/BUILD.bazel b/example_project_bzl_4/third_party/xorg.libX11/BUILD.bazel deleted file mode 100644 index 9ad5f59..0000000 --- a/example_project_bzl_4/third_party/xorg.libX11/BUILD.bazel +++ /dev/null @@ -1,4 +0,0 @@ -exports_files([ - "defs.bzl", - "BUILD.bazel.tmpl", -]) diff --git a/example_project_bzl_4/third_party/xorg.libX11/BUILD.bazel.tmpl b/example_project_bzl_4/third_party/xorg.libX11/BUILD.bazel.tmpl deleted file mode 100644 index 5a322bc..0000000 --- a/example_project_bzl_4/third_party/xorg.libX11/BUILD.bazel.tmpl +++ /dev/null @@ -1,18 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - -package(default_visibility = ["//visibility:public"]) - -cc_library( - name = "all", - srcs = glob([ - "lib/*.a", - "lib/*.so*", - ]), - hdrs = glob([ - "include/**/*.h", - "include/**/*.hpp", - ]), - includes = [ - "include", - ], -) diff --git a/example_project_bzl_4/third_party/xorg.libX11/defs.bzl b/example_project_bzl_4/third_party/xorg.libX11/defs.bzl deleted file mode 100644 index 0d2ebb7..0000000 --- a/example_project_bzl_4/third_party/xorg.libX11/defs.bzl +++ /dev/null @@ -1,17 +0,0 @@ -load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_package") -load("//third_party/nix:defs.bzl", "NIX_REPOSITORIES") - -def libX11(): - nixpkgs_package( - name = "xorg.libX11.headers", - attribute_path = "xorg.libX11.dev", - build_file = "//third_party/xorg.libX11:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) - - nixpkgs_package( - name = "xorg.libX11.lib", - attribute_path = "xorg.libX11", - build_file = "//third_party/xorg.libX11:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) diff --git a/example_project_bzl_4/third_party/xorg.xorgproto/BUILD.bazel b/example_project_bzl_4/third_party/xorg.xorgproto/BUILD.bazel deleted file mode 100644 index 9ad5f59..0000000 --- a/example_project_bzl_4/third_party/xorg.xorgproto/BUILD.bazel +++ /dev/null @@ -1,4 +0,0 @@ -exports_files([ - "defs.bzl", - "BUILD.bazel.tmpl", -]) diff --git a/example_project_bzl_4/third_party/xorg.xorgproto/BUILD.bazel.tmpl b/example_project_bzl_4/third_party/xorg.xorgproto/BUILD.bazel.tmpl deleted file mode 100644 index d2a8cbd..0000000 --- a/example_project_bzl_4/third_party/xorg.xorgproto/BUILD.bazel.tmpl +++ /dev/null @@ -1,14 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - -package(default_visibility = ["//visibility:public"]) - -cc_library( - name = "all", - hdrs = glob([ - "include/**/*.h", - "include/**/*.hpp", - ]), - includes = [ - "include", - ], -) diff --git a/example_project_bzl_4/third_party/xorg.xorgproto/defs.bzl b/example_project_bzl_4/third_party/xorg.xorgproto/defs.bzl deleted file mode 100644 index e159072..0000000 --- a/example_project_bzl_4/third_party/xorg.xorgproto/defs.bzl +++ /dev/null @@ -1,10 +0,0 @@ -load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_package") -load("//third_party/nix:defs.bzl", "NIX_REPOSITORIES") - -def xorgproto(): - nixpkgs_package( - name = "xorg.xorgproto.headers", - attribute_path = "xorg.xorgproto", - build_file = "//third_party/xorg.xorgproto:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) diff --git a/example_project_bzl_4/third_party/xz/BUILD.bazel b/example_project_bzl_4/third_party/xz/BUILD.bazel deleted file mode 100644 index a5daf59..0000000 --- a/example_project_bzl_4/third_party/xz/BUILD.bazel +++ /dev/null @@ -1,15 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -alias( - name = "xz", - actual = select({ - "@bazel_tools//src/conditions:linux_x86_64": "@xz.x86_64_linux//:all", - "@bazel_tools//src/conditions:linux_aarch64": "@xz.aarch64_linux//:all", - "@bazel_tools//src/conditions:linux_ppc64le": "@xz.ppc64_linux//:all", - }), -) - -exports_files([ - "BUILD.bazel.tmpl", - "defs.bzl", -]) diff --git a/example_project_bzl_4/third_party/xz/BUILD.bazel.tmpl b/example_project_bzl_4/third_party/xz/BUILD.bazel.tmpl deleted file mode 100644 index 5a322bc..0000000 --- a/example_project_bzl_4/third_party/xz/BUILD.bazel.tmpl +++ /dev/null @@ -1,18 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - -package(default_visibility = ["//visibility:public"]) - -cc_library( - name = "all", - srcs = glob([ - "lib/*.a", - "lib/*.so*", - ]), - hdrs = glob([ - "include/**/*.h", - "include/**/*.hpp", - ]), - includes = [ - "include", - ], -) diff --git a/example_project_bzl_4/third_party/xz/defs.bzl b/example_project_bzl_4/third_party/xz/defs.bzl deleted file mode 100644 index d17db39..0000000 --- a/example_project_bzl_4/third_party/xz/defs.bzl +++ /dev/null @@ -1,34 +0,0 @@ -load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_package") -load("//third_party/nix:defs.bzl", "NIX_REPOSITORIES") - -def xz(): - nixpkgs_package( - name = "xz.x86_64_linux", - nix_file_content = """ - let pkgs = import {}; in - pkgs.symlinkJoin { name = "xz_x86_64_linux"; paths = with pkgs; [ xz xz.dev ]; } - """, - build_file = "//third_party/xz:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) - - nixpkgs_package( - name = "xz.aarch64_linux", - nix_file_content = """ - let pkgs = import {}; in - pkgs.pkgsCross.aarch64-multiplatform.symlinkJoin { name = "xz_aarch64_linux"; paths = with pkgs.pkgsCross.aarch64-multiplatform; [ xz xz.dev ]; } - """, - build_file = "//third_party/xz:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) - - nixpkgs_package( - name = "xz.ppc64_linux", - nix_file_content = """ - let pkgs = import {}; in - pkgs.pkgsCross.ppc64.symlinkJoin { name = "xz_ppc64_linux"; paths = with pkgs.pkgsCross.ppc64; [ xz xz.dev ]; } - """, - build_file = "//third_party/xz:BUILD.bazel.tmpl", - repositories = NIX_REPOSITORIES, - ) - diff --git a/example_project_bzl_4/x11_app/BUILD.bazel b/example_project_bzl_4/x11_app/BUILD.bazel index df5e589..a6a6116 100644 --- a/example_project_bzl_4/x11_app/BUILD.bazel +++ b/example_project_bzl_4/x11_app/BUILD.bazel @@ -9,8 +9,7 @@ cc_binary( "*.cpp" ]), deps = [ - "@xorg.xorgproto.headers//:all", - "@xorg.libX11.headers//:all", - "@xorg.libX11.lib//:all", + "@distruptor_nix//bzl/packages:xorg.xorgproto", + "@distruptor_nix//bzl/packages:xorg.libX11", ] ) diff --git a/flake.nix b/flake.nix index 5e53715..66fd6a6 100644 --- a/flake.nix +++ b/flake.nix @@ -32,9 +32,12 @@ shellHook = '' export TERM=xterm export DIRENV_CONFIG=$(pwd)/.cache + export NIX_PATH="nixpkgs=${nixpkgs}" export NIX_USER_CONF_FILES=${./scripts/nix.conf} . ${pkgs.nix-direnv}/share/nix-direnv/direnvrc eval "$(direnv hook bash)" + + #$(pwd)/nix/gen-bzl-nix-file-deps.sh ''; TMPDIR = "/tmp"; }; diff --git a/nix/BUILD.bazel b/nix/BUILD.bazel new file mode 100644 index 0000000..f569a86 --- /dev/null +++ b/nix/BUILD.bazel @@ -0,0 +1,7 @@ +package(default_visibility = ["//visibility:public"]) + +exports_files( + glob([ + "**/*" + ]) +) diff --git a/nix/WORKSPACE b/nix/WORKSPACE new file mode 100644 index 0000000..c54dd9a --- /dev/null +++ b/nix/WORKSPACE @@ -0,0 +1,13 @@ +workspace(name = "distruptor_nix") + +load("@distruptor_nix//bzl:deps.bzl", "distruptor_deps") +distruptor_deps() + +load("@distruptor_nix//bzl:deps_init.bzl", "deps_init") +deps_init() + +load("@distruptor_nix//bzl:defs.bzl", "nix_repositories_init") +nix_repositories_init() + +load("@distruptor_nix//bzl:pkgs.bzl", "nix_packages_init") +nix_packages_init() diff --git a/nix/bazelHelpers/default.nix b/nix/bazelHelpers/default.nix new file mode 100644 index 0000000..d37d8eb --- /dev/null +++ b/nix/bazelHelpers/default.nix @@ -0,0 +1,31 @@ +{ disruptor, pkgs, lib, ... }: + +{ + # TODO: It would make sense to add this as default step to every mkDerivation, + # alongs side python equivalents etc. + # This way, pkgs.* could be exposed nearly directly to Nix + # Also: https://github.com/tweag/rules_nixpkgs/compare/master...wolfd:master + createCppBuildFile = target_name: (pkgs.writeText + "BUILD.bazel" + '' + load("@rules_cc//cc:defs.bzl", "cc_library") + + package(default_visibility = ["//visibility:public"]) + + cc_library( + name = "${target_name}", + srcs = glob([ + "lib/*.a*", + "lib/*.so*", + ]), + hdrs = glob([ + "include/**/*.h", + "include/**/*.hpp", + ]), + includes = [ + "include", + ], + ) + '' + ); +} diff --git a/nix/bzl/BUILD.bazel b/nix/bzl/BUILD.bazel new file mode 100644 index 0000000..ffd0fb0 --- /dev/null +++ b/nix/bzl/BUILD.bazel @@ -0,0 +1 @@ +package(default_visibility = ["//visibility:public"]) diff --git a/nix/bzl/defs.bzl b/nix/bzl/defs.bzl new file mode 100644 index 0000000..2ecb0ef --- /dev/null +++ b/nix/bzl/defs.bzl @@ -0,0 +1,47 @@ +load("@distruptor_nix//bzl:nix-file-deps.bzl", "NIX_FILE_DEPS") +load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_git_repository", "nixpkgs_package") + +NIX_REPOSITORIES = { + "nixpkgs": "@nixpkgs", +} + +def nix_repositories_init(): + """ Define nix repositories being used. """ + nixpkgs_git_repository( + name = "nixpkgs", + revision = "21.11", + sha256 = "c77bb41cf5dd82f4718fa789d49363f512bb6fa6bc25f8d60902fe2d698ed7cc", + ) + +BAZEL_PLATFROM_TO_NIX_ARCH = { + "x86_64_linux": None, + "x86_64_darwin": None, + "aarch64_linux": "aarch64-multiplatform", + "ppc64_linux": "ppc64", +} + +def nix_package(name, visibility = ["//visibility:public"]): + native.alias( + name = name, + actual = select({ + "@bazel_tools//src/conditions:linux_x86_64": "@{0}.x86_64_linux//:{0}".format(name), + "@bazel_tools//src/conditions:darwin_x86_64": "@{0}.x86_64_darwin//:{0}".format(name), + "@bazel_tools//src/conditions:linux_aarch64": "@{0}.aarch64_linux//:{0}".format(name), + "@bazel_tools//src/conditions:linux_ppc64le": "@{0}.ppc64_linux//:{0}".format(name), + }), + visibility = visibility, + ) + +def get_nix_package(name, attribute_path = None): + if not attribute_path: + attribute_path = name + + for platform, nix_arch in BAZEL_PLATFROM_TO_NIX_ARCH.items(): + nixpkgs_package( + name = "%s.%s" % (name, platform), + attribute_path = attribute_path, + nix_file = "@distruptor_nix//:default.nix", + nixopts = [ "--argstr", "crossTarget", nix_arch ] if nix_arch else None, + nix_file_deps = NIX_FILE_DEPS, + repositories = NIX_REPOSITORIES, + ) diff --git a/nix/bzl/deps.bzl b/nix/bzl/deps.bzl new file mode 100644 index 0000000..4f441d2 --- /dev/null +++ b/nix/bzl/deps.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +def distruptor_deps(): + maybe( + http_archive, + name = "io_tweag_rules_nixpkgs", + sha256 = "7efb0f82cda5cdaa8e96b687734c5704b91353561d7889e5d84a13b6d30f4cb8", + strip_prefix = "rules_nixpkgs-05a445575de51872f528c537cc7ff3ab11114f21", + urls = ["https://github.com/tweag/rules_nixpkgs/archive/05a445575de51872f528c537cc7ff3ab11114f21.tar.gz"], + ) diff --git a/nix/bzl/deps_init.bzl b/nix/bzl/deps_init.bzl new file mode 100644 index 0000000..7392226 --- /dev/null +++ b/nix/bzl/deps_init.bzl @@ -0,0 +1,4 @@ +load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies") + +def deps_init(): + rules_nixpkgs_dependencies() diff --git a/nix/bzl/packages/BUILD.bazel b/nix/bzl/packages/BUILD.bazel new file mode 100644 index 0000000..0deec71 --- /dev/null +++ b/nix/bzl/packages/BUILD.bazel @@ -0,0 +1,10 @@ +load("@distruptor_nix//bzl:defs.bzl", "nix_package") + +package(default_visibility = ["//visibility:public"]) + +nix_package("libuv") +nix_package("ncurses") +nix_package("readline") +nix_package("xorg.libX11") +nix_package("xorg.xorgproto") +nix_package("xz") diff --git a/nix/bzl/pkgs.bzl b/nix/bzl/pkgs.bzl new file mode 100644 index 0000000..48fd6e6 --- /dev/null +++ b/nix/bzl/pkgs.bzl @@ -0,0 +1,9 @@ +load("@distruptor_nix//bzl:defs.bzl", "get_nix_package") + +def nix_packages_init(): + get_nix_package("libuv") + get_nix_package("ncurses") + get_nix_package("xorg.libX11") + get_nix_package("readline") + get_nix_package("xorg.xorgproto") + get_nix_package("xz") diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..42fe0f1 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,30 @@ +{ + system ? builtins.currentSystem, + # Using due to Bazel nixpkgs_rules compat + nixpkgs ? import { + inherit system; + config.allowUnfree = true; + }, + crossTarget ? null, + ... +}@args: + +let + readTree = import ./readTree { }; + readPackages = packagesArgs: readTree { + args = packagesArgs; + path = ./.; + scopedArgs = { + __findFile = _: _: throw "Do not import from NIX_PATH!"; + }; + }; + pkgs = if builtins.isNull crossTarget then nixpkgs else (builtins.getAttr crossTarget nixpkgs.pkgsCross); +in +readTree.fix (self: (readPackages { + disruptor = self; + # Compatiblity + pkgs = pkgs; + # Expose lib attribute to packages. + lib = pkgs.lib; + externalArgs = args; +})) diff --git a/nix/gen-bzl-nix-file-deps.sh b/nix/gen-bzl-nix-file-deps.sh new file mode 100755 index 0000000..ef8e7a7 --- /dev/null +++ b/nix/gen-bzl-nix-file-deps.sh @@ -0,0 +1,21 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p coreutils + +# Find current script location +{ + __FILE__=$(dirname "$(realpath $0)") +} || { + echo "Unable to determine current script location.." + echo "Will assume '.'" + __FILE__="." +} + +NIX_DEPS_FILE="${__FILE__}/bzl/nix-file-deps.bzl" + +cd "${__FILE__}" +echo 'NIX_FILE_DEPS = [' > "${NIX_DEPS_FILE}" +# TODO: Harden against whitespaces in dir/file names +for f in $(find . -type f -printf '@distruptor_nix//:%P\n'); do + echo " \"${f}\"," >> "${NIX_DEPS_FILE}" +done +echo "]" >> "${NIX_DEPS_FILE}" diff --git a/nix/libuv/default.nix b/nix/libuv/default.nix new file mode 100644 index 0000000..3f35f2d --- /dev/null +++ b/nix/libuv/default.nix @@ -0,0 +1,18 @@ +{ disruptor, pkgs, lib, ... }: + +pkgs.stdenv.mkDerivation { + name = "libuv.bzl"; + buildInputs = [ + pkgs.libuv + ]; + + phases = [ + "installPhase" + ]; + + installPhase = '' + mkdir $out + cp ${disruptor.bazelHelpers.createCppBuildFile "libuv"} $out/BUILD.bazel + cp -R ${pkgs.libuv}/* $out/ + ''; +} diff --git a/nix/ncurses/default.nix b/nix/ncurses/default.nix new file mode 100644 index 0000000..134cfe0 --- /dev/null +++ b/nix/ncurses/default.nix @@ -0,0 +1,40 @@ +{ disruptor, pkgs, lib, ... }: + +let + ncursesStatic = pkgs.ncurses.overrideAttrs (oldAttrs: rec { + enableStatic = true; + + configureFlags = [ + (lib.withFeature (!enableStatic) "shared") + "--without-debug" + "--enable-pc-files" + "--enable-symlinks" + "--with-manpage-format=normal" + "--disable-stripping" + ] ++ lib.optionals pkgs.stdenv.hostPlatform.isWindows [ + "--enable-sp-funcs" + "--enable-term-driver" + ]; + + preFixup = ""; + postFixup = ""; +}); +in +pkgs.stdenv.mkDerivation { + name = "ncurses-static.bzl"; + buildInputs = [ + ncursesStatic + ncursesStatic.dev + ]; + + phases = [ + "installPhase" + ]; + + installPhase = '' + mkdir $out + cp ${disruptor.bazelHelpers.createCppBuildFile "ncurses"} $out/BUILD.bazel + cp -R ${ncursesStatic}/* $out/ + cp -R ${ncursesStatic.dev}/include $out/ + ''; +} diff --git a/nix/readTree/default.nix b/nix/readTree/default.nix new file mode 100644 index 0000000..20dd23f --- /dev/null +++ b/nix/readTree/default.nix @@ -0,0 +1,260 @@ +# Borrowed from: https://code.tvl.fyi/ +# Branch: cannon, commit: 49c8d8371ca17207157058b4daecded67ade1e5f +# +# Copyright (c) 2019 Vincent Ambo +# Copyright (c) 2020-2021 The TVL Authors +# SPDX-License-Identifier: MIT +# +# Provides a function to automatically read a a filesystem structure +# into a Nix attribute set. +# +# Called with an attribute set taking the following arguments: +# +# path: Path to a directory from which to start reading the tree. +# +# args: Argument set to pass to each imported file. +# +# filter: Function to filter `args` based on the tree location. This should +# be a function of the form `args -> location -> args`, where the +# location is a list of strings representing the path components of +# the current readTree target. Optional. +{ ... }: + +let + inherit (builtins) + attrNames + concatMap + concatStringsSep + elem + elemAt + filter + hasAttr + head + isAttrs + listToAttrs + map + match + readDir + substring; + + argsWithPath = args: parts: + let meta.locatedAt = parts; + in meta // (if isAttrs args then args else args meta); + + readDirVisible = path: + let + children = readDir path; + isVisible = f: f == ".skip-subtree" || (substring 0 1 f) != "."; + names = filter isVisible (attrNames children); + in + listToAttrs (map + (name: { + inherit name; + value = children.${name}; + }) + names); + + # Create a mark containing the location of this attribute and + # a list of all child attribute names added by readTree. + marker = parts: children: { + __readTree = parts; + __readTreeChildren = builtins.attrNames children; + }; + + # Merge two attribute sets, but place attributes in `passthru` via + # `overrideAttrs` for derivation targets that support it. + merge = a: b: + if a ? overrideAttrs + then + a.overrideAttrs + (prev: { + passthru = (prev.passthru or { }) // b; + }) + else a // b; + + # Import a file and enforce our calling convention + importFile = args: scopedArgs: path: parts: filter: + let + importedFile = + if scopedArgs != { } + then builtins.scopedImport scopedArgs path + else import path; + pathType = builtins.typeOf importedFile; + in + if pathType != "lambda" + then builtins.throw "readTree: trying to import ${toString path}, but it’s a ${pathType}, you need to make it a function like { depot, pkgs, ... }" + else importedFile (filter parts (argsWithPath args parts)); + + nixFileName = file: + let res = match "(.*)\\.nix" file; + in if res == null then null else head res; + + readTree = { args, initPath, rootDir, parts, argsFilter, scopedArgs }: + let + dir = readDirVisible initPath; + joinChild = c: initPath + ("/" + c); + + self = + if rootDir + then { __readTree = [ ]; } + else importFile args scopedArgs initPath parts argsFilter; + + # Import subdirectories of the current one, unless the special + # `.skip-subtree` file exists which makes readTree ignore the + # children. + # + # This file can optionally contain information on why the tree + # should be ignored, but its content is not inspected by + # readTree + filterDir = f: dir."${f}" == "directory"; + children = if hasAttr ".skip-subtree" dir then [ ] else + map + (c: { + name = c; + value = readTree { + inherit argsFilter scopedArgs; + args = args; + initPath = (joinChild c); + rootDir = false; + parts = (parts ++ [ c ]); + }; + }) + (filter filterDir (attrNames dir)); + + # Import Nix files + nixFiles = + if hasAttr ".skip-subtree" dir then [ ] + else filter (f: f != null) (map nixFileName (attrNames dir)); + nixChildren = map + (c: + let + p = joinChild (c + ".nix"); + childParts = parts ++ [ c ]; + imported = importFile args scopedArgs p childParts argsFilter; + in + { + name = c; + value = + if isAttrs imported + then merge imported (marker childParts { }) + else imported; + }) + nixFiles; + + nodeValue = if dir ? "default.nix" then self else { }; + + allChildren = listToAttrs ( + if dir ? "default.nix" + then children + else nixChildren ++ children + ); + + in + if isAttrs nodeValue + then merge nodeValue (allChildren // (marker parts allChildren)) + else nodeValue; + + # Function which can be used to find all readTree targets within an + # attribute set. + # + # This function will gather physical targets, that is targets which + # correspond directly to a location in the repository, as well as + # subtargets (specified in the meta.targets attribute of a node). + # + # This can be used to discover targets for inclusion in CI + # pipelines. + # + # Called with the arguments: + # + # eligible: Function to determine whether the given derivation + # should be included in the build. + gather = eligible: node: + if node ? __readTree then + # Include the node itself if it is eligible. + (if eligible node then [ node ] else [ ]) + # Include eligible children of the node + ++ concatMap (gather eligible) (map (attr: node."${attr}") node.__readTreeChildren) + # Include specified sub-targets of the node + ++ filter eligible (map + (k: (node."${k}" or { }) // { + # Keep the same tree location, but explicitly mark this + # node as a subtarget. + __readTree = node.__readTree; + __readTreeChildren = [ ]; + __subtarget = k; + }) + (node.meta.targets or [ ])) + else [ ]; + + # Determine whether a given value is a derivation. + # Copied from nixpkgs/lib for cases where lib is not available yet. + isDerivation = x: isAttrs x && x ? type && x.type == "derivation"; +in +{ + inherit gather; + + __functor = _: + { path + , args + , filter ? (_parts: x: x) + , scopedArgs ? { } + }: + readTree { + inherit args scopedArgs; + argsFilter = filter; + initPath = path; + rootDir = true; + parts = [ ]; + }; + + # In addition to readTree itself, some functionality is exposed that + # is useful for users of readTree. + + # Create a readTree filter disallowing access to the specified + # top-level folder in the repository, except for specific exceptions + # specified by their (full) paths. + # + # Called with the arguments: + # + # folder: Name of the restricted top-level folder (e.g. 'experimental') + # + # exceptions: List of readTree parts (e.g. [ [ "services" "some-app" ] ]), + # which should be able to access the restricted folder. + # + # reason: Textual explanation for the restriction (included in errors) + restrictFolder = { folder, exceptions ? [ ], reason }: parts: args: + if (elemAt parts 0) == folder || elem parts exceptions + then args + else args // { + depot = args.depot // { + "${folder}" = throw '' + Access to targets under //${folder} is not permitted from + other repository paths. Specific exceptions are configured + at the top-level. + + ${reason} + At location: ${builtins.concatStringsSep "." parts} + ''; + }; + }; + + # This definition of fix is identical to .lib.fix, but is + # provided here for cases where readTree is used before nixpkgs can + # be imported. + # + # It is often required to create the args attribute set. + fix = f: let x = f x; in x; + + # Takes an attribute set and adds a meta.targets attribute to it + # which contains all direct children of the attribute set which are + # derivations. + # + # Type: attrs -> attrs + drvTargets = attrs: attrs // { + meta = { + targets = builtins.filter + (x: isDerivation attrs."${x}") + (builtins.attrNames attrs); + } // (attrs.meta or { }); + }; +} diff --git a/nix/readline/default.nix b/nix/readline/default.nix new file mode 100644 index 0000000..e8abcb0 --- /dev/null +++ b/nix/readline/default.nix @@ -0,0 +1,36 @@ +{ disruptor, pkgs, lib, ... }: + +let + readlineStatic = pkgs.readline81.overrideAttrs (oldAttrs: rec { + configureFlags = [ + "--enable-static" + "--disable-shared" + ]; + + # static build, so don't need ncurses + # (we also let Bazel handle the dependency) + propagateBuildInputs = []; + + patches = [ + ./no-arch_only.patch + ] ++ oldAttrs.upstreamPatches; + }); +in +pkgs.stdenv.mkDerivation { + name = "readline-static.bzl"; + buildInputs = [ + readlineStatic + readlineStatic.dev + ]; + + phases = [ + "installPhase" + ]; + + installPhase = '' + mkdir $out + cp ${disruptor.bazelHelpers.createCppBuildFile "readline"} $out/BUILD.bazel + cp -R ${readlineStatic}/* $out/ + cp -R ${readlineStatic.dev}/include $out/ + ''; +} diff --git a/example_project_bzl_4/third_party/readline/no-arch_only.patch b/nix/readline/no-arch_only.patch similarity index 100% rename from example_project_bzl_4/third_party/readline/no-arch_only.patch rename to nix/readline/no-arch_only.patch diff --git a/nix/xorg/libX11/default.nix b/nix/xorg/libX11/default.nix new file mode 100644 index 0000000..6a4a21e --- /dev/null +++ b/nix/xorg/libX11/default.nix @@ -0,0 +1,20 @@ +{ disruptor, pkgs, lib, ... }: + +pkgs.stdenv.mkDerivation { + name = "xorg.libX11.bzl"; + buildInputs = [ + pkgs.xorg.libX11 + pkgs.xorg.libX11.dev + ]; + + phases = [ + "installPhase" + ]; + + installPhase = '' + mkdir $out + cp ${disruptor.bazelHelpers.createCppBuildFile "xorg.libX11"} $out/BUILD.bazel + cp -R ${pkgs.xorg.libX11}/* $out/ + cp -R ${pkgs.xorg.libX11.dev}/include $out/ + ''; +} diff --git a/nix/xorg/xorgproto/default.nix b/nix/xorg/xorgproto/default.nix new file mode 100644 index 0000000..c2a4a1b --- /dev/null +++ b/nix/xorg/xorgproto/default.nix @@ -0,0 +1,18 @@ +{ disruptor, pkgs, lib, ... }: + +pkgs.stdenv.mkDerivation { + name = "xorg.xorgproto.bzl"; + buildInputs = [ + pkgs.xorg.xorgproto + ]; + + phases = [ + "installPhase" + ]; + + installPhase = '' + mkdir $out + cp ${disruptor.bazelHelpers.createCppBuildFile "xorg.xorgproto"} $out/BUILD.bazel + cp -R ${pkgs.xorg.xorgproto}/* $out/ + ''; +} diff --git a/nix/xz/default.nix b/nix/xz/default.nix new file mode 100644 index 0000000..c7d6a16 --- /dev/null +++ b/nix/xz/default.nix @@ -0,0 +1,20 @@ +{ disruptor, pkgs, lib, ... }: + +pkgs.stdenv.mkDerivation { + name = "xz.bzl"; + buildInputs = [ + pkgs.xz + pkgs.xz.dev + ]; + + phases = [ + "installPhase" + ]; + + installPhase = '' + mkdir $out + cp ${disruptor.bazelHelpers.createCppBuildFile "xz"} $out/BUILD.bazel + cp -R ${pkgs.xz}/* $out/ + cp -R ${pkgs.xz.dev}/include $out/ + ''; +}