{ lib, inputs, system, ... }: with lib; rec { my = import ./my.nix { inherit lib inputs system; }; dns = import ./dns.nix { inherit lib inputs system; }; packages = import ./packages.nix { inherit lib inputs system; }; isEven = number: assert (builtins.isInt number) || (builtins.isFloat number); builtins.div number 2 == 0; isOdd = number: !isEven number; pow = base: exponent: assert (builtins.isInt base) && (builtins.isInt exponent); assert exponent > 0; builtins.foldl' (x: _: x * base) 1 (builtins.genList (_: _) exponent); mkTcpMem = min: ini: max: assert min <= ini && ini <= max; concatMapStrings (x: toString x + " ") ( map (pow 2) [ min ini max ] ); # Load all files from directory (partially recursively). # # Usage: Assuming other Nix files are present in a directory: # ``` # { ... }: { # imports = attrValue (modulesIn ./.); # # services.foobar.enable = true; # } # ``` # modulesIn = dir: pipe dir [ builtins.readDir (mapAttrsToList ( name: type: let modulePath = dir + "/${name}"; in if type == "regular" && hasSuffix ".nix" name && name != "default.nix" then [ (nameValuePair (removeSuffix ".nix" name) modulePath) ] else if type == "directory" && pathExists (modulePath + "/default.nix") then [ (nameValuePair name modulePath) ] else [ ] )) concatLists listToAttrs ]; # Override a module using another Nixpkgs source tree. # # Usage: Assuming we want to override "services.foobar.enable": # ``` # { config, lib, ... }: # (lib.modulesFromRef # "services/security/foobar.nix" # "azahi:fix-foobar" # Can be copied form a PR. # "sha256-AAA..." # ) // { # config = { # serices.foobar.enable = true; # }; # } # ``` # or # ``` # nixosConfigurations.machine = nixosSystem { # modules = [ # (_: modulesFromRef "services/security/foobar.nix" "azahi:foobar-fix" "sha256-AAA...") # ]; # }; # ``` # moduleFromRef = module: ref: sha256: { disabledModules = [ module ]; imports = [ ( let src = builtins.fetchTarball { url = let cons = splitString ":" ref; owner = head cons; branch = last cons; in "https://github.com/${owner}/nixpkgs/archive/refs/heads/${branch}.tar.gz"; inherit sha256; }; in "${src}/nixos/modules/${module}" ) ]; }; }