This commit is contained in:
Henri Dohmen 2025-05-31 14:22:37 +02:00
parent 1f65e12585
commit 7584ff9a39
5 changed files with 49 additions and 48 deletions

View file

@ -26,9 +26,9 @@
lib = nixpkgs.lib; lib = nixpkgs.lib;
lib' = import ./lib.nix { inherit lib; }; lib' = import ./lib.nix { inherit lib; };
specialArgs = { specialArgs = rec {
inherit inputs lib'; inherit inputs lib';
var = (lib'.walk-dir ./var).map_import_with_lib; var = (lib'.walk-dir ./var)._map (f: import f { inherit lib var; });
}; };
overlays = _: { overlays = _: {
nixpkgs.overlays = [ colmena.overlay ]; nixpkgs.overlays = [ colmena.overlay ];

View file

@ -1,4 +1,4 @@
{ ... }: { var, ... }:
{ {
imports = [ imports = [
./boot.nix ./boot.nix
@ -7,4 +7,6 @@
./shell.nix ./shell.nix
./users.nix ./users.nix
]; ];
networking.extraHosts = var.lan-dns.hostsFile;
} }

32
lib.nix
View file

@ -1,14 +1,10 @@
{ lib, ... }: { lib, ... }:
with builtins; with builtins;
let
lib' = rec {
walk-dir =
let let
walk-dir-inner = walk-dir-inner =
path: path:
let let
dir = readDir path; dir = readDir path;
in in
lib.mapAttrs' (filename: value: { lib.mapAttrs' (filename: value: {
name = lib.removeSuffix ".nix" filename; name = lib.removeSuffix ".nix" filename;
@ -21,31 +17,13 @@ let
throw "Items of type ${value} are unsupported."; throw "Items of type ${value} are unsupported.";
}) dir; }) dir;
helper-attrs = helper-attrs = subpaths: {
subpaths: _map = f: lib.mapAttrsRecursive (_: f) subpaths;
let
_files = lib.collect (x: isPath x || isString x) subpaths;
_nix_files = filter (lib.hasSuffix ".nix") _files;
in
rec {
to_mod = _: {
imports = _nix_files;
};
to_mod_without_default = without_default.to_mod;
collect_nix_files = _nix_files;
map_import = lib.mapAttrsRecursive (_: import) subpaths;
map_import_with_lib = lib.mapAttrsRecursive (_: x: (import x) { inherit lib lib'; }) subpaths;
without_default =
let
subpaths' = removeAttrs subpaths [ "default" ];
in
with-helper-attrs subpaths';
}; };
with-helper-attrs = with-helper-attrs =
x: if isAttrs x then lib.mapAttrs (_: with-helper-attrs) x // helper-attrs x else x; x: if isAttrs x then lib.mapAttrs (_: with-helper-attrs) x // helper-attrs x else x;
in in
p: with-helper-attrs (walk-dir-inner p); {
}; walk-dir = p: with-helper-attrs (walk-dir-inner p);
in }
lib'

18
var/lan-dns.nix Normal file
View file

@ -0,0 +1,18 @@
{ lib, var, ... }:
let
lan-tld = ".lan";
lan-base-domain = ".hdohmen.de";
lan-hosts = lib.mapAttrs' (name: value: {
name = "${name}${lan-tld}";
inherit value;
}) var.wg.ips;
in
rec {
hostsFile = lib.concatStringsSep "\n" (lib.mapAttrsFlatten (n: v: "${n}\t${v}") hosts);
hosts =
lan-hosts
// lib.mapAttrs' (name: value: {
name = "${name}${lan-base-domain}";
inherit value;
}) lan-hosts;
}

View file

@ -32,4 +32,7 @@ rec {
lib.attrValues (lib.filterAttrs (n: _: n != host) wireguard-network) lib.attrValues (lib.filterAttrs (n: _: n != host) wireguard-network)
); );
ips =
with builtins;
mapAttrs (name: value: head (lib.splitString "/" (head value.ips))) wireguard-network;
} }