Add global lib relativePath

This commit is contained in:
SebastianStork 2025-11-07 21:03:19 +01:00
parent 39bd59c8ee
commit 56f11d4ade
Signed by: SebastianStork
SSH key fingerprint: SHA256:tRrGdjYOwgHxpSc/wTOZQZEjxcb15P0tyXRsbAfd+2Q
4 changed files with 19 additions and 9 deletions

View file

@ -1,4 +1,7 @@
{ self, inputs, ... }: { self, inputs, ... }:
{ {
flake.lib = import "${self}/lib" inputs.nixpkgs.lib; flake.lib = import "${self}/lib" {
inherit (inputs.nixpkgs) lib;
inherit self;
};
} }

View file

@ -1,4 +1,8 @@
lib: { {
lib,
self,
}:
{
isTailscaleDomain = domain: domain |> lib.hasSuffix ".ts.net"; isTailscaleDomain = domain: domain |> lib.hasSuffix ".ts.net";
subdomainOf = domain: domain |> lib.splitString "." |> lib.head; subdomainOf = domain: domain |> lib.splitString "." |> lib.head;
@ -15,4 +19,6 @@ lib: {
mkUnprotectedMessage = mkUnprotectedMessage =
name: "${name} should only be exposed on private networks; access control isn't yet configured"; name: "${name} should only be exposed on private networks; access control isn't yet configured";
relativePath = path: path |> toString |> lib.removePrefix "${self}/";
} }

View file

@ -2,6 +2,7 @@
config, config,
self, self,
lib, lib,
lib',
... ...
}: }:
let let
@ -34,10 +35,10 @@ in
|> lib.map (value: value.options.meta.domains.list.definitionsWithLocations) |> lib.map (value: value.options.meta.domains.list.definitionsWithLocations)
|> lib.concatLists |> lib.concatLists
|> lib.concatMap ( |> lib.concatMap (
entry: { file, value }:
entry.value value
|> lib.map (domain: { |> lib.map (domain: {
file = entry.file |> lib.removePrefix "${self}/"; file = lib'.relativePath file;
inherit domain; inherit domain;
}) })
) )

View file

@ -1,8 +1,8 @@
{ {
config, config,
options, options,
self,
lib, lib,
lib',
... ...
}: }:
let let
@ -28,10 +28,10 @@ in
protocol: protocol:
options.meta.ports.${protocol}.list.definitionsWithLocations options.meta.ports.${protocol}.list.definitionsWithLocations
|> lib.concatMap ( |> lib.concatMap (
entry: { file, value }:
entry.value value
|> lib.map (port: { |> lib.map (port: {
file = entry.file |> lib.removePrefix "${self}/"; file = lib'.relativePath file;
inherit port; inherit port;
}) })
) )