dns
This commit is contained in:
parent
1f65e12585
commit
7584ff9a39
5 changed files with 49 additions and 48 deletions
|
|
@ -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 ];
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
68
lib.nix
68
lib.nix
|
|
@ -1,51 +1,29 @@
|
||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
with builtins;
|
with builtins;
|
||||||
let
|
let
|
||||||
lib' = rec {
|
walk-dir-inner =
|
||||||
walk-dir =
|
path:
|
||||||
let
|
let
|
||||||
walk-dir-inner =
|
dir = readDir path;
|
||||||
path:
|
in
|
||||||
let
|
lib.mapAttrs' (filename: value: {
|
||||||
dir = readDir path;
|
name = lib.removeSuffix ".nix" filename;
|
||||||
|
value =
|
||||||
|
if value == "regular" then
|
||||||
|
path + "/${filename}"
|
||||||
|
else if value == "directory" then
|
||||||
|
walk-dir-inner (path + "/${filename}")
|
||||||
|
else
|
||||||
|
throw "Items of type ${value} are unsupported.";
|
||||||
|
}) dir;
|
||||||
|
|
||||||
in
|
helper-attrs = subpaths: {
|
||||||
lib.mapAttrs' (filename: value: {
|
_map = f: lib.mapAttrsRecursive (_: f) subpaths;
|
||||||
name = lib.removeSuffix ".nix" filename;
|
|
||||||
value =
|
|
||||||
if value == "regular" then
|
|
||||||
path + "/${filename}"
|
|
||||||
else if value == "directory" then
|
|
||||||
walk-dir-inner (path + "/${filename}")
|
|
||||||
else
|
|
||||||
throw "Items of type ${value} are unsupported.";
|
|
||||||
}) dir;
|
|
||||||
|
|
||||||
helper-attrs =
|
|
||||||
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 =
|
|
||||||
x: if isAttrs x then lib.mapAttrs (_: with-helper-attrs) x // helper-attrs x else x;
|
|
||||||
in
|
|
||||||
p: with-helper-attrs (walk-dir-inner p);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
with-helper-attrs =
|
||||||
|
x: if isAttrs x then lib.mapAttrs (_: with-helper-attrs) x // helper-attrs x else x;
|
||||||
in
|
in
|
||||||
lib'
|
{
|
||||||
|
walk-dir = p: with-helper-attrs (walk-dir-inner p);
|
||||||
|
}
|
||||||
|
|
|
||||||
18
var/lan-dns.nix
Normal file
18
var/lan-dns.nix
Normal 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;
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue