Skip to content

Commit

Permalink
refact: rename machines to setups
Browse files Browse the repository at this point in the history
  • Loading branch information
klarkc committed Dec 19, 2023
1 parent b4505b7 commit 053c862
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 69 deletions.
37 changes: 14 additions & 23 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,35 @@
nixosGenerate options
else
nixosSystem options;
# TODO: find a faster way to run vm in devShell
mkVirtualMachine = efi: name: args: pkgs.writeShellApplication {
name = "${name}-vm";
# disable spellcheck to build a command line
excludeShellChecks = [ "SC2086" ];
vm = name: pkgs.writeShellApplication {
inherit name;
text = ''
IMG="${name}-efi.img"
BIOS="${name}-efi-bios.img"
ARGS="${args}"
cp -ui --reflink=auto ${pkgs.OVMF.fd}/FV/OVMF.fd "$BIOS"
chmod a+w "$BIOS"
cp -ui --reflink=auto ${efi}/nixos.img "$IMG"
chmod a+w "$IMG"
qemu-system-${platform} \
-bios "$BIOS" \
-drive file="$IMG",format=raw \
-m 2G \
$ARGS
export USE_TMPDIR=0
${self.nixosConfigurations.${name}.config.formats.vm-nogui}
'';
runtimeInputs = with pkgs; [ qemu ];
};
};
machines = import ./machines {
setups = import ./setups {
inherit system pkgs;
flake = self;
};
in
{
inherit lib;

nixosModules = {
inherit (setups.recover.modules) recover;
inherit (setups.cache.modules) cache;
};

nixosConfigurations = {
inherit (machines.recover) recover-os;
inherit (machines.cache) cache-os;
inherit (setups.recover.machines) recover_0;
inherit (setups.cache.machines) cache_0;
};

packages.${system} = {
inherit (machines.recover) recover-efi recover-vm recover-kvm;
inherit (machines.cache) cache-efi cache-vm cache-kvm;
inherit (setups.recover.packages) recover-efi recover-vm;
inherit (setups.cache.packages) cache-vm;
};
};

Expand Down
43 changes: 13 additions & 30 deletions machines/cache/default.nix → setups/cache/default.nix
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
{ system, pkgs, flake, ... }:
let
inherit (pkgs.lib) mkDefault;
inherit (flake.inputs.everyday.nixosModules) logger;
inherit (flake.inputs.attic.nixosModules) atticd;
inherit (flake.outputs.lib) mkSystem mkVirtualMachine;
inherit (flake.outputs.lib) mkSystem vm;
domain = "cache.klarkc.is-a.dev";
cache-module = { config, ... }: {
system.stateVersion = config.system.nixos.version;
imports = [ logger atticd ];
networking = {
hostName = "cache-os";
networkmanager.enable = true;
};
boot = {
kernelParams = [
"console=ttyS0,115200"
"console=tty1"
];
loader.grub = {
enable = true;
device = "nodev";
efiSupport = true;
useOSProber = true;
};
};
fileSystems."/".device = mkDefault "none";

fileSystems."/".device = "none";
boot.loader.grub.device = "nodev";
services.atticd = {
enable = true;
# echo -n 'ATTIC_SERVER_TOKEN_HS256_SECRET_BASE64="' > /tmp/atticd.env
Expand Down Expand Up @@ -57,18 +41,17 @@ let
};
in
rec {
cache-os = mkSystem {
inherit system;
modules = [ cache-module ];
};
modules.cache = cache-module;

cache-efi = mkSystem {
machines.cache_0 = mkSystem {
inherit system;
modules = [ cache-module ];
format = "raw-efi";
modules = [
cache-module
{
networking.hostName = "cache_0";
}
];
};

cache-vm = mkVirtualMachine cache-efi "cache" "--nographic";

cache-kvm = mkVirtualMachine cache-efi "cache" "--nographic --enable-kvm";
packages.cache-vm = vm "cache_0";
}
File renamed without changes.
37 changes: 21 additions & 16 deletions machines/recover/default.nix → setups/recover/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{ system, pkgs, flake, ... }:
let
inherit (pkgs.lib) mkDefault;
inherit (flake.outputs.lib) mkSystem mkVirtualMachine;
recover-module = {
inherit (pkgs.lib) mkDefault version;
inherit (flake.outputs.lib) mkSystem vm;
recover-module = { config, ...}: {
system.stateVersion = config.system.nixos.version;
nix = {
extraOptions = ''
experimental-features = nix-command flakes repl-flake
Expand All @@ -20,10 +21,7 @@ let
};
mutableUsers = false;
};
networking = {
hostName = "recover-os";
networkmanager.enable = true;
};
networking.networkmanager.enable = true;
boot = {
kernelParams = [
"copytoram"
Expand Down Expand Up @@ -121,18 +119,25 @@ let
};
in
rec {
recover-os = mkSystem {
inherit system;
modules = [ recover-module ];
};
modules.recover = recover-module;

recover-efi = mkSystem {
machines.recover_0 = mkSystem {
inherit system;
modules = [ recover-module ];
format = "raw-efi";
modules = [
recover-module
{
networking.hostName = "recover_0";
}
];
};

recover-vm = mkVirtualMachine recover-efi "recover" "";
packages = {
recover-efi = mkSystem {
inherit system;
modules = [ recover-module ];
format = "raw-efi";
};

recover-kvm = mkVirtualMachine recover-efi "recover" "--enable-kvm";
recover-vm = vm "recover_0";
};
}

0 comments on commit 053c862

Please sign in to comment.