Kieran's opinionated (and probably slightly dumb) nix config

feat: add zmx

dunkirk.sh 9c2c7d9e 2c227844

verified
Changed files
+363 -3
machines
atalanta
ember
nest
prattle
terebithia
modules
home
apps
system
+87 -1
flake.lock
···
"type": "github"
}
},
+
"flake-utils_7": {
+
"inputs": {
+
"systems": "systems_10"
+
},
+
"locked": {
+
"lastModified": 1731533236,
+
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
+
"owner": "numtide",
+
"repo": "flake-utils",
+
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
+
"type": "github"
+
},
+
"original": {
+
"owner": "numtide",
+
"repo": "flake-utils",
+
"type": "github"
+
}
+
},
"flare": {
"inputs": {
"flake-utils": "flake-utils_3",
···
"type": "github"
}
},
+
"nixpkgs_8": {
+
"locked": {
+
"lastModified": 1764635402,
+
"narHash": "sha256-6rYcajRLe2C5ZYnV1HYskJl+QAkhvseWTzbdQiTN9OI=",
+
"owner": "nixos",
+
"repo": "nixpkgs",
+
"rev": "5f53b0d46d320352684242d000b36dcfbbf7b0bc",
+
"type": "github"
+
},
+
"original": {
+
"owner": "nixos",
+
"repo": "nixpkgs",
+
"type": "github"
+
}
+
},
"nixvim": {
"inputs": {
"flake-parts": "flake-parts",
···
"spicetify-nix": "spicetify-nix",
"tangled": "tangled",
"terminal-wakatime": "terminal-wakatime",
-
"wakatime-ls": "wakatime-ls"
+
"wakatime-ls": "wakatime-ls",
+
"zmx": "zmx"
},
"rust-overlay": {
···
"type": "github"
},
+
"systems_10": {
+
"locked": {
+
"lastModified": 1681028828,
+
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+
"owner": "nix-systems",
+
"repo": "default",
+
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+
"type": "github"
+
},
+
"original": {
+
"owner": "nix-systems",
+
"repo": "default",
+
"type": "github"
+
}
+
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
···
"original": {
"owner": "mrnossiom",
"repo": "wakatime-ls",
+
"type": "github"
+
}
+
},
+
"zig2nix": {
+
"inputs": {
+
"flake-utils": "flake-utils_7",
+
"nixpkgs": "nixpkgs_8"
+
},
+
"locked": {
+
"lastModified": 1764678235,
+
"narHash": "sha256-NNQWR3DAufaH7fs6ZplfAv1xPHEc0Ne3Z0v4MNHCqSw=",
+
"owner": "Cloudef",
+
"repo": "zig2nix",
+
"rev": "8b6ec85bccdf6b91ded19e9ef671205937e271e6",
+
"type": "github"
+
},
+
"original": {
+
"owner": "Cloudef",
+
"repo": "zig2nix",
+
"type": "github"
+
}
+
},
+
"zmx": {
+
"inputs": {
+
"zig2nix": "zig2nix"
+
},
+
"locked": {
+
"lastModified": 1765255474,
+
"narHash": "sha256-Bs/wb2EIDe1QHsmHHQ34L0se4eANdGsQpxAsc+gDCrU=",
+
"owner": "neurosnap",
+
"repo": "zmx",
+
"rev": "b5b525c333f086798e319b1a27f2bc0119ebca5c",
+
"type": "github"
+
},
+
"original": {
+
"owner": "neurosnap",
+
"repo": "zmx",
"type": "github"
+4
flake.nix
···
url = "github:taciturnaxolotl/battleship-arena";
inputs.nixpkgs.follows = "nixpkgs";
};
+
+
zmx = {
+
url = "github:neurosnap/zmx";
+
};
};
outputs =
+56
machines/atalanta/home/default.nix
···
enable = true;
authTokenFile = osConfig.age.secrets.frp-auth-token.path;
};
+
ssh = {
+
enable = true;
+
+
zmx = {
+
enable = true;
+
hosts = [ "t.*" "p.*" "e.*" ];
+
};
+
+
hosts = {
+
# Dynamic zmx sessions per server
+
"t.*" = {
+
hostname = "150.136.15.177"; # terebithia
+
};
+
+
"p.*" = {
+
hostname = "150.136.63.103"; # prattle
+
};
+
+
"e.*" = {
+
hostname = "192.168.0.94"; # ember
+
};
+
+
# Regular hosts
+
john = {
+
user = "klukas";
+
};
+
+
bandit = {
+
hostname = "bandit.labs.overthewire.org";
+
port = 2220;
+
};
+
+
kali = {
+
user = "kali";
+
};
+
+
terebithia = {
+
hostname = "150.136.15.177";
+
zmx = true;
+
};
+
+
prattle = {
+
hostname = "150.136.63.103";
+
zmx = true;
+
};
+
+
ember = {
+
hostname = "192.168.0.94";
+
zmx = true;
+
};
+
};
+
+
extraConfig = ''
+
IdentityFile ~/.ssh/id_rsa
+
'';
+
};
};
programs.zsh.initContent = ''
+4
machines/ember/default.nix
···
apps = {
helix.enable = true;
};
+
ssh = {
+
enable = true;
+
zmx.enable = true;
+
};
};
# Enable home-manager
+4
machines/nest/default.nix
···
apps = {
helix.enable = true;
};
+
ssh = {
+
enable = true;
+
zmx.enable = true;
+
};
};
# Enable home-manager
+7
machines/prattle/home/default.nix
···
homeDirectory = "/home/kierank";
};
+
atelier = {
+
ssh = {
+
enable = true;
+
zmx.enable = true;
+
};
+
};
+
programs.home-manager.enable = true;
systemd.user.startServices = "sd-switch";
+4
machines/terebithia/home/default.nix
···
helix.enable = true;
irssi.enable = true;
};
+
ssh = {
+
enable = true;
+
zmx.enable = true;
+
};
};
programs.home-manager.enable = true;
+188
modules/home/apps/ssh.nix
···
+
{
+
config,
+
lib,
+
pkgs,
+
inputs,
+
...
+
}:
+
with lib;
+
let
+
cfg = config.atelier.ssh;
+
in
+
{
+
options.atelier.ssh = {
+
enable = mkEnableOption "SSH configuration";
+
+
zmx = {
+
enable = mkEnableOption "zmx integration for persistent sessions";
+
hosts = mkOption {
+
type = types.listOf types.str;
+
default = [ ];
+
description = "List of host patterns to enable zmx auto-attach (e.g., 'd.*')";
+
};
+
};
+
+
extraConfig = mkOption {
+
type = types.lines;
+
default = "";
+
description = "Extra SSH configuration";
+
};
+
+
hosts = mkOption {
+
type = types.attrsOf (
+
types.submodule {
+
options = {
+
hostname = mkOption {
+
type = types.nullOr types.str;
+
default = null;
+
description = "Hostname or IP address";
+
};
+
+
port = mkOption {
+
type = types.nullOr types.int;
+
default = null;
+
description = "SSH port";
+
};
+
+
user = mkOption {
+
type = types.nullOr types.str;
+
default = null;
+
description = "Username for SSH connection";
+
};
+
+
identityFile = mkOption {
+
type = types.nullOr types.str;
+
default = null;
+
description = "Path to SSH identity file";
+
};
+
+
forwardAgent = mkOption {
+
type = types.nullOr types.bool;
+
default = null;
+
description = "Enable SSH agent forwarding";
+
};
+
+
extraOptions = mkOption {
+
type = types.attrsOf types.str;
+
default = { };
+
description = "Additional SSH options for this host";
+
};
+
+
zmx = mkOption {
+
type = types.bool;
+
default = false;
+
description = "Enable zmx persistent sessions for this host";
+
};
+
};
+
}
+
);
+
default = { };
+
description = "SSH host configurations";
+
};
+
};
+
+
config = mkIf cfg.enable {
+
# On macOS (darwin), zmx must be installed manually due to build issues
+
# Download from: https://zmx.sh/a/zmx-0.0.2-macos-aarch64.tar.gz
+
# Extract and place in PATH (e.g., ~/.local/bin/)
+
+
# On Linux, use the zmx flake
+
home.packages =
+
(optionals (cfg.zmx.enable && !pkgs.stdenv.isDarwin) [
+
inputs.zmx.packages.${pkgs.stdenv.hostPlatform.system}.default
+
])
+
++ (optionals cfg.zmx.enable [
+
pkgs.autossh
+
]);
+
+
programs.ssh = {
+
enable = true;
+
enableDefaultConfig = false;
+
+
matchBlocks =
+
let
+
# Convert atelier.ssh.hosts to SSH matchBlocks
+
hostConfigs = mapAttrs (
+
name: hostCfg:
+
{
+
hostname = mkIf (hostCfg.hostname != null) hostCfg.hostname;
+
port = mkIf (hostCfg.port != null) hostCfg.port;
+
user = mkIf (hostCfg.user != null) hostCfg.user;
+
identityFile = mkIf (hostCfg.identityFile != null) hostCfg.identityFile;
+
forwardAgent = mkIf (hostCfg.forwardAgent != null) hostCfg.forwardAgent;
+
extraOptions = hostCfg.extraOptions // (
+
if hostCfg.zmx then
+
{
+
RemoteCommand = "zmx attach %n";
+
RequestTTY = "yes";
+
ControlPath = "~/.ssh/cm-%r@%h:%p";
+
ControlMaster = "auto";
+
ControlPersist = "10m";
+
}
+
else
+
{ }
+
);
+
}
+
) cfg.hosts;
+
+
# Create zmx pattern hosts if enabled
+
zmxPatternHosts = if cfg.zmx.enable then
+
listToAttrs (
+
map (pattern:
+
let
+
patternHost = cfg.hosts.${pattern} or {};
+
in {
+
name = pattern;
+
value = {
+
hostname = mkIf (patternHost.hostname or null != null) patternHost.hostname;
+
port = mkIf (patternHost.port or null != null) patternHost.port;
+
user = mkIf (patternHost.user or null != null) patternHost.user;
+
extraOptions = {
+
RemoteCommand = "zmx attach %k";
+
RequestTTY = "yes";
+
ControlPath = "~/.ssh/cm-%r@%h:%p";
+
ControlMaster = "auto";
+
ControlPersist = "10m";
+
};
+
};
+
}) cfg.zmx.hosts
+
)
+
else
+
{ };
+
+
# Default match block for extraConfig
+
defaultBlock = if cfg.extraConfig != "" then
+
{
+
"*" = { };
+
}
+
else
+
{ };
+
in
+
defaultBlock // hostConfigs // zmxPatternHosts;
+
+
extraConfig = cfg.extraConfig;
+
};
+
+
# Add shell aliases for easier zmx usage
+
programs.zsh.shellAliases = mkIf cfg.zmx.enable {
+
zmls = "zmx list";
+
zmk = "zmx kill";
+
zma = "zmx attach";
+
ash = "autossh -M 0 -q";
+
};
+
+
programs.bash.shellAliases = mkIf cfg.zmx.enable {
+
zmls = "zmx list";
+
zmk = "zmx kill";
+
zma = "zmx attach";
+
ash = "autossh -M 0 -q";
+
};
+
+
programs.fish.shellAliases = mkIf cfg.zmx.enable {
+
zmls = "zmx list";
+
zmk = "zmx kill";
+
zma = "zmx attach";
+
ash = "autossh -M 0 -q";
+
};
+
};
+
}
+9 -2
modules/home/system/shell.nix
···
template = "{{ if .SSHSession }}{{.HostName}} {{ end }}";
}
{
+
type = "text";
+
style = "plain";
+
background = "transparent";
+
foreground = "green";
+
template = "{{ if .Env.ZMX_SESSION }}[{{ .Env.ZMX_SESSION }}] {{ end }}";
+
}
+
{
type = "path";
style = "plain";
background = "transparent";
···
style = "plain";
foreground_templates = [
"{{if gt .Code 0}}red{{end}}"
-
"{{if eq .Code 0}}magenta{{end}}"
+
"{{if eq .Code 0}}{{if .Env.SSH_CONNECTION}}cyan{{else}}magenta{{end}}{{end}}"
];
background = "transparent";
template = "❯";
···
transient_prompt = {
foreground_templates = [
"{{if gt .Code 0}}red{{end}}"
-
"{{if eq .Code 0}}magenta{{end}}"
+
"{{if eq .Code 0}}{{if .Env.SSH_CONNECTION}}cyan{{else}}magenta{{end}}{{end}}"
];
background = "transparent";
template = "❯ ";