Skip to content

Commit

Permalink
Switch lib to an overlay (#207)
Browse files Browse the repository at this point in the history
* switch lib to an overlay

* update README.md

* cleanup README

* format
  • Loading branch information
JonathanLorimer authored Jan 8, 2024
1 parent 51ac2f2 commit 17aab44
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,32 @@ latest development environment you should run:
nix develop github:informalsystems/cosmos.nix#cosmos-shell --refresh
```

## Library
## Overlays

There are a few nix utilities provided as a nix library. You can use these in your own flake like so:
There are a few nix utilities provided as a nix library. There is also an
overlay for all the cosmos packages exported by this flake, so you can fold
them into your nixpkgs package set.

```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
cosmos-nix.url = "github:informalsystems/cosmos.nix";
};
outputs = { cosmos-nix }: {
cosmosLib = cosmos-nix.lib "x86_64-linux";
outputs = { cosmos-nix, nixpkgs }: {
let pkgs = import nixpkgs {
system = "x86_64-linux"; # Or whatever system you are on
overlays = [
cosmos-nix.overlays.cosmosNixLib # Provides just the nix utility lib
cosmos-nix.overlays.cosmosNix # Provides all the cosmos packages provided by cosmos.nix
cosmos-nix.overlay # The default overlay gives you everything in the previous two combined
];
}
in ...
};
}
```

> NOTE: you need to pass `cosmosLib` a "system" argument because it uses system specific pkgs internally. It is
> slightly unfortunate that it isn't pure nix (without derivations), and needs to be `system` aware.
## Development

#### Formatting
Expand Down
16 changes: 1 addition & 15 deletions modules/lib.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# This module provides the lib argument to all other modules as 'cosmosLib'.
# This provides utility functions for packaging cosmos sdk and cosmwasm packages
{
withSystem,
inputs,
...
}: let
{inputs, ...}: let
lib = import ../lib;
std = inputs.nix-std;
in {
Expand All @@ -19,14 +15,4 @@ in {
inherit (self'.packages) cosmwasm-check;
};
};
flake.lib = system:
withSystem system ({
pkgs,
self',
...
}:
lib std {
inherit pkgs;
inherit (self'.packages) cosmwasm-check;
});
}
33 changes: 31 additions & 2 deletions modules/overlay.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
# Provides an overlay for other flakes to consume and get all the cosmos packages in their pkgs
# https://flake.parts/overlays.html?highlight=overlay#defining-an-overlay
{withSystem, ...}: {
flake.overlays.default = final: prev:
{
withSystem,
inputs,
self,
...
}: {
# Overlay with everything
flake.overlays.default = with self.overlays;
inputs.nixpkgs.lib.fixedPoints.composeExtensions
cosmosNix
cosmosNixLib;

# Overlay with all the cosmos.nix cosmos packages
flake.overlays.cosmosNixPackages = final: prev:
withSystem prev.stdenv.hostPlatform.system ({self', ...}: self'.packages);

# Overlay with the cosmos.nix nix lib (comes with a bunch of utility functions for packaging cosmos packages)
flake.overlays.cosmosNixLib = final: prev:
withSystem prev.stdenv.hostPlatform.system ({
self',
pkgs,
...
}: {
cosmosLib = let
lib = import ../lib;
std = inputs.nix-std;
in
lib std {
inherit pkgs;
inherit (self'.packages) cosmwasm-check;
};
});
}

0 comments on commit 17aab44

Please sign in to comment.