mirror of
https://gitlab.com/upRootNutrition/dotfiles.git
synced 2025-12-06 21:17:14 -06:00
146 lines
4.5 KiB
Nix
146 lines
4.5 KiB
Nix
{
|
|
flake,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
inherit (flake.config.people) user0;
|
|
in
|
|
{
|
|
microvm = {
|
|
vms = {
|
|
miner = {
|
|
autostart = true;
|
|
config =
|
|
let
|
|
macAddress = "02:00:00:00:00:57";
|
|
workers = 45;
|
|
in
|
|
{
|
|
environment.systemPackages = [
|
|
pkgs.git
|
|
pkgs.ncurses
|
|
pkgs.python313
|
|
];
|
|
|
|
microvm = {
|
|
forwardPorts = [
|
|
{
|
|
from = "host";
|
|
host.port = 2057;
|
|
guest.port = 22;
|
|
}
|
|
];
|
|
hypervisor = "qemu";
|
|
interfaces = [
|
|
{
|
|
type = "tap";
|
|
id = "vm-miner";
|
|
mac = "02:00:00:00:57:57";
|
|
}
|
|
{
|
|
type = "user";
|
|
id = "uservm-miner";
|
|
mac = macAddress;
|
|
}
|
|
];
|
|
mem = 52100;
|
|
shares = [
|
|
{
|
|
mountPoint = "/nix/.ro-store";
|
|
proto = "virtiofs";
|
|
source = "/nix/store";
|
|
tag = "read_only_nix_store";
|
|
}
|
|
{
|
|
mountPoint = "/var/lib/midnight-data";
|
|
proto = "virtiofs";
|
|
source = "/var/lib/midnight-data";
|
|
tag = "midnight_data";
|
|
}
|
|
];
|
|
vcpu = workers;
|
|
};
|
|
|
|
networking.firewall.allowedTCPPorts = [
|
|
22
|
|
];
|
|
|
|
services = {
|
|
openssh = {
|
|
enable = true;
|
|
settings.PasswordAuthentication = false;
|
|
};
|
|
};
|
|
|
|
system.stateVersion = "25.05";
|
|
|
|
systemd = {
|
|
network = {
|
|
enable = true;
|
|
networks."20-user" = {
|
|
matchConfig.MACAddress = macAddress;
|
|
networkConfig = {
|
|
DHCP = "yes";
|
|
};
|
|
};
|
|
};
|
|
|
|
tmpfiles.rules = [
|
|
"d /var/lib/midnight-data 0755 root root - -"
|
|
];
|
|
|
|
services = {
|
|
midnight-miner = {
|
|
after = [ "network-online.target" ];
|
|
description = "MidnightMiner - Cardano NIGHT token miner";
|
|
serviceConfig = {
|
|
Environment = [
|
|
"PATH=/run/current-system/sw/bin"
|
|
"TERM=xterm-256color"
|
|
];
|
|
ExecStartPre = pkgs.writeShellScript "setup-miner" ''
|
|
# Create venv if not already present (persists on virtiofs mount)
|
|
if [ ! -d /var/lib/midnight-data/venv ]; then
|
|
${pkgs.python313}/bin/python -m venv /var/lib/midnight-data/venv
|
|
fi
|
|
|
|
# Install/upgrade dependencies
|
|
/var/lib/midnight-data/venv/bin/pip install --upgrade pip
|
|
/var/lib/midnight-data/venv/bin/pip install requests pycardano cbor2 portalocker
|
|
|
|
# Clone repo if not already present
|
|
if [ ! -d /var/lib/midnight-data/MidnightMiner ]; then
|
|
cd /var/lib/midnight-data
|
|
${pkgs.git}/bin/git clone https://github.com/djeanql/MidnightMiner.git
|
|
else
|
|
cd /var/lib/midnight-data/MidnightMiner
|
|
${pkgs.git}/bin/git pull
|
|
fi
|
|
'';
|
|
ExecStart = pkgs.writeShellScript "run-miner" ''
|
|
export PATH=/run/current-system/sw/bin:$PATH
|
|
cd /var/lib/midnight-data/MidnightMiner
|
|
/var/lib/midnight-data/venv/bin/python miner.py --workers ${toString workers} --no-donation
|
|
'';
|
|
Restart = "always";
|
|
RestartSec = 10;
|
|
};
|
|
wants = [ "network-online.target" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
};
|
|
};
|
|
};
|
|
|
|
time.timeZone = "America/Winnipeg";
|
|
|
|
users.users.root.openssh.authorizedKeys.keys = flake.config.people.users.${user0}.sshKeys;
|
|
|
|
};
|
|
};
|
|
};
|
|
};
|
|
systemd.tmpfiles.rules = [
|
|
"d /var/lib/midnight-data 0751 microvm wheel - -"
|
|
];
|
|
}
|