From f031c6e452ad883424d65227a558bc4155f6039e Mon Sep 17 00:00:00 2001 From: seth Date: Fri, 24 May 2024 23:17:20 -0400 Subject: document lib --- lib/lib.nix | 50 ++++++++++++++++++++++++++++++++++++-------------- lib/nginx.nix | 6 ++++++ 2 files changed, 42 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/lib.nix b/lib/lib.nix index 5b7ee7d..aedb67a 100644 --- a/lib/lib.nix +++ b/lib/lib.nix @@ -4,8 +4,13 @@ inputs, ... }: let + # function -> function -> { } -> { } + # wrap the `args` applied to `builder` with the result of `apply` + # applied to those `args` wrapBuilderWith = apply: builder: args: builder (apply args); + # string -> function -> { } -> { } + # wrap the `args` for `builder` of type `type` with nice defaults wrapBuilder = type: wrapBuilderWith ({ modules ? [], @@ -21,26 +26,43 @@ specialArgs = specialArgs // {inherit inputs;}; }); - wrapNixOS = wrapBuilder "nixos"; - wrapDarwin = wrapBuilder "darwin"; + # function -> { } -> { } + # wrap the `args` to the nixos `builder` function with nice defaults + wrapNixOS = builder: args: wrapBuilder "nixos" builder args; + # function -> { } -> { } + # wrap the `args` to the darwin `builder` function with nice defaults + wrapDarwin = builder: args: wrapBuilder "darwin" builder args; - wrapUser = wrapBuilderWith ({ - modules ? [], - extraSpecialArgs ? {}, - ... - } @ args: - args - // { - modules = - modules - ++ lib.attrValues (self.homeManagerModules or {}); + # function -> { } -> { } + # wrap the `args` to the homeManager `builder` function with nice defaults + wrapUser = builder: args: + wrapBuilderWith ({ + modules ? [], + extraSpecialArgs ? {}, + ... + } @ args: + args + // { + modules = + modules + ++ lib.attrValues (self.homeManagerModules or {}); - extraSpecialArgs = extraSpecialArgs // {inherit inputs;}; - }); + extraSpecialArgs = extraSpecialArgs // {inherit inputs;}; + }) + builder + args; in { + # { } -> { } + # apply nice defaults to the `args` of `nixosSystem` nixosSystem = wrapNixOS inputs.nixpkgs.lib.nixosSystem; + # { } -> { } + # apply nice defaults to the `args` of (stable) `nixosSystem` nixosSystemStable = wrapNixOS inputs.nixpkgs-stable.lib.nixosSystem; + # { } -> { } + # apply nice defaults to the `args` of `darwinSystem` darwinSystem = wrapDarwin inputs.nix-darwin.lib.darwinSystem; + # { } -> { } + # apply nice defaults to the `args` of `homeManagerConfiguration` homeManagerConfiguration = wrapUser inputs.home-manager.lib.homeManagerConfiguration; nginx = import ./nginx.nix lib; diff --git a/lib/nginx.nix b/lib/nginx.nix index bcf3332..0564dba 100644 --- a/lib/nginx.nix +++ b/lib/nginx.nix @@ -1,4 +1,7 @@ lib: { + # string -> int -> { } + # create an nginx virtualHost submodule proxying local port + # `port` to `endpoint` mkProxy = endpoint: port: { "${endpoint}" = { proxyPass = "http://localhost:${toString port}"; @@ -6,6 +9,9 @@ lib: { }; }; + # string -> { } -> { } + # transform the names of an attribute set of nginx virtualHosts + # into a full subdomain toVHosts = domain: lib.mapAttrs' ( name: lib.nameValuePair "${name}.${domain}" -- cgit v1.2.3