+lib +portshelper

This commit is contained in:
m3tam3re
2025-10-04 17:03:46 +02:00
parent 1ce83403bc
commit 4fa3a8b551
6 changed files with 443 additions and 0 deletions

View File

@@ -125,6 +125,56 @@ When working on your system configuration:
}
```
### 6. Use Library Functions
The repository includes helper functions for common configuration tasks.
#### Port Management Example
```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
m3ta-nixpkgs.url = "git+https://code.m3ta.dev/m3tam3re/nixpkgs";
};
outputs = {nixpkgs, m3ta-nixpkgs, ...}: {
nixosConfigurations.laptop = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = {inherit inputs; system = "x86_64-linux";};
modules = [
({inputs, system, config, ...}: let
# Import the library
m3taLib = inputs.m3ta-nixpkgs.lib.${system};
# Define all your ports centrally
myPorts = {
ports = {
nginx = 80;
grafana = 3000;
prometheus = 9090;
};
hostPorts = {
laptop = {nginx = 8080;}; # Override on laptop
};
};
# Create port helpers
ports = m3taLib.ports.mkPortHelpers myPorts;
hostname = config.networking.hostName;
in {
# Use in configuration
services.nginx.defaultHTTPListenPort = ports.getPort "nginx" hostname;
services.grafana.settings.server.http_port = ports.getPort "grafana" hostname;
})
];
};
};
}
```
See `examples/ports-example.nix` for more examples and `lib/README.md` for full documentation.
## Available Packages
| Package | Description | Command |