Skip to content

Commit 19a5801

Browse files
Update nix-std to get toTOML that omits nulls (#234)
* update nix-std, add some comments * format
1 parent dc09dd9 commit 19a5801

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

flake.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
./modules/apps.nix
3232
# Sets the overlays.default flake output
3333
./modules/overlay.nix
34+
# Sets the flake.nixosModules flake output
35+
./modules/nixosModules.nix
3436
];
3537
};
3638

lib/default.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,18 @@ nix-std: {
140140
}
141141
// buildGoModuleArgs);
142142
in {
143+
# A helper for building rust cosmwasm smart contracts. Does some best practices like using binaryren wasm-opt
144+
# to optimize the bytecode, and runs cosmwasm-check to validate.
143145
inherit buildCosmwasmContract;
146+
147+
# A wrapper around [buildGoModule](https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/go/module.nix)
148+
# that is specialized to packaging cosmos-sdk based go projects
149+
#
150+
# for more information see: https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/go.section.md
144151
mkCosmosGoApp = buildApp;
145152

153+
# A helper function for patching cosmos-sdk binaries that use wasmd, so that the binary artifact references
154+
# a nix store path, and not a local relative path
146155
wasmdPreFixupPhase = libwasmvm: binName:
147156
if pkgs.stdenv.hostPlatform.isLinux
148157
then ''
@@ -156,6 +165,8 @@ in {
156165
''
157166
else null;
158167

168+
# A helper that produces an executable for generating a gomod2nix.toml file (which
169+
# captures a go module's dependencies and their hash in a toml file)
159170
mkGenerator = name: srcDir:
160171
pkgs.writeShellApplication {
161172
inherit name;
@@ -168,6 +179,7 @@ in {
168179
gomod2nix --outdir "$CURDIR"
169180
'';
170181
};
182+
171183
# `hermesModuleConfigToml { modules }).config.hermes.toml`
172184
# will be a string to put into [config.toml](https://hermes.informal.systems/documentation/configuration/configure-hermes.html)
173185
hermesModuleConfigToml = {modules}:

modules/nixosModules.nix

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
inputs,
3-
hermes,
3+
pkgs,
44
...
5-
}: let
6-
std = inputs.nix-std;
7-
in {
5+
}: {
86
flake.nixosModules = {
9-
hermes = import ../../nixosModules/hermes/default.nix {inherit nix-std hermes;};
7+
hermes = import ../../nixosModules/hermes/default.nix {
8+
inherit (inputs) nix-std;
9+
inherit (pkgs) hermes;
10+
};
1011
};
1112
}

nixosModules/hermes/base.nix

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# This module might be slightly confusing, since nixos modules are isntantiated via a "fixed point"
2+
# which is effectively a loop that accumulates attributes.
3+
#
4+
# because of this "fixed point" and lazyness we are able to set the "options"
5+
# attribute, which declares the schema for the module and is required at the
6+
# beginning of the loop, and the "config" attribute which is a serialization of
7+
# the accumulated configuration into a toml file and intuitively happens at the
8+
# end of the loop
9+
#
10+
# TL;DR:
11+
# - 'options' represents the schema for the hermes configuration module
12+
# - 'config.toml' represents the a final serialization of the actual configuration into a toml file
13+
# - for more information on nixos modules see https://nix.dev/tutorials/module-system/module-system.html
114
{
215
lib,
316
nix-std,
@@ -9,10 +22,6 @@ with lib; {
922
toml = mkOption {type = types.unique {message = "only one toml output";} types.str;};
1023
};
1124
config = {
12-
toml = let
13-
# remove `null` from toml render
14-
sanitizedCfg = filterAttrsRecursive (_: v: v != null) cfg.config;
15-
in
16-
nix-std.lib.serde.toTOML sanitizedCfg;
25+
toml = nix-std.lib.serde.toTOML cfg.config;
1726
};
1827
}

0 commit comments

Comments
 (0)