Nix flake library for my repositories
  • Nix 92.4%
  • Just 7.2%
  • Rust 0.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Clank 240dfd02aa
All checks were successful
ci/woodpecker/cron/flake-check Pipeline was successful
chore(deps): update dependency ipetkov/crane to v0.24.0 (#6)
Co-authored-by: Renovate <renovate@martials.no>
Reviewed-on: #6
2026-08-21 19:56:43 +00:00
lib fix: eachSupportedSystem not outputting correctly 2026-08-08 14:45:00 +02:00
pkgs feat(pkgs): Init openapi-to-rust 2026-08-20 18:58:12 +00:00
test fix: eachSupportedSystem not outputting correctly 2026-08-08 14:45:00 +02:00
.gitignore chore: Add target to gitignore 2026-07-27 18:04:19 +02:00
AGENTS.md Remove my key on lib output 2026-08-08 13:57:33 +02:00
CODEOWNERS Migration: codeowners (#4) 2026-07-29 18:15:20 +00:00
flake.lock chore(deps): update dependency ipetkov/crane to v0.24.0 (#6) 2026-08-21 19:56:43 +00:00
flake.nix chore(deps): update dependency ipetkov/crane to v0.24.0 (#6) 2026-08-21 19:56:43 +00:00
justfile Add release recipe 2026-08-20 19:07:34 +00:00
LICENSE Initial commit 2026-07-25 12:28:26 +00:00
README.md fix: eachSupportedSystem not outputting correctly 2026-08-08 14:45:00 +02:00
renovate.json chore(renovate): Use flake preset 2026-08-08 13:58:07 +02:00
treefmt.nix Initial commit 2026-07-25 15:46:08 +02:00

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
      }
    );
}