Skip to content

Commit

Permalink
Problem: nixpkgs-fmt is deprecated (backport: #1677) (#1687)
Browse files Browse the repository at this point in the history
Solution:
- switch to nixfmt-rfc-style
  • Loading branch information
yihuang authored Nov 12, 2024
1 parent a4a57aa commit 1f20b38
Show file tree
Hide file tree
Showing 24 changed files with 641 additions and 426 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ jobs:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
if: steps.changed-files.outputs.any_changed == 'true'
- run: nix-shell -I nixpkgs=./nix -p nixpkgs-fmt --run "make lint-nix"
- run: nix develop -c make lint-nix
if: steps.changed-files.outputs.any_changed == 'true'
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ lint-py:
--format="::error file=%(path)s,line=%(row)d,col=%(col)d::%(path)s:%(row)d:%(col)d: %(code)s %(text)s" \

lint-nix:
find . -name "*.nix" ! -path './integration_tests/contracts/*' ! -path "./contracts/*" | xargs nixpkgs-fmt --check
find . -name "*.nix" ! -path './integration_tests/contracts/*' ! -path "./contracts/*" | xargs nixfmt -c

.PHONY: lint lint-fix lint-py

Expand Down
5 changes: 4 additions & 1 deletion contracts/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 = [
pkgs.which
Expand Down
76 changes: 47 additions & 29 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
{ lib
, stdenv
, buildGoApplication
, nix-gitignore
, buildPackages
, coverage ? false # https://tip.golang.org/doc/go1.20#cover
, rocksdb
, network ? "mainnet" # mainnet|testnet
, rev ? "dirty"
, static ? stdenv.hostPlatform.isStatic
, nativeByteOrder ? true # nativeByteOrder mode will panic on big endian machines
{
lib,
stdenv,
buildGoApplication,
nix-gitignore,
buildPackages,
coverage ? false, # https://tip.golang.org/doc/go1.20#cover
rocksdb,
network ? "mainnet", # mainnet|testnet
rev ? "dirty",
static ? stdenv.hostPlatform.isStatic,
nativeByteOrder ? true, # nativeByteOrder mode will panic on big endian machines
}:
let
version = "v1.3.3";
pname = "cronosd";
tags = [ "ledger" "netgo" network "rocksdb" "grocksdb_no_link" ] ++ lib.optionals nativeByteOrder [ "nativebyteorder" ];
tags = [
"ledger"
"netgo"
network
"rocksdb"
"grocksdb_no_link"
] ++ lib.optionals nativeByteOrder [ "nativebyteorder" ];
ldflags = lib.concatStringsSep "\n" ([
"-X github.com/cosmos/cosmos-sdk/version.Name=cronos"
"-X github.com/cosmos/cosmos-sdk/version.AppName=${pname}"
Expand All @@ -24,29 +31,40 @@ let
buildInputs = [ rocksdb ];
in
buildGoApplication rec {
inherit pname version buildInputs tags ldflags;
src = (nix-gitignore.gitignoreSourcePure [
"/*" # ignore all, then add whitelists
"!/x/"
"!/app/"
"!/cmd/"
"!/client/"
"!/versiondb/"
"!/memiavl/"
"!/store/"
"!go.mod"
"!go.sum"
"!gomod2nix.toml"
] ./.);
inherit
pname
version
buildInputs
tags
ldflags
;
src = (
nix-gitignore.gitignoreSourcePure [
"/*" # ignore all, then add whitelists
"!/x/"
"!/app/"
"!/cmd/"
"!/client/"
"!/versiondb/"
"!/memiavl/"
"!/store/"
"!go.mod"
"!go.sum"
"!gomod2nix.toml"
] ./.
);
modules = ./gomod2nix.toml;
pwd = src; # needed to support replace
subPackages = [ "cmd/cronosd" ];
buildFlags = lib.optionalString coverage "-cover";
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"
);

postFixup = lib.optionalString (stdenv.isDarwin && rocksdb != null) ''
Expand Down
93 changes: 49 additions & 44 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,60 +18,65 @@
};
};

outputs = { self, nixpkgs, nix-bundle-exe, gomod2nix, flake-utils, poetry2nix }:
outputs =
{
self,
nixpkgs,
nix-bundle-exe,
gomod2nix,
flake-utils,
poetry2nix,
}:
let
rev = self.shortRev or "dirty";
mkApp = drv: {
type = "app";
program = "${drv}/bin/${drv.meta.mainProgram}";
};
in
(flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = self.overlays.default;
config = { };
(flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = self.overlays.default;
config = { };
};
in
rec {
packages = pkgs.cronos-matrix // {
inherit (pkgs) rocksdb testground-image;
};
apps = {
cronosd = mkApp packages.cronosd;
cronosd-testnet = mkApp packages.cronosd-testnet;
stateless-testcase = {
type = "app";
program = "${pkgs.benchmark-testcase}/bin/stateless-testcase";
};
in
rec {
packages = pkgs.cronos-matrix // {
inherit (pkgs) rocksdb testground-image;
};
defaultPackage = packages.cronosd;
defaultApp = apps.cronosd;
devShells = rec {
default = pkgs.mkShell {
buildInputs = [
defaultPackage.go
pkgs.gomod2nix
pkgs.nixfmt-rfc-style
];
};
apps = {
cronosd = mkApp packages.cronosd;
cronosd-testnet = mkApp packages.cronosd-testnet;
stateless-testcase = {
type = "app";
program = "${pkgs.benchmark-testcase}/bin/stateless-testcase";
};
rocksdb = pkgs.mkShell {
buildInputs = default.buildInputs ++ [
pkgs.rocksdb
pkgs.rocksdb.tools
];
};
defaultPackage = packages.cronosd;
defaultApp = apps.cronosd;
devShells = rec {
default = pkgs.mkShell {
buildInputs = [
defaultPackage.go
pkgs.gomod2nix
];
};
rocksdb = pkgs.mkShell {
buildInputs = default.buildInputs ++ [
pkgs.rocksdb
pkgs.rocksdb.tools
];
};
full = pkgs.mkShell {
buildInputs = rocksdb.buildInputs ++ [
pkgs.test-env
];
};
};
legacyPackages = pkgs;
}
)
) // {
full = pkgs.mkShell { buildInputs = rocksdb.buildInputs ++ [ pkgs.test-env ]; };
};
legacyPackages = pkgs;
}
))
// {
overlays.default = [
(import ./nix/build_overlay.nix)
poetry2nix.overlays.default
Expand Down
11 changes: 6 additions & 5 deletions integration_tests/configs/broken-cronosd.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{ pkgs ? import ../../nix { } }:
let cronosd = (pkgs.callPackage ../../. { });
{
pkgs ? import ../../nix { },
}:
let
cronosd = (pkgs.callPackage ../../. { });
in
cronosd.overrideAttrs (oldAttrs: {
patches = oldAttrs.patches or [ ] ++ [
./broken-cronosd.patch
];
patches = oldAttrs.patches or [ ] ++ [ ./broken-cronosd.patch ];
})
53 changes: 37 additions & 16 deletions integration_tests/configs/upgrade-test-package.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
let
pkgs = import ../../nix { };
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;
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;
# v0.7.0
released_0 = (fetchFlake "crypto-org-chain/cronos" "799ac47e293403bd57580d2ff96bb8d9851c3cde").default;
released_0 =
(fetchFlake "crypto-org-chain/cronos" "799ac47e293403bd57580d2ff96bb8d9851c3cde").default;
# v0.8.0
released_1 = (fetchFlake "crypto-org-chain/cronos" "2f2cc88b501b47149690fdef05afbbbe5bc116c9").default;
released_1 =
(fetchFlake "crypto-org-chain/cronos" "2f2cc88b501b47149690fdef05afbbbe5bc116c9").default;
# v1.0.15
released_2 = (fetchFlake "crypto-org-chain/cronos" "1f5e2618362303d91f621b47cbc1115cf4fa0195").default;
released_2 =
(fetchFlake "crypto-org-chain/cronos" "1f5e2618362303d91f621b47cbc1115cf4fa0195").default;
# v1.1.1
released_3 = (fetchFlake "crypto-org-chain/cronos" "10b8eeb9052e3c52aa59dec15f5d3aca781d1271").default;
released_3 =
(fetchFlake "crypto-org-chain/cronos" "10b8eeb9052e3c52aa59dec15f5d3aca781d1271").default;
current = pkgs.callPackage ../../. { };
in
pkgs.linkFarm "upgrade-test-package" [
{ name = "genesis"; path = released_0; }
{ name = "v0.7.0-hotfix"; path = released_1; }
{ name = "v1.0.0"; path = released_2; }
{ name = "v1.1.0"; path = released_3; }
{ name = "v1.3"; path = current; }
{
name = "genesis";
path = released_0;
}
{
name = "v0.7.0-hotfix";
path = released_1;
}
{
name = "v1.0.0";
path = released_2;
}
{
name = "v1.1.0";
path = released_3;
}
{
name = "v1.3";
path = current;
}
]
5 changes: 4 additions & 1 deletion 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; },
}:
let
renameExe = pkgs.callPackage ../nix/rename-exe.nix { };
in
Expand Down
4 changes: 1 addition & 3 deletions nix/build_overlay.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# some basic overlays nessesary for the build
final: super: {
rocksdb = final.callPackage ./rocksdb.nix { };
}
final: super: { rocksdb = final.callPackage ./rocksdb.nix { }; }
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
, cronosd
{
runCommand,
windows,
stdenv,
rocksdb,
bzip2,
lz4,
snappy,
zstd,
zlib,
cronosd,
}:
runCommand "tarball-${cronosd.name}"
{
# manually enumerate the runtime dependencies of cronosd 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 cronosd 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 ${cronosd}/bin/${cronosd.meta.mainProgram} $out/
''
cp ${cronosd}/bin/${cronosd.meta.mainProgram} $out/
''
Loading

0 comments on commit 1f20b38

Please sign in to comment.