diff options
author | azahi <azat@bahawi.net> | 2025-02-17 02:21:56 +0300 |
---|---|---|
committer | azahi <azat@bahawi.net> | 2025-02-17 02:21:56 +0300 |
commit | 59180328cda59817d71cd58c8f48ead047375064 (patch) | |
tree | 2cdd7d1bfa309839ef624c19daf283f510aacf69 /lib | |
parent | 2025-02-05 (diff) |
2025-02-17
Diffstat (limited to 'lib')
-rw-r--r-- | lib/default.nix | 54 | ||||
-rw-r--r-- | lib/dns.nix | 3 | ||||
-rw-r--r-- | lib/my.nix | 103 |
3 files changed, 78 insertions, 82 deletions
diff --git a/lib/default.nix b/lib/default.nix index e06b7ec..fbb6086 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -4,7 +4,7 @@ system, ... }: -rec { +{ my = import ./my.nix { inherit lib inputs system; }; dns = import ./dns.nix { inherit lib inputs system; }; @@ -18,7 +18,7 @@ rec { assert (builtins.isInt number) || (builtins.isFloat number); builtins.div number 2 == 0; - isOdd = number: !isEven number; + isOdd = number: !lib.isEven number; pow = base: exponent: @@ -29,20 +29,21 @@ rec { mkTcpMem = min: ini: max: assert min <= ini && ini <= max; - lib.concatMapStrings (x: toString x + " ") ( - map (pow 2) [ - min - ini - max - ] - ); + [ + min + ini + max + ] + |> map (lib.pow 2) + |> map toString + |> lib.concatStringsSep " "; # Load all files from directory (partially recursively). # # Usage: Assuming other Nix files are present in a directory: # ``` # { ... }: { - # imports = attrValue (modulesIn ./.); + # imports = modulesIn ./. |> attrValues; # # services.foobar.enable = true; # } @@ -50,23 +51,22 @@ rec { # modulesIn = dir: - lib.pipe dir [ - builtins.readDir - (lib.mapAttrsToList ( - name: type: - let - modulePath = dir + "/${name}"; - in - if type == "regular" && lib.hasSuffix ".nix" name && name != "default.nix" then - [ (lib.nameValuePair (lib.removeSuffix ".nix" name) modulePath) ] - else if type == "directory" && lib.pathExists (modulePath + "/default.nix") then - [ (lib.nameValuePair name modulePath) ] - else - [ ] - )) - lib.concatLists - lib.listToAttrs - ]; + dir + |> builtins.readDir + |> (lib.mapAttrsToList ( + name: type: + let + modulePath = dir + "/${name}"; + in + if type == "regular" && lib.hasSuffix ".nix" name && name != "default.nix" then + [ (lib.nameValuePair (lib.removeSuffix ".nix" name) modulePath) ] + else if type == "directory" && lib.pathExists (modulePath + "/default.nix") then + [ (lib.nameValuePair name modulePath) ] + else + [ ] + )) + |> lib.concatLists + |> lib.listToAttrs; # Override a module using another Nixpkgs source tree. # diff --git a/lib/dns.nix b/lib/dns.nix index c0e4641..66c3e51 100644 --- a/lib/dns.nix +++ b/lib/dns.nix @@ -1,6 +1,5 @@ { lib, inputs, ... }: -with lib; -recursiveUpdate inputs.dns.lib { +lib.recursiveUpdate inputs.dns.lib { mkDoT = { ips, tls }: map (ip: "${ip}#${tls}") ips; const = { diff --git a/lib/my.nix b/lib/my.nix index 20f01be..e900519 100644 --- a/lib/my.nix +++ b/lib/my.nix @@ -1,66 +1,63 @@ { lib, ... }: -with lib; -(evalModules { +(lib.evalModules { modules = [ { - options.configurations = mkOption { + options.configurations = lib.mkOption { description = "My configurations."; - type = - with types; - attrsOf ( - submodule ( - { name, ... }: - { - freeformType = attrs; - options = - let - mkConfigurationTypeOption = - type: - mkOption { - description = "Whether the machine's functional type is a ${type} one."; - type = bool; - default = false; - }; - in - { - hostname = mkOption { - description = "The machine's hostname."; - type = str; - default = name; - readOnly = true; - }; - - stateVersion = mkOption { - description = "Machine's Nixpkgs state version."; - type = str; - default = trivial.release; + type = lib.types.attrsOf ( + lib.types.submodule ( + { name, ... }: + { + freeformType = lib.types.attrs; + options = + let + mkConfigurationTypeOption = + type: + lib.mkOption { + description = "Whether the machine's functional type is a ${type} one."; + type = lib.types.bool; + default = false; }; + in + { + hostname = lib.mkOption { + description = "The machine's hostname."; + type = lib.types.str; + default = name; + readOnly = true; + }; - deviceIcon = mkOption { - description = "Device icon to be used with nix-topology."; - type = nullOr (either path str); - default = null; - }; + stateVersion = lib.mkOption { + description = "Machine's Nixpkgs state version."; + type = lib.types.str; + default = lib.trivial.release; + }; - system = mkOption { - description = "The machine's system."; - type = nullOr (enum platforms.all); - default = null; - }; + deviceIcon = lib.mkOption { + description = "Device icon to be used with nix-topology."; + type = with lib.types; nullOr (either path str); + default = null; + }; - isHeadless = mkConfigurationTypeOption "headless"; - isHeadful = mkConfigurationTypeOption "headful"; - isOther = mkConfigurationTypeOption "other"; + system = lib.mkOption { + description = "The machine's system."; + type = with lib.types; nullOr (enum lib.platforms.all); + default = null; }; - } - ) - ); + + isHeadless = mkConfigurationTypeOption "headless"; + isHeadful = mkConfigurationTypeOption "headful"; + isOther = mkConfigurationTypeOption "other"; + }; + } + ) + ); default = { }; }; config = { - _module.freeformType = types.attrs; + _module.freeformType = lib.types.attrs; fullname = "Firstname Lastname"; username = "azahi"; @@ -70,7 +67,7 @@ with lib; gondor = "gondor.net"; shire = "shire.net"; }; - email = "frodo@${my.domain.gondor}"; + email = "frodo@${lib.my.domain.gondor}"; pgp = { key = "@PGP_KEY@"; fingerprint = "@PGP_FINGERPRINT@"; @@ -78,7 +75,7 @@ with lib; }; ssh = rec { type = "ed25519"; - id = my.email; + id = lib.my.email; key = "ssh-${type} @PUBLIC_KEY@ ${id}"; }; hashedPassword = "@HASHED_PASSWORD@"; @@ -105,7 +102,7 @@ with lib; ipv6.address = "fd69::0:1"; publicKey = "@PUBLIC_KEY@"; }; - domains = with my.domain; [ + domains = with lib.my.domain; [ "alertmanager.${shire}" "frodo.${rohan}" "frodo.${gondor}" @@ -174,7 +171,7 @@ with lib; ipv6.address = "fd69::1:2"; publicKey = "@PUBLIC_KEY@"; }; - domains = with my.domain; [ + domains = with lib.my.domain; [ "flood.${shire}" "jackett.${shire}" "lidarr.${shire}" |