Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: nixpkgs-fmt is deprecated (backport #1111) #1113

Merged
merged 6 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,9 @@ jobs:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'pull_request'
steps:
<<<<<<< HEAD
- uses: actions/checkout@v4
=======
- uses: actions/checkout@v4
with:
persist-credentials: false
>>>>>>> c23a527 (Problem: persist-credentials might leak github token unintentionally (#1090))
- id: changed-files
uses: tj-actions/changed-files@v35
with:
Expand All @@ -435,7 +431,7 @@ jobs:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: update gomod2nix
run: nix run .#update-gomod2nix
run: nix develop -c gomod2nix
if: steps.changed-files.outputs.any_changed == 'true'
- name: check working directory is clean
id: changes
Expand Down
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
67 changes: 31 additions & 36 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
{ 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,
coverage ? false, # https://tip.golang.org/doc/go1.20#cover
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 @@ -39,7 +36,6 @@ in
buildGoApplication rec {
pname = "chain-maind";
version = "4.2.10";
go = buildPackages.go_1_20;
src = lib.cleanSourceWith {
name = "src";
src = lib.sourceByRegex ./. src_regexes;
Expand All @@ -50,18 +46,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 @@ -72,15 +76,6 @@ buildGoApplication rec {
postFixup = lib.optionalString stdenv.isDarwin ''
${stdenv.cc.targetPrefix}install_name_tool -change "@rpath/librocksdb.8.dylib" "${rocksdb}/lib/librocksdb.dylib" $out/bin/chain-maind
'';
passthru = {
# update script use the same golang version as the project
updateScript =
let helper = gomod2nix.override { inherit go; };
in
writeShellScript "${pname}-updater" ''
exec ${helper}/bin/gomod2nix
'';
};

doCheck = false;
meta = with lib; {
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.

201 changes: 111 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,127 @@
};
};

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 = { };
(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}";
};
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
};
defaultPackage = packages.chain-maind;
defaultApp = apps.chain-maind;
devShells = {
chain-maind = pkgs.mkShell {
buildInputs =
with pkgs;
[
defaultPackage.go
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
];
nixfmt-rfc-style
]
++ [ pkgs.gomod2nix ];
};
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
Loading