Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux-builder: Add ephemeral option to delete VM's disk image on service restart #850

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions modules/nix/linux-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ let
rm -rf $TMPDIR
mkdir -p $TMPDIR
trap "rm -rf $TMPDIR" EXIT
${lib.optionalString cfg.ephemeral ''
rm -f ${cfg.workingDirectory}/${builderWithOverrides.nixosConfig.networking.hostName}.qcow2
''}
${builderWithOverrides}/bin/create-builder
'';
in
Expand Down Expand Up @@ -77,6 +80,22 @@ in
This sets the corresponding `nix.buildMachines.*.supportedFeatures` option.
'';
};

workingDirectory = mkOption {
type = types.str;
default = "/var/lib/darwin-builder";
description = lib.mdDoc ''
The working directory of the Linux builder daemon process.
'';
};

ephemeral = mkEnableOption (lib.mdDoc ''
wipe the builder's filesystem on every restart.

This is disabled by default as maintaining the builder's Nix Store reduces
rebuilds. You can enable this if you don't want your builder to accumulate
state.
'');
};

config = mkIf cfg.enable {
Expand All @@ -89,7 +108,7 @@ in
} ];

system.activationScripts.preActivation.text = ''
mkdir -p /var/lib/darwin-builder
mkdir -p ${cfg.workingDirectory}
'';

launchd.daemons.linux-builder = {
Expand All @@ -103,7 +122,7 @@ in
];
KeepAlive = true;
RunAtLoad = true;
WorkingDirectory = "/var/lib/darwin-builder";
WorkingDirectory = cfg.workingDirectory;
};
};

Expand Down