Compare commits

...

2 Commits

Author SHA1 Message Date
f3bf750fb2
WIP: pc: add home-manager 2025-02-19 17:25:12 -08:00
ba48dd8706
WIP: router: refactor dhcp configs 2025-02-17 22:56:06 -08:00
4 changed files with 196 additions and 103 deletions

21
flake.lock generated
View File

@ -1,5 +1,25 @@
{
"nodes": {
"home-manager": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1739992710,
"narHash": "sha256-9kEscmGnXHjSgcqyJR4TzzHhska4yz1inSQs6HuO9qU=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "1c189f011447810af939a886ba7bee33532bb1f9",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "home-manager",
"type": "github"
}
},
"nixlib": {
"locked": {
"lastModified": 1736643958,
@ -54,6 +74,7 @@
},
"root": {
"inputs": {
"home-manager": "home-manager",
"nixos-generators": "nixos-generators",
"nixpkgs": "nixpkgs"
}

View File

@ -5,13 +5,17 @@
nixpkgs = {
url = "github:NixOS/nixpkgs/nixos-unstable";
};
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, nixos-generators }: {
outputs = { self, nixpkgs, home-manager, nixos-generators }: {
nixosConfigurations = {
Yura-PC = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
@ -19,6 +23,16 @@
./modules
./hosts/common.nix
./hosts/Yura-PC
# https://nix-community.github.io/home-manager/index.xhtml#sec-flakes-nixos-module
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.cazzzer = import ./home;
# Optionally, use home-manager.extraSpecialArgs to pass
# arguments to home.nix
}
];
};
VM = nixpkgs.lib.nixosSystem {

78
home/default.nix Normal file
View File

@ -0,0 +1,78 @@
{ config, pkgs, ... }:
{
# Home Manager needs a bit of information about you and the paths it should
# manage.
home.username = "cazzzer";
home.homeDirectory = "/home/cazzzer";
# This value determines the Home Manager release that your configuration is
# compatible with. This helps avoid breakage when a new Home Manager release
# introduces backwards incompatible changes.
#
# You should not change this value, even if you update Home Manager. If you do
# want to update the value, then make sure to first check the Home Manager
# release notes.
home.stateVersion = "24.11"; # Please read the comment before changing.
# The home.packages option allows you to install Nix packages into your
# environment.
home.packages = [
# # Adds the 'hello' command to your environment. It prints a friendly
# # "Hello, world!" when run.
# pkgs.hello
# # It is sometimes useful to fine-tune packages, for example, by applying
# # overrides. You can do that directly here, just don't forget the
# # parentheses. Maybe you want to install Nerd Fonts with a limited number of
# # fonts?
# (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; })
# # You can also create simple shell scripts directly inside your
# # configuration. For example, this adds a command 'my-hello' to your
# # environment:
# (pkgs.writeShellScriptBin "my-hello" ''
# echo "Hello, ${config.home.username}!"
# '')
];
# Home Manager is pretty good at managing dotfiles. The primary way to manage
# plain files is through 'home.file'.
home.file = {
# # Building this configuration will create a copy of 'dotfiles/screenrc' in
# # the Nix store. Activating the configuration will then make '~/.screenrc' a
# # symlink to the Nix store copy.
# ".screenrc".source = dotfiles/screenrc;
# # You can also set the file content immediately.
# ".gradle/gradle.properties".text = ''
# org.gradle.console=verbose
# org.gradle.daemon.idletimeout=3600000
# '';
".config/hi".text = "hello";
};
# Home Manager can also manage your environment variables through
# 'home.sessionVariables'. These will be explicitly sourced when using a
# shell provided by Home Manager. If you don't want to manage your shell
# through Home Manager then you have to manually source 'hm-session-vars.sh'
# located at either
#
# ~/.nix-profile/etc/profile.d/hm-session-vars.sh
#
# or
#
# ~/.local/state/nix/profiles/profile/etc/profile.d/hm-session-vars.sh
#
# or
#
# /etc/profiles/per-user/cazzzer/etc/profile.d/hm-session-vars.sh
#
home.sessionVariables = {
# EDITOR = "emacs";
};
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
}

View File

@ -5,12 +5,14 @@ let
mkIfConfig = {
name_,
domain_,
p4_, # /24
p6_, # /64
ulaPrefix_, # /64
token? 1,
}: rec {
name = name_;
domain = domain_;
p4 = p4_;
p4Size = 24;
net4 = "${p4}.0/${toString p4Size}";
@ -41,66 +43,93 @@ let
};
lan = mkIfConfig {
name_ = "lan";
domain_ = "lan.${ldomain}";
p4_ = "${p4}.1"; # .0/24
p6_ = "${pdFromWan}9"; # ::/64
ulaPrefix_ = "${ulaPrefix}:0001"; # ::/64
};
lan10 = mkIfConfig {
name_ = "${lan.name}.10";
domain_ = "lab.${ldomain}";
p4_ = "${p4}.10"; # .0/24
p6_ = "${pdFromWan}a"; # ::/64
ulaPrefix_ = "${ulaPrefix}:0010"; # ::/64
};
lan20 = mkIfConfig {
name_ = "${lan.name}.20";
domain_ = "life.${ldomain}";
p4_ = "${p4}.20"; # .0/24
p6_ = "${pdFromWan}2"; # ::/64
ulaPrefix_ = "${ulaPrefix}:0020"; # ::/64
};
lan50 = mkIfConfig {
name_ = "${lan.name}.50";
domain_ = "prox.${ldomain}";
p4_ = "10.17.50"; # .0/24 TODO: change to p4 later
p6_ = "${pdFromWan}a"; # ::/64
ulaPrefix_ = "${ulaPrefix}:0050"; # ::/64
};
};
mkVlanDev = { id, name }:
{
netdevConfig = {
Kind = "vlan";
Name = name;
};
vlanConfig.Id = id;
mkVlanDev = { id, name }: {
netdevConfig = {
Kind = "vlan";
Name = name;
};
mkLanConfig = ifObj:
{
matchConfig.Name = ifObj.name;
networkConfig = {
IPv4Forwarding = true;
IPv6SendRA = true;
Address = [ ifObj.addr4Sized ];
};
ipv6Prefixes = [
{
Prefix = ifObj.net6;
Assign = true;
# Token = [ "static::1" "eui64" ];
Token = [ "static:${ifObj.ip6Token}" ];
}
{
Prefix = ifObj.ulaNet;
Assign = true;
Token = [ "static:${ifObj.ip6Token}" ];
}
];
ipv6SendRAConfig = {
Managed = true;
OtherInformation = true;
EmitDNS = true;
DNS = [ ifObj.ulaAddr ];
};
vlanConfig.Id = id;
};
mkLanConfig = ifObj: {
matchConfig.Name = ifObj.name;
networkConfig = {
IPv4Forwarding = true;
IPv6SendRA = true;
Address = [ ifObj.addr4Sized ];
};
ipv6Prefixes = [
{
Prefix = ifObj.net6;
Assign = true;
# Token = [ "static::1" "eui64" ];
Token = [ "static:${ifObj.ip6Token}" ];
}
{
Prefix = ifObj.ulaNet;
Assign = true;
Token = [ "static:${ifObj.ip6Token}" ];
}
];
ipv6SendRAConfig = {
Managed = true;
OtherInformation = true;
EmitDNS = true;
DNS = [ ifObj.ulaAddr ];
};
};
mkDhcp4Subnet = id: ifObj: {
id = id;
subnet = ifObj.net4;
pools = [ { pool = "${ifObj.p4}.100 - ${ifObj.p4}.199"; } ];
ddns-qualifying-suffix = "4.${ifObj.domain}";
option-data = [
{ name = "routers"; data = ifObj.addr4; }
{ name = "domain-name-servers"; data = ifObj.addr4; }
{ name = "domain-name"; data = "4.${ifObj.domain}"; }
];
};
mkDhcp6Subnet = id: ifObj: {
id = id;
interface = ifObj.name;
subnet = ifObj.net6;
rapid-commit = true;
pools = [ { pool = "${ifObj.p6}::1:1000/116"; } ];
ddns-qualifying-suffix = "6.${ifObj.domain}";
option-data = [
{ name = "domain-search"; data = "6.${ifObj.domain}"; }
];
};
in
{
imports =
@ -202,7 +231,9 @@ in
# make routing on this interface a dependency for network-online.target
linkConfig.RequiredForOnline = "routable";
};
"20-lan" = (mkLanConfig ifs.lan) // {
# "20-lan" = (mkLanConfig ifs.lan) // {
"20-lan" = {
matchConfig.Name = ifs.lan.name;
vlan = [
ifs.lan10.name
ifs.lan20.name
@ -351,23 +382,9 @@ in
ifs.lan50.name
];
dhcp-ddns.enable-updates = true;
ddns-qualifying-suffix = "default.${ldomain}";
ddns-qualifying-suffix = "4.default.${ldomain}";
subnet4 = [
{
id = 1;
subnet = ifs.lan.net4;
ddns-qualifying-suffix = "lan.${ldomain}";
pools = [ { pool = "${ifs.lan.p4}.100 - ${ifs.lan.p4}.199"; } ];
option-data = [
{
name = "routers";
data = ifs.lan.addr4;
}
{
name = "domain-name-servers";
data = ifs.lan.addr4;
}
];
((mkDhcp4Subnet 1 ifs.lan) // {
reservations = [
{
hw-address = "bc:24:11:b7:27:4d";
@ -375,23 +392,8 @@ in
ip-address = "${ifs.lan.p4}.69";
}
];
}
{
id = 50;
subnet = ifs.lan50.net4;
ddns-qualifying-suffix = "prox.${ldomain}";
pools = [ { pool = "${ifs.lan50.p4}.100 - ${ifs.lan50.p4}.199"; } ];
option-data = [
{
name = "routers";
data = ifs.lan50.addr4;
}
{
name = "domain-name-servers";
data = ifs.lan50.addr4;
}
];
}
})
(mkDhcp4Subnet 50 ifs.lan50)
];
};
@ -405,15 +407,9 @@ in
];
# TODO: https://kea.readthedocs.io/en/latest/arm/ddns.html#dual-stack-environments
dhcp-ddns.enable-updates = true;
ddns-qualifying-suffix = "default6.${ldomain}";
ddns-qualifying-suffix = "6.default.${ldomain}";
subnet6 = [
{
id = 1;
interface = ifs.lan.name;
subnet = ifs.lan.net6;
ddns-qualifying-suffix = "lan6.${ldomain}";
rapid-commit = true;
pools = [ { pool = "${ifs.lan.p6}::1:1000/116"; } ];
((mkDhcp6Subnet 1 ifs.lan) // {
reservations = [
{
duid = "00:04:59:c3:ce:9a:08:cf:fb:b7:fe:74:9c:e3:b7:44:bf:01";
@ -421,33 +417,19 @@ in
ip-addresses = [ "${ifs.lan.p6}::69" ];
}
];
}
{
id = 50;
interface = ifs.lan50.name;
subnet = ifs.lan50.net6;
ddns-qualifying-suffix = "prox6.${ldomain}";
rapid-commit = true;
pools = [ { pool = "${ifs.lan50.p6}::1:1000/116"; } ];
}
})
(mkDhcp6Subnet 50 ifs.lan50)
];
};
services.kea.dhcp-ddns.enable = true;
services.kea.dhcp-ddns.settings = {
forward-ddns = {
ddns-domains = [
{
name = "${ldomain}.";
dns-servers = [
{
ip-address = "::1";
port = 1053;
}
];
}
];
};
forward-ddns.ddns-domains = [
{
name = "${ldomain}.";
dns-servers = [ { ip-address = "::1"; port = 1053; } ];
}
];
};
services.resolved.enable = false;
@ -476,10 +458,8 @@ in
services.knot.enable = true;
services.knot.settings = {
server = {
# listen = "0.0.0.0@1053";
listen = "::1@1053";
};
# server.listen = "0.0.0.0@1053";
server.listen = "::1@1053";
# TODO: templates
zone = [
{