big change
This commit is contained in:
@@ -1,21 +1,62 @@
|
||||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
gitRepoUrl = "https://git.skarockoi.de/ska/nixos-production.git";
|
||||
gitLocalPath = "/var/lib/nixos-config";
|
||||
in
|
||||
|
||||
{
|
||||
imports = [ ./hardware-configuration.nix ];
|
||||
# DO NOT import hardware-configuration.nix - we want hardware independence
|
||||
# imports = [ ./hardware-configuration.nix ];
|
||||
|
||||
# Boot configuration for physical machines
|
||||
boot.loader.systemd-boot.enable = true;
|
||||
boot.loader.efi.canTouchEfiVariables = true;
|
||||
boot.supportedFilesystems = [ "vfat" "ext4" "crypto_LUKS" ];
|
||||
|
||||
# Use LABELS instead of UUIDs for portable filesystem setup
|
||||
fileSystems."/" = {
|
||||
device = "/dev/disk/by-label/nixos-root";
|
||||
fsType = "ext4";
|
||||
options = [ "noatime" "nodiratime" ];
|
||||
};
|
||||
|
||||
fileSystems."/boot" = {
|
||||
device = "/dev/disk/by-label/nixos-boot";
|
||||
fsType = "vfat";
|
||||
options = [ "fmask=0077" "dmask=0077" ];
|
||||
};
|
||||
|
||||
# Generic kernel modules for maximum hardware compatibility
|
||||
boot.initrd.availableKernelModules = [
|
||||
"xhci_pci" "ehci_pci" "ohci_pci" "ahci" "usb_storage" "sd_mod" "sr_mod"
|
||||
"usbhid" "hid_generic" "hid_apple" "hid_logitech" "hid_cherry"
|
||||
"uas" "usb_storage" "nvme" "rtsx_pci_sdmmc"
|
||||
];
|
||||
|
||||
# First boot setup to handle machine-specific configuration
|
||||
boot.initrd.postDeviceCommands = pkgs.writeScript "first-boot-initrd" ''
|
||||
#!/usr/bin/env bash
|
||||
# Check if this is first boot on this hardware
|
||||
if [ ! -e /proc/first-boot-done ]; then
|
||||
echo "First boot detected - setting up hardware-specific configuration"
|
||||
|
||||
# Auto-detect LUKS device if not already set up
|
||||
if ! [ -e /dev/mapper/luks-root ]; then
|
||||
echo "No LUKS device found - attempting to find encrypted partition"
|
||||
for dev in /dev/sd* /dev/nvme* /dev/mmcblk*; do
|
||||
if cryptsetup isLuks "$dev" 2>/dev/null; then
|
||||
echo "Found LUKS partition on $dev"
|
||||
# This is a placeholder - actual decryption would happen interactively
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
'';
|
||||
|
||||
networking.hostName = "nixos-usb";
|
||||
networking.networkmanager.enable = true;
|
||||
|
||||
time.timeZone = "Europe/Berlin";
|
||||
|
||||
i18n.defaultLocale = "de_DE.UTF-8";
|
||||
i18n.extraLocaleSettings = {
|
||||
LC_ADDRESS = "de_DE.UTF-8";
|
||||
@@ -36,6 +77,7 @@ in
|
||||
services.xserver.libinput.enable = true;
|
||||
console.keyMap = "de";
|
||||
|
||||
# Audio setup
|
||||
services.pulseaudio.enable = false;
|
||||
security.rtkit.enable = true;
|
||||
services.pipewire = {
|
||||
@@ -47,21 +89,31 @@ in
|
||||
|
||||
services.printing.enable = true;
|
||||
|
||||
# User setup
|
||||
users.users.user = {
|
||||
isNormalUser = true;
|
||||
description = "user";
|
||||
extraGroups = [ "networkmanager" "wheel" ];
|
||||
extraGroups = [ "networkmanager" "wheel" "audio" "video" "disk" ];
|
||||
shell = pkgs.bash;
|
||||
# For cloned systems, don't set a password in config
|
||||
# Users should set their own passwords after first boot
|
||||
};
|
||||
|
||||
# Allow unfree packages
|
||||
nixpkgs.config.allowUnfree = true;
|
||||
|
||||
# Essential packages for a portable system
|
||||
environment.systemPackages = with pkgs; [
|
||||
git
|
||||
vim
|
||||
curl
|
||||
wget
|
||||
openssh
|
||||
rsync
|
||||
pciutils
|
||||
usbutils
|
||||
gparted
|
||||
gnome-disk-utility
|
||||
obsidian
|
||||
libreoffice
|
||||
keepassxc
|
||||
@@ -73,11 +125,53 @@ in
|
||||
epiphany
|
||||
gnomeExtensions.gsconnect
|
||||
gnomeExtensions.dash-to-dock
|
||||
file
|
||||
psmisc
|
||||
lsof
|
||||
strace
|
||||
pciutils
|
||||
usbutils
|
||||
];
|
||||
|
||||
programs.firefox.enable = true;
|
||||
|
||||
# === Auto-update script with full PATH and NIX_PATH ===
|
||||
# SSH server configuration
|
||||
services.openssh.enable = true;
|
||||
services.openssh.settings.PermitRootLogin = "no";
|
||||
|
||||
# First-boot setup script to regenerate machine-specific configurations
|
||||
environment.etc."first-boot-setup.sh".text = ''
|
||||
#!/run/current-system/sw/bin/bash
|
||||
set -e
|
||||
|
||||
if [ ! -f /var/lib/nixos-firstboot-done ]; then
|
||||
echo "=== First boot setup for cloned NixOS USB ==="
|
||||
|
||||
# Regenerate SSH host keys
|
||||
echo "Regenerating SSH host keys..."
|
||||
rm -f /etc/ssh/ssh_host_*
|
||||
ssh-keygen -A
|
||||
|
||||
# Generate new machine-id
|
||||
echo "Generating new machine ID..."
|
||||
rm -f /etc/machine-id /var/lib/dbus/machine-id
|
||||
systemd-machine-id-setup
|
||||
|
||||
# Ensure proper permissions
|
||||
chmod 700 /root
|
||||
chmod 755 /home/user
|
||||
|
||||
# Mark first boot complete
|
||||
touch /var/lib/nixos-firstboot-done
|
||||
echo "First boot setup complete."
|
||||
else
|
||||
echo "System already set up - skipping first boot configuration."
|
||||
fi
|
||||
'';
|
||||
|
||||
environment.etc."first-boot-setup.sh".mode = "0700";
|
||||
|
||||
# Auto-update script with improved hardware independence
|
||||
environment.etc."update-nixos-config.sh".text = ''
|
||||
#!/run/current-system/sw/bin/bash
|
||||
set -e
|
||||
@@ -87,7 +181,9 @@ in
|
||||
export NIX_PATH="nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos"
|
||||
|
||||
LOCAL_PATH="/var/lib/nixos-config"
|
||||
REPO_URL="https://git.skarockoi.de/ska/nixos-production.git"
|
||||
REPO_URL="${gitRepoUrl}"
|
||||
|
||||
echo "[$(date)] Checking for configuration updates..."
|
||||
|
||||
if [ ! -d "$LOCAL_PATH/.git" ]; then
|
||||
mkdir -p "$LOCAL_PATH"
|
||||
@@ -103,18 +199,35 @@ in
|
||||
if [ "$LOCAL_HEAD" != "$REMOTE_HEAD" ]; then
|
||||
echo "New config available. Updating..."
|
||||
git reset --hard origin/main
|
||||
|
||||
# Rebuild the system with the new configuration
|
||||
nixos-rebuild switch -I nixos-config="$LOCAL_PATH/configuration.nix"
|
||||
|
||||
echo "System updated successfully."
|
||||
else
|
||||
echo "Config is already up to date."
|
||||
fi
|
||||
fi
|
||||
'';
|
||||
|
||||
environment.etc."update-nixos-config.sh".mode = "0700";
|
||||
|
||||
# === Systemd service (simple, no extra path needed) ===
|
||||
# First boot service
|
||||
systemd.services.first-boot-setup = {
|
||||
description = "One-time setup for cloned NixOS USB";
|
||||
script = "/etc/first-boot-setup.sh";
|
||||
path = with pkgs; [ systemd openssh ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /var/lib";
|
||||
};
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
};
|
||||
|
||||
# Auto-update service
|
||||
systemd.services.nixos-git-update = {
|
||||
description = "Update NixOS from public Git config";
|
||||
description = "Update NixOS from Git config repository";
|
||||
script = "/etc/update-nixos-config.sh";
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
@@ -123,6 +236,7 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
# Run updates hourly after boot
|
||||
systemd.timers.nixos-git-update = {
|
||||
description = "Check for config updates hourly";
|
||||
wantedBy = [ "timers.target" ];
|
||||
@@ -132,5 +246,13 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
# Power management for USB devices
|
||||
powerManagement.enable = true;
|
||||
services.udev.extraRules = ''
|
||||
# Allow all users to mount USB devices
|
||||
ACTION=="add", SUBSYSTEM=="block", ENV{ID_BUS}=="usb", MODE="0660", GROUP="disk"
|
||||
'';
|
||||
|
||||
# NixOS version compatibility
|
||||
system.stateVersion = "25.11";
|
||||
}
|
||||
Reference in New Issue
Block a user