+lib +portshelper
This commit is contained in:
@@ -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 |
|
||||
|
Reference in New Issue
Block a user