Skip to content

Commit

Permalink
Problem: nixpkgs-fmt is deprecated (#1111)
Browse files Browse the repository at this point in the history
* Problem: nixpkgs-fmt is deprecated

Solution:
- switch to nixfmt-rfc-style

* fmt
  • Loading branch information
yihuang authored Feb 4, 2025
1 parent 0fc2416 commit 76d6cd7
Show file tree
Hide file tree
Showing 16 changed files with 398 additions and 275 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 37 additions & 27 deletions default.nix
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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}
Expand All @@ -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
Expand Down
23 changes: 12 additions & 11 deletions docker.nix
Original file line number Diff line number Diff line change
@@ -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" ];
};
}
61 changes: 29 additions & 32 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -59,6 +59,7 @@
defaultPackage.go
pkgs.gomod2nix
pkgs.rocksdb
pkgs.nixfmt-rfc-style
];
};
};
Expand Down Expand Up @@ -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
{
Expand Down
7 changes: 5 additions & 2 deletions integration_tests/shell.nix
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,7 +10,7 @@ pkgs.mkShell {

# lint tools
test-env
nixpkgs-fmt
nixfmt
lint-ci

# tools
Expand Down
70 changes: 52 additions & 18 deletions integration_tests/upgrade-test.nix
Original file line number Diff line number Diff line change
@@ -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;
}
]
66 changes: 34 additions & 32 deletions nix/bundle-win-exe.nix
Original file line number Diff line number Diff line change
@@ -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/
''
11 changes: 6 additions & 5 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{ sources ? import ./sources.nix, system ? builtins.currentSystem }:
{
sources ? import ./sources.nix,
system ? builtins.currentSystem,
}:
import sources.nixpkgs {
overlays = [
(_: pkgs: {
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 76d6cd7

Please sign in to comment.