Skip to content

Commit

Permalink
Problem: nixpkgs-fmt is deprecated (backport #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 committed Feb 4, 2025
1 parent 12cab72 commit facfe27
Show file tree
Hide file tree
Showing 19 changed files with 496 additions and 488 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,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,18 +51,26 @@ buildGoApplication rec {
buildInputs = lib.lists.optional (rocksdb != null) rocksdb;
CGO_ENABLED = "1";
CGO_LDFLAGS =
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" ];
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" ];
ldflags = ''
-X github.com/cosmos/cosmos-sdk/version.Name=crypto-org-chain
-X github.com/cosmos/cosmos-sdk/version.AppName=${pname}
Expand All @@ -75,7 +84,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" ];
};
}
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

198 changes: 108 additions & 90 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-22.11";
nixpkgs.url = "github:NixOS/nixpkgs/release-24.05";
flake-utils.url = "github:numtide/flake-utils";
nix-bundle-exe = {
url = "github:3noch/nix-bundle-exe";
Expand All @@ -13,106 +13,124 @@
};
};

outputs = { self, nixpkgs, nix-bundle-exe, gomod2nix, flake-utils }:
outputs =
{
self,
nixpkgs,
nix-bundle-exe,
gomod2nix,
flake-utils,
}:
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 = [
(import ./nix/build_overlay.nix)
gomod2nix.overlays.default
self.overlay
];
config = { };
};
in
rec {
packages = pkgs.chain-main-matrix;
apps = {
chain-maind = mkApp packages.chain-maind;
chain-maind-testnet = mkApp packages.chain-maind-testnet;
update-gomod2nix = {
type = "app";
program = "${packages.chain-maind.updateScript}";
};
(flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(import ./nix/build_overlay.nix)
gomod2nix.overlays.default
self.overlay
];
config = { };
};
in
rec {
packages = pkgs.chain-main-matrix;
apps = {
chain-maind = mkApp packages.chain-maind;
chain-maind-testnet = mkApp packages.chain-maind-testnet;
update-gomod2nix = {
type = "app";
program = "${packages.chain-maind.updateScript}";
};
defaultPackage = packages.chain-maind;
defaultApp = apps.chain-maind;
devShells = {
chain-maind = pkgs.mkShell {
buildInputs = with pkgs; [
go_1_20
rocksdb
];
};
};
devShell = devShells.chain-maind;
legacyPackages = pkgs;
}
)
) // {
overlay = final: prev: {
bundle-exe = final.pkgsBuildBuild.callPackage nix-bundle-exe { };
# make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references.
# reset the ownership and permissions to make the extract result more normal.
make-tarball = drv: final.runCommand "tarball-${drv.name}"
{
nativeBuildInputs = with final.buildPackages; [ gnutar gzip ];
} ''
tar cfv - -C "${drv}" \
--owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \
| gzip -9 > $out
'';
bundle-win-exe = drv: final.callPackage ./nix/bundle-win-exe.nix { chain-maind = drv; };
} // (with final;
let
matrix = lib.cartesianProductOfSets {
network = [ "mainnet" "testnet" ];
pkgtype = [
"nix" # normal nix package
"bundle" # relocatable bundled package
"tarball" # tarball of the bundle, for distribution and checksum
};
defaultPackage = packages.chain-maind;
defaultApp = apps.chain-maind;
devShells = {
chain-maind = pkgs.mkShell {
buildInputs = with pkgs; [
go_1_22
rocksdb
nixfmt-rfc-style
];
};
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
);
in
};
devShell = devShells.chain-maind;
legacyPackages = pkgs;
}
))
// {
overlay =
final: prev:
{
chain-main-matrix = binaries;
bundle-exe = final.pkgsBuildBuild.callPackage nix-bundle-exe { };
# make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references.
# reset the ownership and permissions to make the extract result more normal.
make-tarball =
drv:
final.runCommand "tarball-${drv.name}"
{
nativeBuildInputs = with final.buildPackages; [
gnutar
gzip
];
}
''
tar cfv - -C "${drv}" \
--owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \
| gzip -9 > $out
'';
bundle-win-exe = drv: final.callPackage ./nix/bundle-win-exe.nix { chain-maind = drv; };
}
);
// (
with final;
let
matrix = lib.cartesianProductOfSets {
network = [
"mainnet"
"testnet"
];
pkgtype = [
"nix" # normal nix package
"bundle" # relocatable bundled package
"tarball" # tarball of the bundle, for distribution and checksum
];
};
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
);
in
{
chain-main-matrix = binaries;
}
);
};
}
Loading

0 comments on commit facfe27

Please sign in to comment.