2022-11-14 20:56:23 +00:00
|
|
|
{ lib, pkgs, config, modulesPath, specialArgs, ... }:
|
2022-11-15 22:43:30 +00:00
|
|
|
let
|
|
|
|
hostname = specialArgs.hostname;
|
|
|
|
enableSSH = specialArgs.enableSSH or true;
|
2022-12-13 18:42:17 +00:00
|
|
|
_networking = lib.recursiveUpdate { hostName = hostname; } (specialArgs._networking or { });
|
2022-11-26 05:39:32 +00:00
|
|
|
_boot = specialArgs._boot or { };
|
|
|
|
_services = specialArgs._services or { };
|
2022-11-15 22:43:30 +00:00
|
|
|
includeHardware = specialArgs.includeHardware or true;
|
2022-12-03 10:43:45 +00:00
|
|
|
proj_root = builtins.toString ./../..;
|
2022-11-14 20:56:23 +00:00
|
|
|
in
|
2022-08-30 14:29:44 +00:00
|
|
|
with lib;
|
|
|
|
{
|
2022-11-15 22:43:30 +00:00
|
|
|
imports = (if includeHardware then [
|
2022-11-14 20:56:23 +00:00
|
|
|
./profiles/${hostname}/hardware-configuration.nix
|
2022-11-15 22:44:56 +00:00
|
|
|
] else [ ]) ++ [
|
|
|
|
"${modulesPath}/profiles/minimal.nix"
|
2022-08-30 14:29:44 +00:00
|
|
|
];
|
2022-11-26 05:39:32 +00:00
|
|
|
boot = _boot;
|
2022-08-30 14:29:44 +00:00
|
|
|
|
2022-12-21 10:37:03 +00:00
|
|
|
# prune old builds
|
2022-11-30 11:32:24 +00:00
|
|
|
nix.settings.auto-optimise-store = true;
|
|
|
|
|
2022-08-30 14:29:44 +00:00
|
|
|
# Enable nix flakes
|
|
|
|
nix.package = pkgs.nixFlakes;
|
|
|
|
nix.extraOptions = ''
|
|
|
|
experimental-features = nix-command flakes
|
|
|
|
'';
|
2022-11-14 22:10:46 +00:00
|
|
|
users.users.hungtr = {
|
2022-11-15 22:44:56 +00:00
|
|
|
isNormalUser = true;
|
|
|
|
home = "/home/hungtr";
|
|
|
|
description = "pegasust/hungtr";
|
2023-01-13 06:42:21 +00:00
|
|
|
extraGroups = [ "wheel" "networkmanager" "audio" ];
|
2022-11-30 02:29:09 +00:00
|
|
|
};
|
|
|
|
users.users.root = {
|
|
|
|
# openssh runs in root, no? This is because port < 1024 requires root.
|
2022-12-27 04:22:07 +00:00
|
|
|
openssh.authorizedKeys.keys = lib.strings.splitString "\n" (builtins.readFile "${proj_root}/native_configs/ssh/authorized_keys");
|
2022-11-14 18:01:39 +00:00
|
|
|
};
|
2022-08-30 14:29:44 +00:00
|
|
|
|
2022-11-06 20:23:10 +00:00
|
|
|
# Some basic programs
|
2022-08-30 14:29:44 +00:00
|
|
|
programs.neovim = {
|
2022-11-15 22:44:56 +00:00
|
|
|
enable = true;
|
|
|
|
defaultEditor = true;
|
2022-08-30 14:29:44 +00:00
|
|
|
};
|
2022-11-14 18:01:39 +00:00
|
|
|
|
2022-08-30 14:29:44 +00:00
|
|
|
programs.git = {
|
2022-11-15 22:44:56 +00:00
|
|
|
enable = true;
|
|
|
|
# more information should be configured under user level
|
2022-11-24 00:58:22 +00:00
|
|
|
# See other config at @/home-nix
|
2022-08-30 14:29:44 +00:00
|
|
|
};
|
2022-11-14 18:01:39 +00:00
|
|
|
|
2022-08-30 14:29:44 +00:00
|
|
|
environment.systemPackages = [
|
2022-11-15 22:44:56 +00:00
|
|
|
pkgs.gnumake
|
|
|
|
pkgs.wget
|
2022-11-24 00:58:22 +00:00
|
|
|
pkgs.inetutils # network diag
|
2022-11-24 02:14:25 +00:00
|
|
|
pkgs.mtr # network diag
|
2022-11-24 00:58:22 +00:00
|
|
|
pkgs.sysstat # sys diag
|
2022-11-24 02:14:25 +00:00
|
|
|
pkgs.mosh # ssh-alt; parsec-like
|
2022-11-24 01:28:46 +00:00
|
|
|
pkgs.tailscale # VPC
|
2022-08-30 14:29:44 +00:00
|
|
|
];
|
2022-11-24 02:14:25 +00:00
|
|
|
# tailscale is mandatory : ^)
|
|
|
|
# inherit services;
|
2022-12-13 18:42:17 +00:00
|
|
|
services = lib.recursiveUpdate _services {
|
2022-11-24 02:14:25 +00:00
|
|
|
tailscale.enable = true;
|
2022-12-21 23:42:59 +00:00
|
|
|
ntp.enable = true;
|
2022-11-24 02:14:25 +00:00
|
|
|
};
|
|
|
|
# create a oneshot job to authenticate to Tailscale
|
|
|
|
systemd.services.tailscale-autoconnect = {
|
|
|
|
description = "Automatic connection to Tailscale";
|
|
|
|
|
|
|
|
# make sure tailscale is running before trying to connect to tailscale
|
|
|
|
after = [ "network-pre.target" "tailscale.service" ];
|
|
|
|
wants = [ "network-pre.target" "tailscale.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
# set this service as a oneshot job
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
|
|
|
|
# have the job run this shell script
|
|
|
|
script = ''
|
|
|
|
# wait for tailscaled to settle
|
2022-11-24 03:48:28 +00:00
|
|
|
sleep 2
|
2022-11-24 02:14:25 +00:00
|
|
|
# check if we are already authenticated to tailscale
|
|
|
|
status="$(${pkgs.tailscale}/bin/tailscale status -json | ${pkgs.jq}/bin/jq -r .BackendState)"
|
|
|
|
if [ $status = "Running" ]; then # if so, then do nothing
|
|
|
|
exit 0
|
|
|
|
fi
|
2022-11-24 03:48:28 +00:00
|
|
|
|
|
|
|
# ${pkgs.tailscale}/bin/tailscale up # blocks, doesn't give url
|
|
|
|
# This time, configure device auth so that we authenticate from portal
|
|
|
|
# https://tailscale.com/kb/1099/device-authorization/#enable-device-authorization-for-your-network
|
|
|
|
${pkgs.tailscale}/bin/tailscale up -authkey tskey-auth-kJcgTG5CNTRL-PUVFkk31z1bThHpfq3FC5b1jcMmkW2EYW
|
2022-11-24 02:14:25 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
# Don't touch networking.firewall.enable, just configure everything else.
|
|
|
|
# inherit networking;
|
2022-11-26 05:39:32 +00:00
|
|
|
# inherit _networking;
|
2022-12-13 18:42:17 +00:00
|
|
|
networking = lib.recursiveUpdate _networking {
|
2022-11-26 05:39:32 +00:00
|
|
|
firewall =
|
2022-11-26 06:28:05 +00:00
|
|
|
if _networking ? firewall.enable && _networking.firewall.enable then {
|
2022-11-26 05:39:32 +00:00
|
|
|
trustedInterfaces = _networking.firewall.trustedInterfaces or [ ] ++ [
|
|
|
|
"tailscale0"
|
|
|
|
];
|
|
|
|
allowedUDPPorts = _networking.firewall.allowedUDPPorts or [ ] ++ [
|
|
|
|
config.services.tailscale.port
|
|
|
|
];
|
|
|
|
allowedTCPPorts = _networking.firewall.allowedTCPPorts or [ ] ++ [
|
|
|
|
22
|
|
|
|
];
|
|
|
|
allowedUDPPortRanges = _networking.firewall.allowedUDPPortRanges or [ ] ++ [
|
|
|
|
{ from = 60000; to = 61000; } # mosh
|
2022-11-24 04:25:13 +00:00
|
|
|
|
2022-11-26 05:39:32 +00:00
|
|
|
];
|
|
|
|
checkReversePath = "loose";
|
|
|
|
} else { enable = false; };
|
2022-11-24 02:14:25 +00:00
|
|
|
};
|
|
|
|
|
2022-12-21 10:37:03 +00:00
|
|
|
environment.noXlibs = lib.mkForce false;
|
|
|
|
|
2022-11-15 22:44:56 +00:00
|
|
|
}
|
2022-11-14 18:01:39 +00:00
|
|
|
|