Skip to content

Commit

Permalink
A new re-build - a messy state
Browse files Browse the repository at this point in the history
Lot going on in here that I have not yet taken
time to understand; however, in this state the
build completes.

Of note, the homemanager configuration is
disabled because it currently fails.

This version borrows more from mitchellh/nixos-config
even in cases where I know I don't want
a package in order to get the build to
work. It appears I went my own path on
the previous build. This time I wanted
to have a working build quickly which
meant I needed to start with someone
elses build.
  • Loading branch information
Jason Wieringa authored and Jason Wieringa committed Jan 15, 2025
1 parent 0306920 commit 23f921b
Show file tree
Hide file tree
Showing 16 changed files with 715 additions and 339 deletions.
50 changes: 34 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Connectivity info for Linux VM
NIXADDR ?= unset
NIXPORT ?= 22
NIXUSER ?= root
Expand All @@ -7,39 +6,58 @@ NIXUSER ?= root
MAKEFILE_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))

# The name of the nixosConfiguration in the flake
NIXNAME ?= vm-intel
NIXNAME ?= vm-aarch64

# SSH options that are used. These aren't meant to be overridden but are
# reused a lot so we just store them up here.
SSH_OPTIONS=-o PubkeyAuthentication=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no

vm/bootstrap0:
ssh $(SSH_OPTIONS) -p$(NIXPORT) root@$(NIXADDR) " \
parted /dev/nvme0n1 -- mklabel gpt; \
parted /dev/nvme0n1 -- mkpart primary 512MiB -8GiB; \
parted /dev/nvme0n1 -- mkpart primary linux-swap -8GiB 100\%; \
parted /dev/nvme0n1 -- mkpart ESP fat32 1MiB 512MiB; \
parted /dev/nvme0n1 -- set 3 esp on; \
sleep 1; \
mkfs.ext4 -L nixos /dev/nvme0n1p1; \
mkswap -L swap /dev/nvme0n1p2; \
mkfs.fat -F 32 -n boot /dev/nvme0n1p3; \
sleep 1; \
mount /dev/disk/by-label/nixos /mnt; \
mkdir -p /mnt/boot; \
mount /dev/disk/by-label/boot /mnt/boot; \
nixos-generate-config --root /mnt; \
sed --in-place '/system\.stateVersion = .*/a \
nix.extraOptions = \"experimental-features = nix-command flakes\";\n \
services.openssh.enable = true;\n \
services.openssh.settings.PasswordAuthentication = true;\n \
services.openssh.settings.PermitRootLogin = \"yes\";\n \
users.users.root.initialPassword = \"root\";\n \
' /mnt/etc/nixos/configuration.nix; \
nixos-install --no-root-passwd && reboot; \
"

# bootstrap the vm. only run again on macos if the secrets change
vm/bootstrap:
NIXUSER=root $(MAKE) vm/copy
NIXUSER=root $(MAKE) vm/install
$(MAKE) vm/secrets
NIXUSER=root $(MAKE) vm/switch
# $(MAKE) vm/secrets

# copy our secrets into the VM
vm/secrets:
# SSH keys
rsync -av -e 'ssh $(SSH_OPTIONS)' \
--exclude='environment' \
$(HOME)/.ssh/ $(NIXUSER)@$(NIXADDR):~/.ssh

# copy the Nix configurations into the VM.
vm/copy:
rsync -av -e 'ssh $(SSH_OPTIONS) -p$(NIXPORT)' \
--exclude='vendor/' \
--exclude='.git/' \
--exclude='.git-crypt/' \
--exclude='iso/' \
--rsync-path="sudo rsync" \
$(MAKEFILE_DIR)/ $(NIXUSER)@$(NIXADDR):/nix-config

# run the nixos-install command. This does NOT copy files so you
# have to run vm/copy before.
vm/install:
vm/switch:
ssh $(SSH_OPTIONS) -p$(NIXPORT) $(NIXUSER)@$(NIXADDR) " \
sudo nix-shell \
--argstr systemName $(NIXNAME) \
/nix-config/bootstrap \
sudo NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nixos-rebuild switch --flake \"/nix-config#${NIXNAME}\" \
"

vm/reboot:
Expand Down
29 changes: 0 additions & 29 deletions bootstrap/default.nix

This file was deleted.

65 changes: 0 additions & 65 deletions flake.lock

This file was deleted.

66 changes: 42 additions & 24 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,39 +1,57 @@
# Credit: https://github.com/mitchellh/nixos-config/blob/501f9aa0a669479c34d8d036f52a15b04002d259/flake.nix
# Credit: https://github.com/mitchellh/nixos-config/blob/06b6eb4aa6f9817605f4d45a33331f4263e02d58/flake.nix

