diff --git a/Makefile b/Makefile index cea3d6d1e..9e6d93337 100644 --- a/Makefile +++ b/Makefile @@ -150,7 +150,7 @@ lint: @golangci-lint run @go mod verify @flake8 --show-source --count --statistics - @find . -name "*.nix" -type f | xargs nixpkgs-fmt --check + @find . -name "*.nix" -type f | xargs nixfmt -c # a trick to make all the lint commands execute, return error when at least one fails. # golangci-lint is run in standalone job in ci diff --git a/default.nix b/default.nix index 2aebcf34b..e6b5a2166 100644 --- a/default.nix +++ b/default.nix @@ -1,17 +1,18 @@ -{ lib -, stdenv -, buildGoApplication -, nix-gitignore -, writeShellScript -, buildPackages -, coverage ? false # https://tip.golang.org/doc/go1.20#cover -, gomod2nix -, rocksdb ? null -, network ? "mainnet" # mainnet|testnet -, rev ? "dirty" -, ledger_zemu ? false -, static ? stdenv.hostPlatform.isStatic -, nativeByteOrder ? true # nativeByteOrder mode will panic on big endian machines +{ + lib, + stdenv, + buildGoApplication, + nix-gitignore, + writeShellScript, + buildPackages, + coverage ? false, # https://tip.golang.org/doc/go1.20#cover + gomod2nix, + rocksdb ? null, + network ? "mainnet", # mainnet|testnet + rev ? "dirty", + ledger_zemu ? false, + static ? stdenv.hostPlatform.isStatic, + nativeByteOrder ? true, # nativeByteOrder mode will panic on big endian machines }: let inherit (lib) concatStringsSep; @@ -50,19 +51,27 @@ buildGoApplication rec { buildInputs = lib.lists.optional (rocksdb != null) rocksdb; CGO_ENABLED = "1"; CGO_LDFLAGS = lib.optionalString (rocksdb != null) ( - if static then "-lrocksdb -pthread -lstdc++ -ldl -lzstd -lsnappy -llz4 -lbz2 -lz" - else if stdenv.hostPlatform.isWindows then "-lrocksdb-shared" - else "-lrocksdb -pthread -lstdc++ -ldl" + if static then + "-lrocksdb -pthread -lstdc++ -ldl -lzstd -lsnappy -llz4 -lbz2 -lz" + else if stdenv.hostPlatform.isWindows then + "-lrocksdb-shared" + else + "-lrocksdb -pthread -lstdc++ -ldl" ); - tags = [ - "cgo" - "ledger" - "!test_ledger_mock" - "!ledger_mock" - (if ledger_zemu then "ledger_zemu" else "!ledger_zemu") - network - ] ++ lib.optionals (rocksdb != null) [ "rocksdb" "grocksdb_no_link" ] - ++ lib.optionals nativeByteOrder [ "nativebyteorder" ]; + tags = + [ + "cgo" + "ledger" + "!test_ledger_mock" + "!ledger_mock" + (if ledger_zemu then "ledger_zemu" else "!ledger_zemu") + network + ] + ++ lib.optionals (rocksdb != null) [ + "rocksdb" + "grocksdb_no_link" + ] + ++ lib.optionals nativeByteOrder [ "nativebyteorder" ]; ldflags = '' -X github.com/cosmos/cosmos-sdk/version.Name=crypto-org-chain -X github.com/cosmos/cosmos-sdk/version.AppName=${pname} @@ -76,7 +85,8 @@ buildGoApplication rec { passthru = { # update script use the same golang version as the project updateScript = - let helper = gomod2nix.override { inherit go; }; + let + helper = gomod2nix.override { inherit go; }; in writeShellScript "${pname}-updater" '' exec ${helper}/bin/gomod2nix diff --git a/docker.nix b/docker.nix index d8f889f07..6d158b72d 100644 --- a/docker.nix +++ b/docker.nix @@ -1,17 +1,18 @@ -{ system ? "x86_64-linux", pkgs ? import ./nix { inherit system; } }: +{ + system ? "x86_64-linux", + pkgs ? import ./nix { inherit system; }, +}: let self = import ./. { inherit pkgs; }; in { - chaindImage = - pkgs.dockerTools.buildLayeredImage { - name = "crypto-org-chain/chain-maind"; - config.Entrypoint = [ "${pkgs.callPackage ./. {}}/bin/chain-maind" ]; - }; + chaindImage = pkgs.dockerTools.buildLayeredImage { + name = "crypto-org-chain/chain-maind"; + config.Entrypoint = [ "${pkgs.callPackage ./. { }}/bin/chain-maind" ]; + }; - pystarportImage = - pkgs.dockerTools.buildLayeredImage { - name = "crypto-org-chain/chain-main-pystarport"; - config.Entrypoint = [ "${pkgs.test-env}/bin/pystarport" ]; - }; + pystarportImage = pkgs.dockerTools.buildLayeredImage { + name = "crypto-org-chain/chain-main-pystarport"; + config.Entrypoint = [ "${pkgs.test-env}/bin/pystarport" ]; + }; } diff --git a/flake.nix b/flake.nix index 0b50a4b03..cbdd3790a 100644 --- a/flake.nix +++ b/flake.nix @@ -14,12 +14,12 @@ }; outputs = - { self - , nixpkgs - , nix-bundle-exe - , gomod2nix - , flake-utils - , + { + self, + nixpkgs, + nix-bundle-exe, + gomod2nix, + flake-utils, }: let rev = self.shortRev or "dirty"; @@ -59,6 +59,7 @@ defaultPackage.go pkgs.gomod2nix pkgs.rocksdb + pkgs.nixfmt-rfc-style ]; }; }; @@ -104,32 +105,28 @@ ]; }; binaries = builtins.listToAttrs ( - builtins.map - ( - { network, pkgtype }: - { - name = builtins.concatStringsSep "-" ( - [ "chain-maind" ] - ++ lib.optional (network != "mainnet") network - ++ lib.optional (pkgtype != "nix") pkgtype - ); - value = - let - chain-maind = callPackage ./. { - inherit rev network; - }; - bundle = - if stdenv.hostPlatform.isWindows then bundle-win-exe chain-maind else bundle-exe chain-maind; - in - if pkgtype == "bundle" then - bundle - else if pkgtype == "tarball" then - make-tarball bundle - else - chain-maind; - } - ) - matrix + builtins.map ( + { network, pkgtype }: + { + name = builtins.concatStringsSep "-" ( + [ "chain-maind" ] + ++ lib.optional (network != "mainnet") network + ++ lib.optional (pkgtype != "nix") pkgtype + ); + value = + let + chain-maind = callPackage ./. { inherit rev network; }; + bundle = + if stdenv.hostPlatform.isWindows then bundle-win-exe chain-maind else bundle-exe chain-maind; + in + if pkgtype == "bundle" then + bundle + else if pkgtype == "tarball" then + make-tarball bundle + else + chain-maind; + } + ) matrix ); in { diff --git a/integration_tests/shell.nix b/integration_tests/shell.nix index c5ca520f1..fedc22462 100644 --- a/integration_tests/shell.nix +++ b/integration_tests/shell.nix @@ -1,4 +1,7 @@ -{ system ? builtins.currentSystem, pkgs ? import ../nix { inherit system; } }: +{ + system ? builtins.currentSystem, + pkgs ? import ../nix { inherit system; }, +}: pkgs.mkShell { buildInputs = with pkgs; [ # build tools @@ -7,7 +10,7 @@ pkgs.mkShell { # lint tools test-env - nixpkgs-fmt + nixfmt lint-ci # tools diff --git a/integration_tests/upgrade-test.nix b/integration_tests/upgrade-test.nix index ef03992cd..3e8462600 100644 --- a/integration_tests/upgrade-test.nix +++ b/integration_tests/upgrade-test.nix @@ -1,24 +1,58 @@ let pkgs = import ../nix { }; - released = (import (builtins.fetchTarball "https://github.com/crypto-org-chain/chain-main/archive/v1.1.0.tar.gz") { }).chain-maind; - released2 = (import (builtins.fetchTarball "https://github.com/crypto-org-chain/chain-main/archive/v2.0.1.tar.gz") { }).chain-maind; - released3 = (import (builtins.fetchTarball "https://github.com/crypto-org-chain/chain-main/archive/v3.3.4.tar.gz") { }).chain-maind; - fetchFlake = repo: rev: (pkgs.flake-compat { - src = { - outPath = builtins.fetchTarball "https://github.com/${repo}/archive/${rev}.tar.gz"; - inherit rev; - shortRev = builtins.substring 0 7 rev; - }; - }).defaultNix; - released4_2 = (fetchFlake "crypto-org-chain/chain-main" "b3226f06fd2a236f9957304c4d83b0ea06ed2604").default; - released4_3 = (fetchFlake "crypto-org-chain/chain-main" "7598bc46226a1b58116da2e6bd3903aca5b5313b").default; + released = + (import + (builtins.fetchTarball "https://github.com/crypto-org-chain/chain-main/archive/v1.1.0.tar.gz") + { } + ).chain-maind; + released2 = + (import + (builtins.fetchTarball "https://github.com/crypto-org-chain/chain-main/archive/v2.0.1.tar.gz") + { } + ).chain-maind; + released3 = + (import + (builtins.fetchTarball "https://github.com/crypto-org-chain/chain-main/archive/v3.3.4.tar.gz") + { } + ).chain-maind; + fetchFlake = + repo: rev: + (pkgs.flake-compat { + src = { + outPath = builtins.fetchTarball "https://github.com/${repo}/archive/${rev}.tar.gz"; + inherit rev; + shortRev = builtins.substring 0 7 rev; + }; + }).defaultNix; + released4_2 = + (fetchFlake "crypto-org-chain/chain-main" "b3226f06fd2a236f9957304c4d83b0ea06ed2604").default; + released4_3 = + (fetchFlake "crypto-org-chain/chain-main" "7598bc46226a1b58116da2e6bd3903aca5b5313b").default; current = pkgs.callPackage ../. { }; in pkgs.linkFarm "upgrade-test-package" [ - { name = "genesis"; path = released; } - { name = "v2.0.0"; path = released2; } - { name = "v3.0.0"; path = released3; } - { name = "v4.2.0"; path = released4_2; } - { name = "v4.3.0"; path = released4_3; } - { name = "v5.0"; path = current; } + { + name = "genesis"; + path = released; + } + { + name = "v2.0.0"; + path = released2; + } + { + name = "v3.0.0"; + path = released3; + } + { + name = "v4.2.0"; + path = released4_2; + } + { + name = "v4.3.0"; + path = released4_3; + } + { + name = "v5.0"; + path = current; + } ] diff --git a/nix/bundle-win-exe.nix b/nix/bundle-win-exe.nix index ed31cdf9f..0a42aba85 100644 --- a/nix/bundle-win-exe.nix +++ b/nix/bundle-win-exe.nix @@ -1,35 +1,37 @@ -{ runCommand -, windows -, stdenv -, rocksdb -, bzip2 -, lz4 -, snappy -, zstd -, zlib -, chain-maind +{ + runCommand, + windows, + stdenv, + rocksdb, + bzip2, + lz4, + snappy, + zstd, + zlib, + chain-maind, }: runCommand "tarball-${chain-maind.name}" -{ - # manually enumerate the runtime dependencies of chain-maind on mingwW64 - deps = [ - "${rocksdb}/bin/librocksdb-shared.dll" - "${snappy}/bin/libsnappy.dll" - "${lz4.out}/lib/liblz4.dll" - "${bzip2.bin}/bin/libbz2-1.dll" - "${zlib}/bin/zlib1.dll" - "${zstd.bin}/bin/libzstd.dll" - "${windows.mingw_w64_pthreads}/bin/libwinpthread-1.dll" - "${windows.mcfgthreads}/bin/libmcfgthread-1.dll" - "${stdenv.cc.cc.lib}/x86_64-w64-mingw32/lib/libgcc_s_seh-1.dll" - "${stdenv.cc.cc.lib}/x86_64-w64-mingw32/lib/libstdc++-6.dll" - ]; -} '' - mkdir -p $out - for so in $deps - do - cp $so $out/ - done + { + # manually enumerate the runtime dependencies of chain-maind on mingwW64 + deps = [ + "${rocksdb}/bin/librocksdb-shared.dll" + "${snappy}/bin/libsnappy.dll" + "${lz4.out}/lib/liblz4.dll" + "${bzip2.bin}/bin/libbz2-1.dll" + "${zlib}/bin/zlib1.dll" + "${zstd.bin}/bin/libzstd.dll" + "${windows.mingw_w64_pthreads}/bin/libwinpthread-1.dll" + "${windows.mcfgthreads}/bin/libmcfgthread-1.dll" + "${stdenv.cc.cc.lib}/x86_64-w64-mingw32/lib/libgcc_s_seh-1.dll" + "${stdenv.cc.cc.lib}/x86_64-w64-mingw32/lib/libstdc++-6.dll" + ]; + } + '' + mkdir -p $out + for so in $deps + do + cp $so $out/ + done - cp ${chain-maind}/bin/${chain-maind.meta.mainProgram} $out/ -'' + cp ${chain-maind}/bin/${chain-maind.meta.mainProgram} $out/ + '' diff --git a/nix/default.nix b/nix/default.nix index 404f5ef04..e421552b9 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,4 +1,7 @@ -{ sources ? import ./sources.nix, system ? builtins.currentSystem }: +{ + sources ? import ./sources.nix, + system ? builtins.currentSystem, +}: import sources.nixpkgs { overlays = [ (_: pkgs: { @@ -25,12 +28,10 @@ import sources.nixpkgs { ${pkgs.test-env}/bin/flake8 --show-source --count --statistics \ --format="::error file=%(path)s,line=%(row)d,col=%(col)d::%(path)s:%(row)d:%(col)d: %(code)s %(text)s" \ || EXIT_STATUS=$? - find . -name "*.nix" -type f | xargs ${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt --check || EXIT_STATUS=$? + find . -name "*.nix" -type f | xargs ${pkgs.nixfmt-rfc-style}/bin/nixfmt -c || EXIT_STATUS=$? exit $EXIT_STATUS ''; - chain-maind-zemu = pkgs.callPackage ../. { - ledger_zemu = true; - }; + chain-maind-zemu = pkgs.callPackage ../. { ledger_zemu = true; }; # chain-maind for integration test chain-maind-test = pkgs.callPackage ../. { ledger_zemu = true; diff --git a/nix/golangci-lint.nix b/nix/golangci-lint.nix index 9845f267d..9f94ac696 100644 --- a/nix/golangci-lint.nix +++ b/nix/golangci-lint.nix @@ -1,4 +1,9 @@ -{ buildGo123Module, fetchFromGitHub, lib, installShellFiles }: +{ + buildGo123Module, + fetchFromGitHub, + lib, + installShellFiles, +}: buildGo123Module rec { pname = "golangci-lint"; @@ -38,6 +43,9 @@ buildGo123Module rec { changelog = "https://github.com/golangci/golangci-lint/blob/v${version}/CHANGELOG.md"; mainProgram = "golangci-lint"; license = licenses.gpl3Plus; - maintainers = with maintainers; [ SuperSandro2000 mic92 ]; + maintainers = with maintainers; [ + SuperSandro2000 + mic92 + ]; }; } diff --git a/nix/hermes.nix b/nix/hermes.nix index 67268a410..4db4b1849 100644 --- a/nix/hermes.nix +++ b/nix/hermes.nix @@ -1,11 +1,12 @@ -{ src -, lib -, stdenv -, darwin -, rustPlatform -, symlinkJoin -, openssl -, pkg-config +{ + src, + lib, + stdenv, + darwin, + rustPlatform, + symlinkJoin, + openssl, + pkg-config, }: rustPlatform.buildRustPackage rec { name = "hermes"; @@ -26,6 +27,9 @@ rustPlatform.buildRustPackage rec { OPENSSL_NO_VENDOR = "1"; OPENSSL_DIR = symlinkJoin { name = "openssl"; - paths = with openssl; [ out dev ]; + paths = with openssl; [ + out + dev + ]; }; } diff --git a/nix/rocksdb.nix b/nix/rocksdb.nix index a9dd5d6e8..87a86f312 100644 --- a/nix/rocksdb.nix +++ b/nix/rocksdb.nix @@ -1,22 +1,23 @@ -{ lib -, stdenv -, fetchFromGitHub -, fetchpatch -, cmake -, ninja -, bzip2 -, lz4 -, snappy -, zlib -, zstd -, windows +{ + lib, + stdenv, + fetchFromGitHub, + fetchpatch, + cmake, + ninja, + bzip2, + lz4, + snappy, + zlib, + zstd, + windows, # only enable jemalloc for non-windows platforms # see: https://github.com/NixOS/nixpkgs/issues/216479 -, enableJemalloc ? !stdenv.hostPlatform.isWindows && !stdenv.hostPlatform.isStatic -, jemalloc -, enableLite ? false -, enableShared ? !stdenv.hostPlatform.isStatic -, sse42Support ? stdenv.hostPlatform.sse4_2Support + enableJemalloc ? !stdenv.hostPlatform.isWindows && !stdenv.hostPlatform.isStatic, + jemalloc, + enableLite ? false, + enableShared ? !stdenv.hostPlatform.isStatic, + sse42Support ? stdenv.hostPlatform.sse4_2Support, }: stdenv.mkDerivation rec { @@ -30,11 +31,21 @@ stdenv.mkDerivation rec { sha256 = "sha256-Zifn5Gu/4h6TaEqSaWQ2mFdryeAarqbHWW3fKUGGFac="; }; - nativeBuildInputs = [ cmake ninja ]; + nativeBuildInputs = [ + cmake + ninja + ]; - propagatedBuildInputs = [ bzip2 lz4 snappy zlib zstd ]; + propagatedBuildInputs = [ + bzip2 + lz4 + snappy + zlib + zstd + ]; - buildInputs = lib.optional enableJemalloc jemalloc + buildInputs = + lib.optional enableJemalloc jemalloc ++ lib.optional stdenv.hostPlatform.isMinGW windows.mingw_w64_pthreads; outputs = [ @@ -42,16 +53,18 @@ stdenv.mkDerivation rec { "tools" ]; - NIX_CFLAGS_COMPILE = lib.optionals stdenv.cc.isGNU [ - "-Wno-error=deprecated-copy" - "-Wno-error=pessimizing-move" - # Needed with GCC 12 - "-Wno-error=format-truncation" - "-Wno-error=maybe-uninitialized" - ] ++ lib.optionals stdenv.cc.isClang [ - "-Wno-error=unused-private-field" - "-faligned-allocation" - ]; + NIX_CFLAGS_COMPILE = + lib.optionals stdenv.cc.isGNU [ + "-Wno-error=deprecated-copy" + "-Wno-error=pessimizing-move" + # Needed with GCC 12 + "-Wno-error=format-truncation" + "-Wno-error=maybe-uninitialized" + ] + ++ lib.optionals stdenv.cc.isClang [ + "-Wno-error=unused-private-field" + "-faligned-allocation" + ]; cmakeFlags = [ "-DPORTABLE=1" @@ -77,25 +90,30 @@ stdenv.mkDerivation rec { # otherwise "cc1: error: -Wformat-security ignored without -Wformat [-Werror=format-security]" hardeningDisable = lib.optional stdenv.hostPlatform.isWindows "format"; - preInstall = '' - mkdir -p $tools/bin - cp tools/{ldb,sst_dump}${stdenv.hostPlatform.extensions.executable} $tools/bin/ - '' + lib.optionalString stdenv.isDarwin '' - ls -1 $tools/bin/* | xargs -I{} ${stdenv.cc.bintools.targetPrefix}install_name_tool -change "@rpath/librocksdb.${lib.versions.major version}.dylib" $out/lib/librocksdb.dylib {} - '' + lib.optionalString (stdenv.isLinux && enableShared) '' - ls -1 $tools/bin/* | xargs -I{} patchelf --set-rpath $out/lib:${stdenv.cc.cc.lib}/lib {} - ''; + preInstall = + '' + mkdir -p $tools/bin + cp tools/{ldb,sst_dump}${stdenv.hostPlatform.extensions.executable} $tools/bin/ + '' + + lib.optionalString stdenv.isDarwin '' + ls -1 $tools/bin/* | xargs -I{} ${stdenv.cc.bintools.targetPrefix}install_name_tool -change "@rpath/librocksdb.${lib.versions.major version}.dylib" $out/lib/librocksdb.dylib {} + '' + + lib.optionalString (stdenv.isLinux && enableShared) '' + ls -1 $tools/bin/* | xargs -I{} patchelf --set-rpath $out/lib:${stdenv.cc.cc.lib}/lib {} + ''; # Old version doesn't ship the .pc file, new version puts wrong paths in there. - postFixup = '' - if [ -f "$out"/lib/pkgconfig/rocksdb.pc ]; then - substituteInPlace "$out"/lib/pkgconfig/rocksdb.pc \ - --replace '="''${prefix}//' '="/' - fi - '' + lib.optionalString stdenv.isDarwin '' - ${stdenv.cc.targetPrefix}install_name_tool -change "@rpath/libsnappy.1.dylib" "${snappy}/lib/libsnappy.1.dylib" $out/lib/librocksdb.dylib - ${stdenv.cc.targetPrefix}install_name_tool -change "@rpath/librocksdb.${lib.versions.major version}.dylib" "$out/lib/librocksdb.${lib.versions.major version}.dylib" $out/lib/librocksdb.dylib - ''; + postFixup = + '' + if [ -f "$out"/lib/pkgconfig/rocksdb.pc ]; then + substituteInPlace "$out"/lib/pkgconfig/rocksdb.pc \ + --replace '="''${prefix}//' '="/' + fi + '' + + lib.optionalString stdenv.isDarwin '' + ${stdenv.cc.targetPrefix}install_name_tool -change "@rpath/libsnappy.1.dylib" "${snappy}/lib/libsnappy.1.dylib" $out/lib/librocksdb.dylib + ${stdenv.cc.targetPrefix}install_name_tool -change "@rpath/librocksdb.${lib.versions.major version}.dylib" "$out/lib/librocksdb.${lib.versions.major version}.dylib" $out/lib/librocksdb.dylib + ''; meta = with lib; { homepage = "https://rocksdb.org"; @@ -103,6 +121,9 @@ stdenv.mkDerivation rec { changelog = "https://github.com/facebook/rocksdb/raw/v${version}/HISTORY.md"; license = licenses.asl20; platforms = platforms.all; - maintainers = with maintainers; [ adev magenbluten ]; + maintainers = with maintainers; [ + adev + magenbluten + ]; }; } diff --git a/nix/solomachine.nix b/nix/solomachine.nix index 8157ef5bf..250aac198 100644 --- a/nix/solomachine.nix +++ b/nix/solomachine.nix @@ -1,11 +1,11 @@ -{ fetchFromGitHub -, lib -, stdenv -, darwin -, rustPlatform -, protobuf -, rustfmt -, +{ + fetchFromGitHub, + lib, + stdenv, + darwin, + rustPlatform, + protobuf, + rustfmt, }: rustPlatform.buildRustPackage rec { pname = "ibc-solo-machine"; diff --git a/nix/sources.nix b/nix/sources.nix index f614e6867..99cdf8747 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -4,76 +4,99 @@ let # The fetchers. fetch_ fetches specs of type . # - fetch_file = pkgs: spec: + fetch_file = + pkgs: spec: if spec.builtin or true then builtins_fetchurl { inherit (spec) url sha256; } else pkgs.fetchurl { inherit (spec) url sha256; }; - fetch_tarball = pkgs: name: spec: + fetch_tarball = + pkgs: name: spec: let - ok = str: ! builtins.isNull (builtins.match "[a-zA-Z0-9+-._?=]" str); + ok = str: !builtins.isNull (builtins.match "[a-zA-Z0-9+-._?=]" str); # sanitize the name, though nix will still fail if name starts with period - name' = stringAsChars (x: if ! ok x then "-" else x) "${name}-src"; + name' = stringAsChars (x: if !ok x then "-" else x) "${name}-src"; in if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + builtins_fetchTarball { + name = name'; + inherit (spec) url sha256; + } else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = spec: - builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; }; + pkgs.fetchzip { + name = name'; + inherit (spec) url sha256; + }; + + fetch_git = + spec: + builtins.fetchGit { + url = spec.repo; + inherit (spec) rev ref; + }; fetch_local = spec: spec.path; - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; + fetch_builtin-tarball = + name: + throw '' + [${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; + fetch_builtin-url = + name: + throw '' + [${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; # # Various helpers # # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: + mkPkgs = + sources: let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { }; + sourcesNixpkgs = import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { }; hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; hasThisAsNixpkgsPath = == ./.; in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + if builtins.hasAttr "nixpkgs" sources then + sourcesNixpkgs + else if hasNixpkgsPath && !hasThisAsNixpkgsPath then import { } else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; + abort '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; # The actual fetching function. - fetch = pkgs: name: spec: + fetch = + pkgs: name: spec: - if ! builtins.hasAttr "type" spec then + if !builtins.hasAttr "type" spec then abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name + else if spec.type == "file" then + fetch_file pkgs spec + else if spec.type == "tarball" then + fetch_tarball pkgs name spec + else if spec.type == "git" then + fetch_git spec + else if spec.type == "local" then + fetch_local spec + else if spec.type == "builtin-tarball" then + fetch_builtin-tarball name + else if spec.type == "builtin-url" then + fetch_builtin-url name else abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; # If the environment variable NIV_OVERRIDE_${name} is set, then use # the path directly as opposed to the fetched source. - replace = name: drv: + replace = + name: drv: let saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; @@ -83,13 +106,21 @@ let # Ports of functions for older nix versions # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); + mapAttrs = + builtins.mapAttrs or ( + f: set: + with builtins; + listToAttrs ( + map (attr: { + name = attr; + value = f attr set.${attr}; + }) (attrNames set) + ) + ); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + range = + first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); @@ -99,45 +130,44 @@ let concatStrings = builtins.concatStringsSep ""; # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name, sha256 }@attrs: + builtins_fetchTarball = + { + url, + name, + sha256, + }@attrs: let inherit (builtins) lessThan nixVersion fetchTarball; in - if lessThan nixVersion "1.12" then - fetchTarball { inherit name url; } - else - fetchTarball attrs; + if lessThan nixVersion "1.12" then fetchTarball { inherit name url; } else fetchTarball attrs; # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, sha256 }@attrs: + builtins_fetchurl = + { url, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchurl; in - if lessThan nixVersion "1.12" then - fetchurl { inherit url; } - else - fetchurl attrs; + if lessThan nixVersion "1.12" then fetchurl { inherit url; } else fetchurl attrs; # Create the final "sources" from the config - mkSources = config: - mapAttrs - ( - name: spec: - if builtins.hasAttr "outPath" spec - then - abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) - config.sources; + mkSources = + config: + mapAttrs ( + name: spec: + if builtins.hasAttr "outPath" spec then + abort "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) config.sources; # The "config" used by the fetchers mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then { } else builtins.fromJSON (builtins.readFile sourcesFile) - , pkgs ? mkPkgs sources - }: rec { + { + sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null, + sources ? if isNull sourcesFile then { } else builtins.fromJSON (builtins.readFile sourcesFile), + pkgs ? mkPkgs sources, + }: + rec { # The sources, i.e. the attribute set of spec name to spec inherit sources; diff --git a/nix/testenv.nix b/nix/testenv.nix index 59353e2f8..23424ee76 100644 --- a/nix/testenv.nix +++ b/nix/testenv.nix @@ -1,8 +1,13 @@ -{ poetry2nix, python311, lib }: +{ + poetry2nix, + python311, + lib, +}: poetry2nix.mkPoetryEnv { python = python311; projectDir = ../integration_tests; - overrides = poetry2nix.overrides.withDefaults (self: super: + overrides = poetry2nix.overrides.withDefaults ( + self: super: let buildSystems = { pystarport = [ "poetry-core" ]; @@ -12,14 +17,17 @@ poetry2nix.mkPoetryEnv { pytest-github-actions-annotate-failures = [ "setuptools" ]; flake8-black = [ "setuptools" ]; flake8-isort = [ "hatchling" ]; - docker = [ "hatchling" "hatch-vcs" ]; + docker = [ + "hatchling" + "hatch-vcs" + ]; }; in - lib.mapAttrs - (attr: systems: super.${attr}.overridePythonAttrs - (old: { - nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ map (a: self.${a}) systems; - })) - buildSystems + lib.mapAttrs ( + attr: systems: + super.${attr}.overridePythonAttrs (old: { + nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ map (a: self.${a}) systems; + }) + ) buildSystems ); } diff --git a/proto.nix b/proto.nix index 4d12b1d4c..d1a7997a1 100644 --- a/proto.nix +++ b/proto.nix @@ -1,11 +1,14 @@ -{ pkgs ? import ./nix { }, commit ? "" }: +{ + pkgs ? import ./nix { }, + commit ? "", +}: with pkgs; pkgs.mkShell { buildInputs = [ buf git ]; - shellHook = '' - cd ./pystarport - ./new-convert.sh ''; + shellHook = '' + cd ./pystarport + ./new-convert.sh ''; } diff --git a/pystarport/default.nix b/pystarport/default.nix index 3fe538828..55723ba87 100644 --- a/pystarport/default.nix +++ b/pystarport/default.nix @@ -1,3 +1,4 @@ -{ pkgs ? import { } +{ + pkgs ? import { }, }: pkgs.poetry2nix.mkPoetryEnv { projectDir = ./.; }