Skip to content

Instantly share code, notes, and snippets.

@joehealy
Last active September 14, 2020 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joehealy/d6e8d1d2ea5c47eb9d791346afbec4a3 to your computer and use it in GitHub Desktop.
Save joehealy/d6e8d1d2ea5c47eb9d791346afbec4a3 to your computer and use it in GitHub Desktop.
infinite recusion. Likely to do with line 73 and 39.
let
ppkgs_files = (builtins.fetchTarball {
# Descriptive name to make the store path easier to identify
name = "nixos-unstable-2020-07-03";
# Commit hash for nixos-unstable as of 2018-09-12
url =
"https://github.com/nixos/nixpkgs/archive/9a3e34ae60130c63b93809eecf555b0d796f001c.tar.gz";
# Hash obtained using `nix-prefetch-url --unpack <url>`
sha256 = "0azkaa2q4pp62icfs56s1hsmzpyzqafaw24v365n7qv9xffbk044";
});
buildVm = conf: (import "${ppkgs_files}/nixos" { configuration = conf; }).vm;
ppkgs = import "${ppkgs_files}" { };
myOverlay = self: super:
let writeJson = d: super.writeText "app-config.json" (builtins.toJSON d);
in rec {
inherit writeJson;
buildScheduledTask =
{ name, scriptContents, timeoutSec ? "3600", restartSec ? "10" }:
let
service = {
description = name;
startAt = "*:10";
script = "${runScript}/bin/runner";
serviceConfig = {
RuntimeMaxSec = timeoutSec;
RestartSec = restartSec;
};
};
runScript = super.writeShellScriptBin "runner" scriptContents;
nixosService = {
systemd = { services = { "${name}" = service; }; };
};
in {
service = nixosService;
scriptContents = runScript;
serviceContents = writeJson nixosService;
};
};
in {
infiniteMachine = buildVm ({ config, pkgs, ... }:
let
xx = pkgs.writeShellScriptBin "runStuff" ''
set +e
echo ${pkgs.writeText "app-config.json" (builtins.toJSON { ok = 42; })}
echo ${pkgs.writeJson yz.serviceContents}
'';
yz = pkgs.buildScheduledTask {
name = "testService2";
scriptContents = "echo doStuff";
};
in ({
environment.systemPackages = [ xx ];
nixpkgs.overlays = [ myOverlay ];
} // yz.service));
okMachine = buildVm ({ config, pkgs, ... }:
let
xx = pkgs.writeShellScriptBin "runStuff" ''
set +e
echo ${pkgs.writeText "app-config.json" (builtins.toJSON { ok = 42; })}
echo ${pkgs.writeJson yz.serviceContents}
'';
yz = pkgs.buildScheduledTask {
name = "testService2";
scriptContents = "echo doStuff";
};
in {
environment.systemPackages = [ xx ];
nixpkgs.overlays = [ myOverlay ];
});
}
@joehealy
Copy link
Author

nix-build vms.nix -A okMachine is fine, nix-build vms.nix -A infiniteMachine crashes with an infinite recursion error.

The issue seems to be the merging (//) of the results of a function that build a service that comes from an overlay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment