From 5fe2777acda756ae69f59e084afd9f6d35a535da Mon Sep 17 00:00:00 2001 From: seth Date: Fri, 5 Jul 2024 07:30:49 -0400 Subject: tree-wide: document most things --- lib/README.md | 13 ++++++++++ lib/builders.nix | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/lib.nix | 76 ++++++++------------------------------------------------ 3 files changed, 98 insertions(+), 66 deletions(-) create mode 100644 lib/README.md create mode 100644 lib/builders.nix (limited to 'lib') diff --git a/lib/README.md b/lib/README.md new file mode 100644 index 0000000..bde1e94 --- /dev/null +++ b/lib/README.md @@ -0,0 +1,13 @@ +# ./lib/ + +## lib.nix + +Top-level declaration of my functions + +## builders.nix + +Wrappers around configurations builders such as `nixosSystem` and `darwinSystem` + +## nginx.nix + +Small helpers to avoid boilerplate in the `services.nginx` module diff --git a/lib/builders.nix b/lib/builders.nix new file mode 100644 index 0000000..6669c2d --- /dev/null +++ b/lib/builders.nix @@ -0,0 +1,75 @@ +{ + lib, + inputs, + self, +}: +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 ? [ ], + specialArgs ? { }, + ... + }@args: + args + // { + modules = modules ++ lib.attrValues (self."${type}Modules" or { }); + + specialArgs = specialArgs // { + inherit inputs; + }; + } + ); + + # 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; + + # 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; + }; + } + ) 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; +} diff --git a/lib/lib.nix b/lib/lib.nix index 1dea9be..54d6712 100644 --- a/lib/lib.nix +++ b/lib/lib.nix @@ -1,76 +1,20 @@ { lib, - self, inputs, + self, }: 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 ? [ ], - specialArgs ? { }, - ... - }@args: - args - // { - modules = modules ++ lib.attrValues (self."${type}Modules" or { }); - - specialArgs = specialArgs // { - inherit inputs; - }; - } - ); - - # 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; - - # 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; - }; - } - ) builder args; + builders = import ./builders.nix { inherit lib inputs self; }; 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; + inherit builders; + + inherit (builders) + nixosSystem + nixosSystemStable + darwinSystem + homeManagerConfiguration + ; nginx = import ./nginx.nix lib; } -- cgit v1.2.3