add oci target

This commit is contained in:
alisceon 2026-05-27 16:39:26 +02:00
parent 9cb871275a
commit 87cc464d1b
5 changed files with 131 additions and 14 deletions

2
.gitignore vendored
View file

@ -1,4 +1,4 @@
result result*
.stfolder .stfolder
flake.lock flake.lock

View file

@ -31,7 +31,6 @@
... ...
}: }:
let let
system = "x86_64-linux";
repoLocalPath = repoLocalPath =
let let
fromEnv = builtins.getEnv "NIXOS_CONFIG_ROOT"; fromEnv = builtins.getEnv "NIXOS_CONFIG_ROOT";
@ -42,26 +41,21 @@
inputs.nur.overlays.default inputs.nur.overlays.default
]; ];
pkgs = import nixpkgs { mkPkgs = system: import nixpkgs {
inherit system; inherit system;
config.allowUnfree = true; config.allowUnfree = true;
flake.setFlakeRegistry = true; flake.setFlakeRegistry = true;
inherit overlays; inherit overlays;
}; };
pkgs-unstable = import nixpkgs-unstable { mkPkgsUnstable = system: import nixpkgs-unstable {
inherit system; inherit system;
config.allowUnfree = true; config.allowUnfree = true;
flake.setFlakeRegistry = true; flake.setFlakeRegistry = true;
inherit overlays; inherit overlays;
}; };
sharedSpecialArgs = { mkSharedModules = pkgs: pkgs-unstable: [
inherit repoLocalPath pkgs-unstable;
repoRoot = self;
};
sharedModules = [
./nixos/modules/base.nix ./nixos/modules/base.nix
inputs.home-manager.nixosModules.home-manager inputs.home-manager.nixosModules.home-manager
({ ... }: { ({ ... }: {
@ -77,15 +71,23 @@
mkHost = { mkHost = {
hostName, hostName,
system,
nixosModules ? [ ], nixosModules ? [ ],
hmModules ? [ ], hmModules ? [ ],
extraModules ? [ ], extraModules ? [ ],
}: }:
let
pkgs = mkPkgs system;
pkgs-unstable = mkPkgsUnstable system;
in
nixpkgs.lib.nixosSystem { nixpkgs.lib.nixosSystem {
inherit system pkgs; inherit system pkgs;
specialArgs = sharedSpecialArgs; specialArgs = {
inherit repoLocalPath pkgs-unstable;
repoRoot = self;
};
modules = modules =
sharedModules (mkSharedModules pkgs pkgs-unstable)
++ [ (./nixos/hosts + "/${hostName}/configuration.nix") ] ++ [ (./nixos/hosts + "/${hostName}/configuration.nix") ]
++ nixosModules ++ nixosModules
++ extraModules ++ extraModules
@ -125,6 +127,7 @@
nixosConfigurations = { nixosConfigurations = {
electra = mkHost { electra = mkHost {
hostName = "electra"; hostName = "electra";
system = "x86_64-linux";
nixosModules = workstationModules; nixosModules = workstationModules;
hmModules = workstationHomeModules ++ [ hmModules = workstationHomeModules ++ [
./home/hosts/alisceon/electra.nix ./home/hosts/alisceon/electra.nix
@ -133,6 +136,7 @@
tower = mkHost { tower = mkHost {
hostName = "tower"; hostName = "tower";
system = "x86_64-linux";
nixosModules = workstationModules; nixosModules = workstationModules;
hmModules = workstationHomeModules ++ [ hmModules = workstationHomeModules ++ [
./home/hosts/alisceon/tower.nix ./home/hosts/alisceon/tower.nix
@ -141,6 +145,7 @@
tesla-nixos = mkHost { tesla-nixos = mkHost {
hostName = "tesla-nixos"; hostName = "tesla-nixos";
system = "x86_64-linux";
nixosModules = serverModules; nixosModules = serverModules;
hmModules = serverHomeModules; hmModules = serverHomeModules;
extraModules = [ extraModules = [
@ -151,6 +156,14 @@
nuc = mkHost { nuc = mkHost {
hostName = "nuc"; hostName = "nuc";
system = "x86_64-linux";
nixosModules = serverModules;
hmModules = serverHomeModules;
};
oci-a1 = mkHost {
hostName = "oci-a1";
system = "aarch64-linux";
nixosModules = serverModules; nixosModules = serverModules;
hmModules = serverHomeModules; hmModules = serverHomeModules;
}; };

View file

@ -34,6 +34,10 @@
hostname = "oci.malice.zone"; hostname = "oci.malice.zone";
user = "opc"; user = "opc";
}; };
"oci-a1" = {
hostname = "oci-a1";
user = "alisceon";
};
"dnspi" = { "dnspi" = {
hostname = "10.40.0.2"; hostname = "10.40.0.2";
user = "pi"; user = "pi";

View file

@ -0,0 +1,99 @@
{ lib, pkgs, modulesPath, ... }:
let
fetchOciAuthorizedKeys = pkgs.writeShellApplication {
name = "fetch-oci-authorized-keys";
runtimeInputs = [
pkgs.coreutils
pkgs.curl
];
text = ''
install -d -m 0700 -o alisceon -g users /home/alisceon/.ssh
if [ -s /home/alisceon/.ssh/authorized_keys ]; then
echo "OCI authorized_keys already present for alisceon"
exit 0
fi
curl --fail --silent --show-error --location \
--header "Authorization: Bearer Oracle" \
--output /home/alisceon/.ssh/authorized_keys \
http://169.254.169.254/opc/v2/instance/metadata/ssh_authorized_keys
chown alisceon:users /home/alisceon/.ssh/authorized_keys
chmod 0600 /home/alisceon/.ssh/authorized_keys
'';
};
in
{
imports = [
"${modulesPath}/virtualisation/oci-image.nix"
];
nixpkgs.hostPlatform = lib.mkDefault "aarch64-linux";
networking = {
hostName = "nixos-oci-a1";
networkmanager.enable = lib.mkForce false;
};
boot.initrd.availableKernelModules = [
"virtio_pci"
"virtio_blk"
"virtio_scsi"
"virtio_net"
"xhci_pci"
];
users.users.alisceon.extraGroups = [ "systemd-journal" ];
security.sudo-rs.wheelNeedsPassword = false;
services.openssh.settings = {
PasswordAuthentication = false;
PermitRootLogin = lib.mkForce "prohibit-password";
};
services.cloud-init = {
enable = true;
network.enable = true;
settings = {
datasource_list = [ "Oracle" "ConfigDrive" "NoCloud" ];
users = [ "default" ];
system_info.default_user = {
name = "alisceon";
gecos = "Alisceon";
groups = [ "wheel" "systemd-journal" ];
shell = "/run/current-system/sw/bin/xonsh";
lock_passwd = true;
};
};
};
systemd.services.fetch-oci-authorized-keys = {
description = "Fetch OCI metadata authorized_keys for alisceon";
wantedBy = [ "sshd.service" ];
before = [ "sshd.service" ];
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
StandardError = "journal+console";
StandardOutput = "journal+console";
};
script = lib.getExe fetchOciAuthorizedKeys;
};
systemd.services.fetch-ssh-keys.enable = false;
environment.systemPackages = with pkgs; [
curl
git
htop
jq
vim
wget
];
system.stateVersion = lib.mkForce "25.11";
}

View file

@ -19,6 +19,7 @@ in
"udev.log_level=3" "udev.log_level=3"
"systemd.show_status=auto" "systemd.show_status=auto"
]; ];
binfmt.emulatedSystems = [ "aarch64-linux" ];
}; };
security.sudo.wheelNeedsPassword = false; security.sudo.wheelNeedsPassword = false;