fix indentation
This commit is contained in:
178
flake.nix
178
flake.nix
@@ -10,7 +10,6 @@
|
|||||||
let
|
let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
# You can change the range here for local development (e.g., 1 2)
|
|
||||||
participantRange = nixpkgs.lib.range 1 2;
|
participantRange = nixpkgs.lib.range 1 2;
|
||||||
fullParticipantNames = [
|
fullParticipantNames = [
|
||||||
"hopper" "curie" "lovelace" "noether" "hamilton"
|
"hopper" "curie" "lovelace" "noether" "hamilton"
|
||||||
@@ -33,7 +32,6 @@
|
|||||||
extraGroups = [ "wheel" ];
|
extraGroups = [ "wheel" ];
|
||||||
password = "workshop";
|
password = "workshop";
|
||||||
};
|
};
|
||||||
# Use generic autologin for the live ISO TTY
|
|
||||||
services.getty.autologinUser = "workshop";
|
services.getty.autologinUser = "workshop";
|
||||||
programs.zsh.enable = true;
|
programs.zsh.enable = true;
|
||||||
environment.systemPackages = with pkgs; [ openssh curl git ];
|
environment.systemPackages = with pkgs; [ openssh curl git ];
|
||||||
@@ -41,10 +39,9 @@
|
|||||||
enable = true;
|
enable = true;
|
||||||
displayManager.lightdm.enable = true;
|
displayManager.lightdm.enable = true;
|
||||||
desktopManager.xfce.enable = true;
|
desktopManager.xfce.enable = true;
|
||||||
displayManager.sessionCommands = ''
|
|
||||||
${pkgs.xfce.xfce4-terminal}/bin/xfce4-terminal -e "sudo -i" &
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
services.displayManager.autoLogin.enable = true;
|
||||||
|
services.displayManager.autoLogin.user = "workshop";
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
@@ -59,32 +56,74 @@
|
|||||||
boot.loader.grub.enable = false;
|
boot.loader.grub.enable = false;
|
||||||
boot.loader.generic-extlinux-compatible.enable = true;
|
boot.loader.generic-extlinux-compatible.enable = true;
|
||||||
|
|
||||||
|
# Enable IP forwarding for NAT
|
||||||
|
boot.kernel.sysctl."net.ipv4.ip_forward" = 1;
|
||||||
|
|
||||||
|
# Host VM user setup
|
||||||
users.users.workshop = {
|
users.users.workshop = {
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
extraGroups = [ "wheel" ]; # for sudo
|
extraGroups = [ "wheel" ];
|
||||||
password = "";
|
password = "";
|
||||||
|
shell = pkgs.bash;
|
||||||
};
|
};
|
||||||
|
|
||||||
# --- THIS IS THE CORRECTED SECTION ---
|
# GUI setup
|
||||||
services.xserver = {
|
services.xserver = {
|
||||||
enable = true;
|
enable = true;
|
||||||
desktopManager.xfce.enable = true;
|
desktopManager.xfce.enable = true;
|
||||||
displayManager.lightdm.enable = true;
|
displayManager.lightdm.enable = true;
|
||||||
};
|
};
|
||||||
# Use the generic, documented options for graphical autologin
|
|
||||||
services.displayManager.autoLogin.enable = true;
|
services.displayManager.autoLogin.enable = true;
|
||||||
services.displayManager.autoLogin.user = "workshop";
|
services.displayManager.autoLogin.user = "workshop";
|
||||||
|
|
||||||
|
# Auto-open root terminal
|
||||||
|
services.xserver.displayManager.sessionCommands = ''
|
||||||
|
${pkgs.xfce.xfce4-terminal}/bin/xfce4-terminal -T "Workshop Root Shell" -e "sudo -i" &
|
||||||
|
'';
|
||||||
|
|
||||||
environment.systemPackages = with pkgs; [ gnumake nano nixos-container firefox ];
|
# Workshop user convenience
|
||||||
|
programs.bash = {
|
||||||
|
shellAliases = {
|
||||||
|
connect = "sudo nixos-container login";
|
||||||
|
containers = "sudo nixos-container list";
|
||||||
|
root = "sudo -i";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
environment.systemPackages = with pkgs; [
|
||||||
|
gnumake nano nixos-container firefox git curl jq
|
||||||
|
];
|
||||||
security.pam.services.login.allowNullPassword = true;
|
security.pam.services.login.allowNullPassword = true;
|
||||||
security.sudo.wheelNeedsPassword = false;
|
security.sudo.wheelNeedsPassword = false;
|
||||||
networking.hostName = "workshop-vm";
|
networking.hostName = "workshop-vm";
|
||||||
|
|
||||||
|
# FIXED: Proper NAT configuration
|
||||||
|
networking = {
|
||||||
|
nat = {
|
||||||
|
enable = true;
|
||||||
|
internalInterfaces = ["ve-+"];
|
||||||
|
externalInterface = "eth0";
|
||||||
|
# Ensure we have masquerading
|
||||||
|
extraCommands = ''
|
||||||
|
iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o eth0 -j MASQUERADE
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
firewall = {
|
||||||
|
enable = true;
|
||||||
|
trustedInterfaces = [ "ve-+" ];
|
||||||
|
# Allow forwarding from containers
|
||||||
|
extraCommands = ''
|
||||||
|
iptables -A FORWARD -i ve-+ -j ACCEPT
|
||||||
|
iptables -A FORWARD -o ve-+ -j ACCEPT
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# Container configurations
|
||||||
containers = builtins.listToAttrs (map (i:
|
containers = builtins.listToAttrs (map (i:
|
||||||
let participant = builtins.elemAt fullParticipantNames (i - 1);
|
let participant = builtins.elemAt fullParticipantNames (i - 1);
|
||||||
in {
|
in {
|
||||||
name = "participant${toString i}";
|
name = participant;
|
||||||
value = {
|
value = {
|
||||||
autoStart = true;
|
autoStart = true;
|
||||||
privateNetwork = true;
|
privateNetwork = true;
|
||||||
@@ -92,34 +131,131 @@
|
|||||||
localAddress = "192.168.100.${toString (10 + i)}";
|
localAddress = "192.168.100.${toString (10 + i)}";
|
||||||
config = {
|
config = {
|
||||||
system.stateVersion = "25.05";
|
system.stateVersion = "25.05";
|
||||||
services.openssh.enable = true;
|
|
||||||
networking.hostName = participant;
|
users.users.root = {
|
||||||
|
password = "root";
|
||||||
|
openssh.authorizedKeys.keys = [];
|
||||||
|
};
|
||||||
|
users.users.workshop = {
|
||||||
|
isNormalUser = true;
|
||||||
|
password = "workshop";
|
||||||
|
extraGroups = [ "wheel" "docker" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
services.openssh = {
|
||||||
|
enable = true;
|
||||||
|
settings = {
|
||||||
|
PasswordAuthentication = true;
|
||||||
|
PermitRootLogin = "yes";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# FIXED: Proper network configuration
|
||||||
|
networking = {
|
||||||
|
hostName = participant;
|
||||||
|
nameservers = [ "8.8.8.8" "1.1.1.1" ];
|
||||||
|
defaultGateway = {
|
||||||
|
address = "192.168.100.1";
|
||||||
|
interface = "eth0";
|
||||||
|
};
|
||||||
|
firewall.enable = false;
|
||||||
|
useHostResolvConf = false;
|
||||||
|
# Ensure eth0 is configured properly
|
||||||
|
interfaces.eth0.ipv4.addresses = [{
|
||||||
|
address = "192.168.100.${toString (10 + i)}";
|
||||||
|
prefixLength = 24;
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
console.enable = true;
|
console.enable = true;
|
||||||
users.users.root.password = "root";
|
security.sudo.wheelNeedsPassword = false;
|
||||||
|
|
||||||
virtualisation.docker.enable = true;
|
virtualisation.docker.enable = true;
|
||||||
environment.systemPackages = with pkgs; [ docker git curl jq ];
|
environment.systemPackages = with pkgs; [
|
||||||
|
docker git curl jq wget gnutar gzip util-linux
|
||||||
|
];
|
||||||
|
|
||||||
|
# FIXED: Better network initialization
|
||||||
|
systemd.services.container-network-setup = {
|
||||||
|
wantedBy = [ "network.target" ];
|
||||||
|
before = [ "network-online.target" ];
|
||||||
|
script = ''
|
||||||
|
# Ensure proper routing
|
||||||
|
${pkgs.iproute2}/bin/ip route add default via 192.168.100.1 dev eth0 || true
|
||||||
|
# Set up DNS
|
||||||
|
echo "nameserver 8.8.8.8" > /etc/resolv.conf
|
||||||
|
echo "nameserver 1.1.1.1" >> /etc/resolv.conf
|
||||||
|
'';
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
systemd.services.workshop-setup = {
|
systemd.services.workshop-setup = {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "docker.service" ];
|
after = [ "network-online.target" "docker.service" "container-network-setup.service" ];
|
||||||
|
wants = [ "network-online.target" ];
|
||||||
script = ''
|
script = ''
|
||||||
export HOME=/root;
|
export HOME=/root
|
||||||
${pkgs.docker}/bin/docker swarm init --advertise-addr 192.168.100.${toString (10 + i)} || true;
|
export PATH=/run/current-system/sw/bin:$PATH
|
||||||
${pkgs.curl}/bin/curl -fsSL https://install.abra.coopcloud.tech | ${pkgs.bash}/bin/bash;
|
|
||||||
/root/.local/bin/abra server add ${participant}.local;
|
# Wait for network with better test
|
||||||
|
echo "Testing network connectivity..."
|
||||||
|
for attempt in {1..30}; do
|
||||||
|
if ${pkgs.curl}/bin/curl -s --max-time 10 --connect-timeout 5 https://install.abra.coopcloud.tech >/dev/null 2>&1; then
|
||||||
|
echo "Network is up!"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
echo "Attempt $attempt: Waiting for network..."
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
# Docker swarm init
|
||||||
|
${pkgs.docker}/bin/docker swarm init --advertise-addr 192.168.100.${toString (10 + i)} || true
|
||||||
|
|
||||||
|
# Install abra
|
||||||
|
if [ ! -f /root/.local/bin/abra ]; then
|
||||||
|
echo "Installing abra..."
|
||||||
|
${pkgs.curl}/bin/curl -fsSL https://install.abra.coopcloud.tech | ${pkgs.bash}/bin/bash
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Make abra globally available
|
||||||
|
if [ -f /root/.local/bin/abra ]; then
|
||||||
|
ln -sf /root/.local/bin/abra /usr/local/bin/abra || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add server
|
||||||
|
if command -v abra >/dev/null 2>&1; then
|
||||||
|
abra server add ${participant}.local || true
|
||||||
|
fi
|
||||||
'';
|
'';
|
||||||
serviceConfig = { Type = "oneshot"; RemainAfterExit = true; };
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
|
StandardOutput = "journal";
|
||||||
|
StandardError = "journal";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
environment.sessionVariables = {
|
||||||
|
PATH = [ "/root/.local/bin" "$PATH" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
) participantRange);
|
) participantRange);
|
||||||
|
|
||||||
|
# DNS for .local domains
|
||||||
services.dnsmasq = {
|
services.dnsmasq = {
|
||||||
enable = true;
|
enable = true;
|
||||||
settings.address = builtins.concatMap (i:
|
settings = {
|
||||||
|
address = builtins.concatMap (i:
|
||||||
let participant = builtins.elemAt fullParticipantNames (i - 1);
|
let participant = builtins.elemAt fullParticipantNames (i - 1);
|
||||||
in [ "/${participant}.local/192.168.100.${toString (10 + i)}" ]
|
in [ "/${participant}.local/192.168.100.${toString (10 + i)}" ]
|
||||||
) participantRange;
|
) participantRange;
|
||||||
|
server = [ "8.8.8.8" "1.1.1.1" ];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user