dotfiles/profiles/user0/files/misc/justfile.nix
2025-11-16 01:09:16 -06:00

65 lines
1.9 KiB
Nix
Executable file

{
flake,
config,
lib,
...
}:
let
inherit (flake.config.machines) devices;
inherit (flake.config.services) instances;
hostname = config.networking.hostName;
dotPath = "~/projects/dotfiles";
mkLocalRebuild = type: ''
${type}-rebuild:
nixos-rebuild ${type} --sudo --flake ${dotPath}#${hostname} --show-trace
'';
mkRemoteRebuild = name: ip: ''
${name}-rebuild:
nixos-rebuild switch --flake ${dotPath}#${name} --target-host ${ip} --sudo --ask-sudo-password --show-trace
'';
mkSshCommands = name: ip: ''
${name}-ssh:
ssh ${ip}
'';
mkMicrVMSshCommands = name: ssh: ''
${name}:
ssh -p ${builtins.toString ssh} root@localhost
'';
systemRecords =
command:
lib.concatStrings [
(command devices.ceres.name devices.ceres.ip.address0)
(command devices.eris.name devices.eris.ip.address0)
(command devices.mars.name devices.mars.ip.address0)
(command devices.deimos.name devices.deimos.ip.address0)
(command devices.phobos.name devices.phobos.ip.address0)
];
instanceRecords =
command:
lib.concatStrings [
(command instances.vaultwarden.name instances.vaultwarden.interface.ssh)
(command instances.jellyfin.name instances.jellyfin.interface.ssh)
(command instances.forgejo.name instances.forgejo.interface.ssh)
(command instances.firefly-iii.name instances.firefly-iii.interface.ssh)
(command instances.mastodon.name instances.mastodon.interface.ssh)
];
typeLabels =
type:
lib.concatStrings [
(type "switch")
(type "build")
(type "boot")
];
localRebuild = typeLabels mkLocalRebuild;
remoteRebuild = systemRecords mkRemoteRebuild;
sshCommand = systemRecords mkSshCommands;
microVMSshCommand = instanceRecords mkMicrVMSshCommands;
in
{
text = ''
${localRebuild}
${remoteRebuild}
${sshCommand}
${microVMSshCommand}
'';
}