{ pkgs, lib, config, ... }: let inherit (builtins) listToAttrs; inherit (lib) types; inherit (config) networking; cfg = config.install; in { options.install = { enable = lib.mkEnableOption "Install"; shellHook = lib.mkOption { type = types.lines; default = ""; }; shellScript = lib.mkOption { type = types.lines; default = ""; apply = pkgs.writeShellScriptBin "bash"; }; target = lib.mkOption { type = types.str; default = "root@${networking.hostName}.${networking.domain}"; }; generations = lib.mkOption { type = types.str; default = "+10"; }; profile = lib.mkOption { type = types.str; default = "/nix/var/nix/profiles/system"; }; }; config = lib.mkIf cfg.enable { install.shellScript = let nixos = config.system.build.toplevel; in '' PATH="$PATH:${with pkgs; lib.makeBinPath [nix openssh]}" set -x nix ''${TRACE:+-L} copy \ --to ssh://${cfg.target} --substitute-on-destination \ ${nixos} ssh ${cfg.target} nix-env --profile "${cfg.profile}" --set "${nixos}" \ '&&' nix-env --profile "${cfg.profile}" --delete-generations "${cfg.generations}" \ '&&' "${cfg.profile}"/bin/switch-to-configuration "''${switch:-switch}" ''; }; }