2021-04-17 19:09:25 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
2021-05-29 02:00:37 +00:00
|
|
|
let
|
|
|
|
cfg = config.oci;
|
|
|
|
in
|
2021-04-17 19:09:25 +00:00
|
|
|
{
|
|
|
|
imports = [ ./oci-common.nix ];
|
|
|
|
|
|
|
|
config = {
|
2024-09-10 17:14:43 +00:00
|
|
|
# Use a priority just below mkOptionDefault (1500) instead of lib.mkDefault
|
|
|
|
# to avoid breaking existing configs using that.
|
|
|
|
virtualisation.diskSize = lib.mkOverride 1490 (8 * 1024);
|
|
|
|
virtualisation.diskSizeAutoSupported = false;
|
|
|
|
|
2021-04-17 19:09:25 +00:00
|
|
|
system.build.OCIImage = import ../../lib/make-disk-image.nix {
|
|
|
|
inherit config lib pkgs;
|
2024-09-10 17:14:43 +00:00
|
|
|
inherit (config.virtualisation) diskSize;
|
2021-04-17 19:09:25 +00:00
|
|
|
name = "oci-image";
|
|
|
|
configFile = ./oci-config-user.nix;
|
|
|
|
format = "qcow2";
|
2021-05-29 02:00:37 +00:00
|
|
|
partitionTableType = if cfg.efi then "efi" else "legacy";
|
2021-04-17 19:09:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.fetch-ssh-keys = {
|
|
|
|
description = "Fetch authorized_keys for root user";
|
|
|
|
|
|
|
|
wantedBy = [ "sshd.service" ];
|
|
|
|
before = [ "sshd.service" ];
|
|
|
|
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
|
|
|
|
path = [
|
|
|
|
pkgs.coreutils
|
|
|
|
pkgs.curl
|
|
|
|
];
|
|
|
|
script = ''
|
|
|
|
mkdir -m 0700 -p /root/.ssh
|
|
|
|
if [ -f /root/.ssh/authorized_keys ]; then
|
|
|
|
echo "Authorized keys have already been downloaded"
|
|
|
|
else
|
|
|
|
echo "Downloading authorized keys from Instance Metadata Service v2"
|
|
|
|
curl -s -S -L \
|
|
|
|
-H "Authorization: Bearer Oracle" \
|
|
|
|
-o /root/.ssh/authorized_keys \
|
|
|
|
http://169.254.169.254/opc/v2/instance/metadata/ssh_authorized_keys
|
|
|
|
chmod 600 /root/.ssh/authorized_keys
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
StandardError = "journal+console";
|
|
|
|
StandardOutput = "journal+console";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|