initial commit

This commit is contained in:
Janis 2025-07-17 23:39:35 +02:00
commit 1dc1e850d2
11 changed files with 321 additions and 0 deletions

11
config/configuration.nix Normal file
View file

@ -0,0 +1,11 @@
{ ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
# inputs.home-manager.nixosModules.default
./nixos
./users/alice.nix
];
}

37
config/disks.nix Normal file
View file

@ -0,0 +1,37 @@
{
disko.devices = {
disk = {
root = {
device = "/dev/vda";
type = "disk";
content = {
type = "gpt";
partitions = {
ESP = {
label = "boot";
name = "ESP";
type = "EF00";
size = "512M";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "umask=0077" ];
};
};
root = {
label = "root";
size = "100%";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
};
};
};
};
};
};
}

34
config/flake.nix Normal file
View file

@ -0,0 +1,34 @@
{
inputs = {
# This is pointing to an unstable release.
# If you prefer a stable release instead, you can this to the latest number shown here: https://nixos.org/download
# i.e. nixos-24.11
# Use `nix flake update` to update the flake to the latest revision of the chosen release channel.
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs"; # Use the same nixpkgs as the system
};
};
outputs = inputs @ { self, nixpkgs, home-manager, ... }:
{
# NOTE: 'nixos' is the default hostname
nixosConfigurations = {
nixos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux"; # Change this to your system architecture if needed
modules = [
./configuration.nix
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true; # Use global packages in home-manager
home-manager.useUserPackages = true; # Use user packages in home-manager
# home-manager.users.alice = ./users/alice.nix; # Define user-specific home-manager configuration
}
];
};
};
};
}

View file

@ -0,0 +1,37 @@
# 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 =
[ (modulesPath + "/profiles/qemu-guest.nix")
];
boot.initrd.availableKernelModules = [ "ahci" "xhci_pci" "virtio_pci" "sr_mod" "virtio_blk" ];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ "kvm-intel" ];
boot.extraModulePackages = [ ];
fileSystems."/" =
{ device = "/dev/disk/by-uuid/723e4a6a-97b9-49ff-999f-806b12ea26b6";
fsType = "ext4";
};
fileSystems."/boot" =
{ device = "/dev/disk/by-uuid/15E6-98FA";
fsType = "vfat";
options = [ "fmask=0077" "dmask=0077" ];
};
swapDevices = [ ];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# (the default) this is the recommended approach. When using systemd-networkd it's
# still possible to use this option, but it's recommended to use it in conjunction
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
networking.useDHCP = lib.mkDefault true;
# networking.interfaces.enp1s0.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
}

6
config/nixos/default.nix Normal file
View file

@ -0,0 +1,6 @@
{...}: {
imports = [
./hardware.nix
./system.nix
];
}

19
config/nixos/hardware.nix Normal file
View file

@ -0,0 +1,19 @@
{ config, pkgs, ...}:
with pkgs;
{
hardware = {
graphics = {
enable = true; # Enable graphics support.
extraPackages = [
amdvlk
intel-media-driver
intel-vaapi-driver
];
};
cpu = {
amd = {
updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
};
};
};
}

54
config/nixos/system.nix Normal file
View file

@ -0,0 +1,54 @@
{pkgs, ...}:
let
base = import ../options.nix {};
in {
system.stateVersion = "${base.stateVersion}";
nixpkgs.config.allowUnfree = true; # Allow unfree packages, if necessary.
nix.settings.experimental-features = [
"nix-command"
"flakes"
];
# Use the systemd-boot EFI boot loader.
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
networking.networkmanager.enable = true; # Easiest to use and most distros use this by default.
# Set your time zone.
time.timeZone = "Europe/Amsterdam";
i18n.defaultLocale = "en_GB.UTF-8";
console = {
font = "Lat2-Terminus16";
keyMap = "uk";
# useXkbConfig = true; # use xkb.options in tty.
};
security.rtkit.enable = true; # Enable real-time scheduling for audio applications.
services = {
pipewire = {
enable = true;
pulse.enable = true;
alsa.enable = true;
alsa.support32Bit = true; # Enable 32-bit support if needed.
};
openssh = {
enable = true;
settings = {
PasswordAuthentication = true; # Enable password authentication.
PermitRootLogin = "yes"; # Allow root login (not recommended for production).
};
};
libinput.enable = true;
};
environment.systemPackages = with pkgs; [
vim wget curl git emacs
];
}

