Skip to content

Commit

Permalink
refactor: use script rather than command in daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
will-lol committed Sep 21, 2024
1 parent 86fb601 commit 10c4d1f
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions modules/nix/linux-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,6 @@ with lib;

let
cfg = config.nix.linux-builder;

# create-builder uses TMPDIR to share files with the builder, notably certs.
# macOS will clean up files in /tmp automatically that haven't been accessed in 3+ days.
# If we let it use /tmp, leaving the computer asleep for 3 days makes the certs vanish.
# So we'll use /run/org.nixos.linux-builder instead and clean it up ourselves.
script = pkgs.writeShellScript "linux-builder-start" ''
export TMPDIR=/run/org.nixos.linux-builder USE_TMPDIR=1
rm -rf $TMPDIR
mkdir -p $TMPDIR
trap "rm -rf $TMPDIR" EXIT
${lib.optionalString cfg.ephemeral ''
rm -f ${cfg.workingDirectory}/${cfg.package.nixosConfig.networking.hostName}.qcow2
''}
${cfg.package}/bin/create-builder
'';
in

{
Expand Down Expand Up @@ -176,7 +161,22 @@ in
environment = {
inherit (config.environment.variables) NIX_SSL_CERT_FILE;
};
command = "${script}";

# create-builder uses TMPDIR to share files with the builder, notably certs.
# macOS will clean up files in /tmp automatically that haven't been accessed in 3+ days.
# If we let it use /tmp, leaving the computer asleep for 3 days makes the certs vanish.
# So we'll use /run/org.nixos.linux-builder instead and clean it up ourselves.
script = ''
export TMPDIR=/run/org.nixos.linux-builder USE_TMPDIR=1
rm -rf $TMPDIR
mkdir -p $TMPDIR
trap "rm -rf $TMPDIR" EXIT
${lib.optionalString cfg.ephemeral ''
rm -f ${cfg.workingDirectory}/${cfg.package.nixosConfig.networking.hostName}.qcow2
''}
${cfg.package}/bin/create-builder
'';

serviceConfig = {
KeepAlive = true;
RunAtLoad = true;
Expand Down

0 comments on commit 10c4d1f

Please sign in to comment.