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
Remove cloud-init from the Openstack image configuration #54800
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2858b35
nova-image: use wget instead of cloud-init (via EC2 API)
nlewo 849460f
nova-image: add amazon-init module to the nova image
nlewo d190b20
Rename `novaImage` to `openstackImage`
nlewo 78acac0
nixos/openstackImage: default hostname is empty string
nlewo 933da6d
nixos: Add ec2-metadata-fetcher.nix file
nlewo ff31014
nixos/tests/ec2: reuse ssh keys from ssh-keys.nix
nlewo File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# nix-build '<nixpkgs/nixos>' -A config.system.build.openstackImage --arg configuration "{ imports = [ ./nixos/maintainers/scripts/openstack/openstack-image.nix ]; }" | ||
|
||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
|
||
{ | ||
imports = | ||
[ ../../../modules/installer/cd-dvd/channel.nix | ||
../../../modules/virtualisation/openstack-config.nix | ||
]; | ||
|
||
system.build.openstackImage = import ../../../lib/make-disk-image.nix { | ||
inherit lib config; | ||
pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package | ||
diskSize = 8192; | ||
format = "qcow2"; | ||
configFile = pkgs.writeText "configuration.nix" | ||
'' | ||
{ | ||
imports = [ <nixpkgs/nixos/modules/virtualisation/openstack-config.nix> ]; | ||
} | ||
''; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ targetRoot, wgetExtraOptions }: | ||
'' | ||
metaDir=${targetRoot}etc/ec2-metadata | ||
mkdir -m 0755 -p "$metaDir" | ||
|
||
echo "getting EC2 instance metadata..." | ||
|
||
if ! [ -e "$metaDir/ami-manifest-path" ]; then | ||
wget ${wgetExtraOptions} -O "$metaDir/ami-manifest-path" http://169.254.169.254/1.0/meta-data/ami-manifest-path | ||
fi | ||
|
||
if ! [ -e "$metaDir/user-data" ]; then | ||
wget ${wgetExtraOptions} -O "$metaDir/user-data" http://169.254.169.254/1.0/user-data && chmod 600 "$metaDir/user-data" | ||
fi | ||
|
||
if ! [ -e "$metaDir/hostname" ]; then | ||
wget ${wgetExtraOptions} -O "$metaDir/hostname" http://169.254.169.254/1.0/meta-data/hostname | ||
fi | ||
|
||
if ! [ -e "$metaDir/public-keys-0-openssh-key" ]; then | ||
wget ${wgetExtraOptions} -O "$metaDir/public-keys-0-openssh-key" http://169.254.169.254/1.0/meta-data/public-keys/0/openssh-key | ||
fi | ||
'' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ pkgs, lib, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
metadataFetcher = import ./ec2-metadata-fetcher.nix { | ||
targetRoot = "/"; | ||
wgetExtraOptions = "--retry-connrefused"; | ||
}; | ||
in | ||
{ | ||
imports = [ | ||
../profiles/qemu-guest.nix | ||
../profiles/headless.nix | ||
# The Openstack Metadata service exposes data on an EC2 API also. | ||
./ec2-data.nix | ||
./amazon-init.nix | ||
]; | ||
|
||
config = { | ||
fileSystems."/" = { | ||
device = "/dev/disk/by-label/nixos"; | ||
autoResize = true; | ||
}; | ||
|
||
boot.growPartition = true; | ||
boot.kernelParams = [ "console=ttyS0" ]; | ||
boot.loader.grub.device = "/dev/vda"; | ||
boot.loader.timeout = 0; | ||
|
||
# Allow root logins | ||
services.openssh = { | ||
enable = true; | ||
permitRootLogin = "prohibit-password"; | ||
passwordAuthentication = mkDefault false; | ||
}; | ||
|
||
# Force getting the hostname from Openstack metadata. | ||
networking.hostName = mkDefault ""; | ||
|
||
systemd.services.openstack-init = { | ||
path = [ pkgs.wget ]; | ||
description = "Fetch Metadata on startup"; | ||
wantedBy = [ "multi-user.target" ]; | ||
before = [ "apply-ec2-data.service" "amazon-init.service"]; | ||
wants = [ "network-online.target" ]; | ||
after = [ "network-online.target" ]; | ||
script = metadataFetcher; | ||
restartIfChanged = false; | ||
unitConfig.X-StopOnRemoval = false; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
RemainAfterExit = true; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ pkgs, makeTest }: | ||
|
||
with pkgs.lib; | ||
|
||
{ | ||
makeEc2Test = { name, image, userData, script, hostname ? "ec2-instance", sshPublicKey ? null }: | ||
let | ||
metaData = pkgs.stdenv.mkDerivation { | ||
name = "metadata"; | ||
buildCommand = '' | ||
mkdir -p $out/1.0/meta-data | ||
ln -s ${pkgs.writeText "userData" userData} $out/1.0/user-data | ||
echo "${hostname}" > $out/1.0/meta-data/hostname | ||
echo "(unknown)" > $out/1.0/meta-data/ami-manifest-path | ||
'' + optionalString (sshPublicKey != null) '' | ||
mkdir -p $out/1.0/meta-data/public-keys/0 | ||
ln -s ${pkgs.writeText "sshPublicKey" sshPublicKey} $out/1.0/meta-data/public-keys/0/openssh-key | ||
''; | ||
}; | ||
in makeTest { | ||
name = "ec2-" + name; | ||
nodes = {}; | ||
testScript = | ||
'' | ||
my $imageDir = ($ENV{'TMPDIR'} // "/tmp") . "/vm-state-machine"; | ||
mkdir $imageDir, 0700; | ||
my $diskImage = "$imageDir/machine.qcow2"; | ||
system("qemu-img create -f qcow2 -o backing_file=${image}/nixos.qcow2 $diskImage") == 0 or die; | ||
system("qemu-img resize $diskImage 10G") == 0 or die; | ||
|
||
# Note: we use net=169.0.0.0/8 rather than | ||
# net=169.254.0.0/16 to prevent dhcpcd from getting horribly | ||
# confused. (It would get a DHCP lease in the 169.254.* | ||
# range, which it would then configure and prompty delete | ||
# again when it deletes link-local addresses.) Ideally we'd | ||
# turn off the DHCP server, but qemu does not have an option | ||
# to do that. | ||
my $startCommand = "qemu-kvm -m 768"; | ||
$startCommand .= " -device virtio-net-pci,netdev=vlan0"; | ||
$startCommand .= " -netdev 'user,id=vlan0,net=169.0.0.0/8,guestfwd=tcp:169.254.169.254:80-cmd:${pkgs.micro-httpd}/bin/micro_httpd ${metaData}'"; | ||
$startCommand .= " -drive file=$diskImage,if=virtio,werror=report"; | ||
$startCommand .= " \$QEMU_OPTS"; | ||
|
||
my $machine = createMachine({ startCommand => $startCommand }); | ||
|
||
${script} | ||
''; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lassulus this might need a fix in https://github.com/nix-community/nixos-generators too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could do it.
I also plan to send a post on discourse to ask for some help to publish this image on the NixOS download page.