- Nix 92.4%
- Just 7.2%
- Rust 0.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
All checks were successful
ci/woodpecker/cron/flake-check Pipeline was successful
Co-authored-by: Renovate <renovate@martials.no> Reviewed-on: #6 |
||
| lib | ||
| pkgs | ||
| test | ||
| .gitignore | ||
| AGENTS.md | ||
| CODEOWNERS | ||
| flake.lock | ||
| flake.nix | ||
| justfile | ||
| LICENSE | ||
| README.md | ||
| renovate.json | ||
| treefmt.nix | ||
my-nix-lib
Reusable Nix library functions, exposed through the flake's lib output.
Modules
All attributes are exposed under the flake's lib output and consumed as my.lib.*.
my.lib.domain
Homelab domain configuration — forge URL, auth, container registry, cargo registry.
my.lib.domain.registries.crate
# => { indexUrl = "https://code.martials.no/..."; dl = "..."; registryPrefix = "sparse+"; }
my.lib.defaults
Package defaults, currently just the licence:
my.lib.defaults.licence
# => lib.licenses.mit
my.lib.system
Systems supported by the flake:
my.lib.system.supportedSystems
Use eachSupportedSystem to create flake outputs for every supported system. The
function transposes the result, so consumers do not need a separate transpose step:
my.lib.system.eachSupportedSystem (system: {
packages.default = ...;
devShells.default = ...;
checks.example = ...;
})
# => { packages.${system} = ...; devShells.${system} = ...; checks.${system} = ...; }
my.lib.<system>.rust
Rust build helpers using crane + fenix.
| Function | Returns | Description |
|---|---|---|
mkCraneLib { } |
crane lib | Crane library with the configured toolchain |
mkDevShell { } |
dev shell | Shell ready for Rust development |
mkRustPlatform { } |
rust platform | craneLib.appendCrateRegistries with configured registries |
mkCraneLib
Returns a crane library with the configured toolchain.
| Arg | Default | Description |
|---|---|---|
channel |
"stable" |
Rust toolchain channel |
tooltip |
"minimalToolchain" |
fenix toolchain attribute |
mkDevShell
Returns a dev shell with the configured toolchain.
Containing the packages rust-analyzer, cargo, rustfmt, clippy.
shellHook exports LD_LIBRARY_PATH to the shell.
| Arg | Default | Description |
|---|---|---|
channel |
"stable" |
Rust toolchain channel |
tooltip |
"minimalToolchain" |
fenix toolchain attribute |
packages |
[] |
Extra packages to include in the shell |
shellHook |
"" |
Shell hook script |
mkRustPlatform
| Arg | Default | Description |
|---|---|---|
channel |
"stable" |
Rust toolchain channel |
tooltip |
"minimalToolchain" |
fenix toolchain attribute |
registries |
[] |
Extra crate registries |
Automatically prepends my.lib.domain.registries.crate (with {crate}/{version}/download suffix appended) to the registries list, so the private crate registry is configured by default.
Minimal usage:
let
craneLib = my.lib.${system}.rust.mkCraneLib { };
rustPlatform = my.lib.${system}.rust.mkRustPlatform { };
in {
packages.default = rustPlatform.buildPackage {
src = lib.cleanSource ./.;
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ openssl ];
};
devShells.default = my.lib.${system}.rust.mkDevShell {
packages = with pkgs; [ pkg-config openssl ];
};
}
With extra registries:
my.lib.${system}.rust.mkRustPlatform {
registries = [
{ indexUrl = "https://..." ; dl = "https://..." ; registryPrefix = "sparse+"; }
];
}
Usage
Add my-nix-lib as a flake input and access its library output directly:
# flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
my-nix-lib.url = "github:martinals/my-nix-lib";
fenix.url = "github:nix-community/fenix";
crane.url = "github:ipetkov/crane";
};
outputs = { self, my-nix-lib, ... }:
let
systems = my-nix-lib.lib.system.supportedSystems;
in
builtins.genAttrs systems (system:
let
my = my-nix-lib;
in {
# my.lib.domain / my.lib.defaults / my.lib.${system}.rust
}
);
}