Files
machine_setup/nix/configuration/roles/robot/default.nix
2026-11-19 17:16:43 -05:00

82 lines
1.8 KiB
Nix

{
config,
lib,
pkgs,
self,
...
}:
let
patchScriptBin =
filename: contents:
((pkgs.writeScriptBin filename contents).overrideAttrs (old: {
buildCommand = "${old.buildCommand}\n patchShebangs $out";
}));
launch_robot_script = (
patchScriptBin "launch_robot" (
builtins.readFile (
pkgs.replaceVars ./files/robot/launch_robot.bash (
let
robot_image_package = self.packages.${pkgs.system}.robot.vm_iso;
robot_image = "${robot_image_package}/iso/${robot_image_package.isoName}";
in
{
"OVMFfd" = "${pkgs.OVMF.fd}";
"mountiso" = robot_image;
}
)
)
)
);
launch_robot_script_wrapped =
(pkgs.writeScriptBin "launch_robot" ''
#!/usr/bin/env bash
export "PATH=${
pkgs.lib.makeBinPath (
with pkgs;
[
qemu
]
)
}:''${PATH}"
exec ${launch_robot_script}/bin/launch_robot "''${@}"
'').overrideAttrs
(old: {
buildCommand = ''
${old.buildCommand}
patchShebangs $out
'';
});
in
{
imports = [ ];
options.me = {
robot.enable = lib.mkOption {
type = lib.types.bool;
default = false;
example = true;
description = "Whether we want to install robot.";
};
};
config = lib.mkIf config.me.robot.enable {
environment.systemPackages = with pkgs; [
launch_robot_script_wrapped
];
environment.persistence."/persist" = lib.mkIf (config.me.mountPersistence) {
hideMounts = true;
directories = [
{
directory = "/robot";
user = "talexander";
group = "talexander";
mode = "0700";
}
];
};
};
}