Skip to content

Commit

Permalink
feat(nix): add nix run .#pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cor committed Jun 7, 2024
1 parent b5188ef commit fd40223
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 95 deletions.
2 changes: 1 addition & 1 deletion app/app.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
packages = {
app = unstablePkgs.buildNpmPackage {
npmDepsHash = "sha256-JJH1vqXzv7IYw2SEVJFqHydvlGXdtPvfb/PazNsZqv4=";
npmDepsHash = "sha256-LbggeFObMO400/fl4armnF8ggA4AVBojdqCzVxVOS3Q=";
src = ./.;
sourceRoot = "app";
npmFlags = [ "--legacy-peer-deps" ];
Expand Down
70 changes: 36 additions & 34 deletions app/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
<script lang="ts">
import * as Card from "$lib/components/ui/card/index.ts"
import { derived, type Readable } from 'svelte/store';
import { rawToBech32, rawToHex } from '$lib/utilities/address';
import { cosmosBalancesQuery, evmBalancesQuery } from '$lib/queries/balance'
import { chainsQuery } from '$lib/queries/chains'
import { sepoliaStore } from "$lib/wallet/evm/config.ts"
import { cosmosStore } from "$lib/wallet/cosmos"
import { truncate } from '$lib/utilities/format';
let evmBalances: null | ReturnType<typeof evmBalancesQuery>;
$: if($sepoliaStore.address) evmBalances = evmBalancesQuery({
chainId: '11155111',
address: $sepoliaStore.address,
tokenSpecification: 'erc20',
import * as Card from "$lib/components/ui/card/index.ts"
import { derived, type Readable } from "svelte/store"
import { rawToBech32, rawToHex } from "$lib/utilities/address"
import { cosmosBalancesQuery, evmBalancesQuery } from "$lib/queries/balance"
import { chainsQuery } from "$lib/queries/chains"
import { sepoliaStore } from "$lib/wallet/evm/config.ts"
import { cosmosStore } from "$lib/wallet/cosmos"
import { truncate } from "$lib/utilities/format"
let evmBalances: null | ReturnType<typeof evmBalancesQuery>
$: if ($sepoliaStore.address)
evmBalances = evmBalancesQuery({
chainId: "11155111",
address: $sepoliaStore.address,
tokenSpecification: "erc20"
})
let chains = chainsQuery();
let cosmosBalances: null | ReturnType<typeof cosmosBalancesQuery>;
let cosmosChains = derived(chains, ($chains) => {
if (!$chains?.isSuccess) {
return null
}
return $chains.data.v0_chains.filter((c: typeof $chains.data.v0_chains[number]) => c.rpc_type === "cosmos" && c.addr_prefix !== null && c.rpcs && c.chain_id)
});
$: if ($cosmosChains && $cosmosStore.rawAddress?.length && $cosmosStore.rawAddress?.length > 0) {
console.log($cosmosChains);
cosmosBalances = cosmosBalancesQuery({
// https://stackoverflow.com/questions/77206461/type-guard-function-is-not-narrowing-the-type-in-array-filter
//@ts-ignore
chains: $cosmosChains,
address: $cosmosStore.rawAddress
})
let chains = chainsQuery()
let cosmosBalances: null | ReturnType<typeof cosmosBalancesQuery>
let cosmosChains = derived(chains, $chains => {
if (!$chains?.isSuccess) {
return null
}
return $chains.data.v0_chains.filter(
(c: (typeof $chains.data.v0_chains)[number]) =>
c.rpc_type === "cosmos" && c.addr_prefix !== null && c.rpcs && c.chain_id
)
})
$: if ($cosmosChains && $cosmosStore.rawAddress?.length && $cosmosStore.rawAddress?.length > 0) {
console.log($cosmosChains)
cosmosBalances = cosmosBalancesQuery({
// https://stackoverflow.com/questions/77206461/type-guard-function-is-not-narrowing-the-type-in-array-filter
//@ts-ignore
chains: $cosmosChains,
address: $cosmosStore.rawAddress
})
}
</script>

<main class="flex flex-col items-center w-full p-4 mt-16 gap-6">
Expand Down
37 changes: 37 additions & 0 deletions devShell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{ ... }: {
perSystem = { biome, pkgs, unstablePkgs, lib, ensureAtRepositoryRoot, ... }:
let
pkgsDeps = with pkgs; [ pkg-config biome ];
nodeDeps = with unstablePkgs; [ vips nodePackages_latest.nodejs ];
combinedDeps = pkgsDeps ++ nodeDeps;
in
{
apps = {
pre-commit = {
type = "app";
program = pkgs.writeShellApplication {
name = "pre-commit";
runtimeInputs = combinedDeps;
text = ''
${ensureAtRepositoryRoot}
echo "Applying nix fmt"
nix fmt
echo "Applying biome fmt"
${lib.getExe biome} format . \
--log-level="info" \
--log-kind="pretty" \
--error-on-warnings \
--diagnostic-level="info" \
--write
echo "Checking spelling"
nix build .\#checks.${pkgs.system}.spellcheck -L
'';
};
};
};
};
}
61 changes: 1 addition & 60 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
systems =
[ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
imports = [
./devShell.nix
./uniond/uniond.nix
./galoisd/galoisd.nix
./unionvisor/unionvisor.nix
Expand Down Expand Up @@ -476,66 +477,6 @@
'';
});
};

devShells.default = pkgs.mkShell {
name = "union-devShell";
buildInputs = [ rust.toolchains.dev ] ++ (with pkgs; [
cargo-fuzz
cargo-llvm-cov
bacon
cargo-nextest
jq
go-ethereum
marksman
nil
nixfmt
nix-tree
openssl
pkg-config
protobuf
httpie
self'.packages.tdc
self'.packages.voy-send-msg
yq
]) ++ (with unstablePkgs; [
bun # for running TypeScript files on the fly
postgresql
emmet-language-server
nodePackages.graphqurl
nodePackages_latest.nodejs
nodePackages_latest.svelte-language-server
nodePackages_latest."@astrojs/language-server"
nodePackages_latest."@tailwindcss/language-server"
nodePackages_latest.typescript-language-server
nodePackages_latest.vscode-langservers-extracted
])
++ (with goPkgs; [
go
gopls
go-tools
gotools
]) ++ (if pkgs.stdenv.isLinux then [
pkgs.solc
pkgs.foundry-bin
goPkgs.sqlx-cli
self'.packages.hasura-cli
] else [ ]);
nativeBuildInputs = [ config.treefmt.build.wrapper ]
++ lib.attrsets.attrValues config.treefmt.build.programs;

GOPRIVATE = "github.com/unionlabs/*";
PUPPETEER_SKIP_DOWNLOAD = 1; # avoid npm install downloading chromium
NODE_OPTIONS = "--no-warnings"; # avoid useless warnings from nodejs
ASTRO_TELEMETRY_DISABLED = 1;

ICS23_TEST_SUITE_DATA_DIR = "${inputs.ics23}/testdata";
ETHEREUM_CONSENSUS_SPECS_DIR = "${inputs.ethereum-consensus-specs}";

RUST_SRC_PATH = "${rust.toolchains.dev}/lib/rustlib/src/rust/library";

SQLX_OFFLINE = true;
};

treefmt = {
package = pkgs.treefmt;
projectRootFile = "flake.nix";
Expand Down

0 comments on commit fd40223

Please sign in to comment.