{
description = "Jason Wieringa's NixOS";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/release-22.11";
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";

neovim-nightly-overlay = {
url = "github:nix-community/neovim-nightly-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};

home-manager = {
url = "github:nix-community/home-manager/release-22.11";
url = "github:nix-community/home-manager/release-24.11";
inputs.nixpkgs.follows = "nixpkgs";
};

# Other packages
zig.url = "github:mitchellh/zig-overlay";
};

outputs = inputs@{ self, nixpkgs, home-manager, ... }: {
# This configuration would produce a vmdx for use in VMware.
#
# I tried to build a VMware image on Github actions, but they do not yet support
# nested virtualization (kvm). I'll need a place in CI to build the VM image to
# enable this workflow.
#
# packages.x86_64-linux = {
# vmwareImage = self.nixosConfigurations.vm-intel.config.system.build.vmwareImage;
# };

nixosConfigurations.vm-aarch64 = nixpkgs.lib.nixosSystem {
outputs = { self, nixpkgs, home-manager, ... }@inputs: let
overlays = [
inputs.zig.overlays.default

(final: prev: {
# gh CLI on stable has bugs.
gh = inputs.nixpkgs-unstable.legacyPackages.${prev.system}.gh;
})
];

mkSystem = import ./lib/mksystem.nix {
inherit overlays nixpkgs inputs;
};
in {
nixosConfigurations.vm-aarch64 = mkSystem "vm-aarch64" {
system = "aarch64-linux";
modules = [
./hardware/vm-aarch64.nix
./machines/vm-aarch64.nix
home-manager.nixosModules.home-manager {
home-manager.users.jason = import ./users/jason/home-manager.nix;
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
}
];
user = "jason";
};
};
}

# nixosConfigurations.vm-aarch64 = nixpkgs.lib.nixosSystem {
# system = "aarch64-linux";
# modules = [
# ./hardware/vm-aarch64.nix
# ./machines/vm-aarch64.nix
# home-manager.nixosModules.home-manager {
# home-manager.users.jason = import ./users/jason/home-manager.nix;
# home-manager.useGlobalPkgs = true;
# home-manager.useUserPackages = true;
# }
# ];
# };
# };
# }
34 changes: 0 additions & 34 deletions hardware/vm-aarch64.nix

This file was deleted.

52 changes: 52 additions & 0 deletions lib/mksystem.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This function creates a NixOS system based on our VM setup for a
# particular architecture.
{ nixpkgs, overlays, inputs }:

name:
{
system,
user,
}:

let
# The config files for this system.
machineConfig = ../machines/${name}.nix;
userOSConfig = ../users/${user}/nixos.nix;
# userHMConfig = ../users/${user}/home-manager.nix;

systemFunc = nixpkgs.lib.nixosSystem;
home-manager = inputs.home-manager.nixosModules;
in systemFunc rec {
inherit system;

modules = [
# Apply our overlays. Overlays are keyed by system type so we have
# to go through and apply our system type. We do this first so
# the overlays are available globally.
{ nixpkgs.overlays = overlays; }

# Allow unfree packages.
{ nixpkgs.config.allowUnfree = true; }

machineConfig
userOSConfig
# home-manager.home-manager {
# home-manager.useGlobalPkgs = true;
# home-manager.useUserPackages = true;
# home-manager.users.${user} = import userHMConfig {
# inputs = inputs;
# };
# }

# We expose some extra arguments so that our modules can parameterize
# better based on these values.
{
config._module.args = {
currentSystem = system;
currentSystemName = name;
currentSystemUser = user;
inputs = inputs;
};
}
];
}
7 changes: 7 additions & 0 deletions lib/overlays.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* This configures nixpkgs.overlays to include our overlays/ directory.
*/
let path = ../overlays; in with builtins;
map (n: import (path + ("/" + n)))
(filter (n: match ".*\\.nix" n != null ||
pathExists (path + ("/" + n + "/default.nix")))
(attrNames (readDir path)))
8 changes: 8 additions & 0 deletions machines/desktop/gnome.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ config, pkgs, lib, currentSystem, currentSystemName,... }: {
services.xserver = {
enable = true;
xkb.layout = "us";
desktopManager.gnome.enable = true;
displayManager.gdm.enable = true;
};
}
25 changes: 25 additions & 0 deletions machines/hardware/vm-aarch64.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Do not modify this file! It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }:

{
imports = [ ];

boot.initrd.availableKernelModules = [ "uhci_hcd" "ahci" "xhci_pci" "nvme" "usbhid" "sr_mod" ];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ ];
boot.extraModulePackages = [ ];

fileSystems."/" =
{ device = "/dev/disk/by-label/nixos";
fsType = "ext4";
};

fileSystems."/boot" =
{ device = "/dev/disk/by-label/boot";
fsType = "vfat";
};

swapDevices = [ ];
}
Loading

0 comments on commit 23f921b

Please sign in to comment.