6
config/options.nix Normal file
View file

@ -0,0 +1,6 @@
{...}:
let
stateVersion = "25.05";
in {
inherit stateVersion;
}

39
config/users/alice.nix Normal file
View file

@ -0,0 +1,39 @@
inputs @ { pkgs, lib, ...}: let
# NixOS version
# Function to create the home-manager configuration for the account
aliceUserFn = {pkgs, ...}: {
home = {
packages = with pkgs; [
htop
]; # Default packages for the owner account.
};
# configure the shell
programs.zsh = {
enable = true; # Enable zsh shell.
enableCompletion = true; # Enable zsh completion.
shellAliases = {
ll = "ls -l";
la = "ls -la";
git-tree = "git log --graph --oneline --all";
};
};
};
in
{
imports = [(lib.modules.importApply ./user.nix {
user = {
userName = "alice";
defaultPassword = "password";
shell = pkgs.zsh;
packages = with pkgs; [
tree
vim
wget
curl
git
];
userModule = aliceUserFn;
};
})];
}

45
config/users/user.nix Normal file
View file

@ -0,0 +1,45 @@
# `user` has the following attributes:
# - `userName`: The username for the user account.
# - `defaultPassword`: The default password for the user account.
# - `shell`: The shell for the user account.
# - `packages`: List of packages to install for the user account.
# - `userModule`: A module that provides additional configuration for the user account.
{user}: inputs @ {lib, pkgs, ...}:
let
userName = user.userName or "alice";
base = import ../options.nix {};
in
let
homeDirectory = "/home/${userName}";
passwordConfig = lib.mkIf user.defaultPassword {
initialPassword = user.defaultPassword;
};
in {
users.users.${userName} = {
shell = user.shell or pkgs.zsh; # Default shell for the user
home = homeDirectory;
createHome = true;
group = "users"; # Default group
isNormalUser = true;
extraGroups = [ "wheel" ]; # Add to wheel group for sudo access
} // passwordConfig;
home-manager.users.${userName} = {...}: {
imports = [ user.userModule (inputs) ];
home = {
inherit userName;
inherit (user) homeDirectory;
inherit (user) packages;
stateVersion = "${base.stateVersion}";
sessionVariables = {
EDITOR = user.editor or "vim";
};
};
};
}

33
upload.sh Executable file
View file

@ -0,0 +1,33 @@
#!/bin/bash
set -e
VM_NAME="nixos"
VM_IP=$(sudo virsh domifaddr "$VM_NAME" | awk '/ipv4/ {print $4}' | cut -d'/' -f1)
USER="root"
PASSWORD="asdf"
# function for printing error messages in yellow
eprint() {
echo -e "\033[1;33m$1\033[0m"
}
echo "IP: $VM_IP"
# FILES=(
# "configuration.nix"
# "flake.nix"
# "hardware-configuration.nix"
# )
# for FILE in "${FILES[@]}"; do
# if [ -f "$FILE" ]; then
# echo "Uploading $FILE to $VM_IP..."
# sshpass -p "$PASSWORD" scp "$FILE" "$USER@$VM_IP:/etc/nixos/$FILE"
# else
# eprint "Warning: $FILE does not exist, skipping upload."
# fi
# done
# Synchronize the NixOS configuration with rsync
sshpass -p "$PASSWORD" rsync -avz config/ "$USER@$VM_IP:/etc/nixos/"