Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Created April 1, 2025 19:40
Show Gist options
  • Save danidiaz/efd1aa2c934972ecc099eaca75c8ec88 to your computer and use it in GitHub Desktop.
Save danidiaz/efd1aa2c934972ecc099eaca75c8ec88 to your computer and use it in GitHub Desktop.
Basic example of Nix modules
{
description = "A very basic example of modules";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
outputs = { self, nixpkgs }: {
# nix eval .#.lib.boo.config
lib = {
boo = nixpkgs.lib.evalModules {
modules = [
({lib, ...} : {
options =
{
a = lib.mkOption { type = lib.types.str; };
b = lib.mkOption { type = lib.types.str; };
c = lib.mkOption { type = lib.types.str; };
};
})
({lib, ...} : {
config = { a = "aaa"; };
})
({lib, ...} : {
# https://nix.dev/tutorials/module-system/index.html
b = "bbb";
})
({
# https://nix.dev/tutorials/module-system/index.html
c = "ccc";
})
];
};
# nix eval .#.lib.ty
ty = nixpkgs.lib.attrNames self.lib.boo.type;
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment