mirror of
https://github.com/lxstinthesky/matrix.git
synced 2025-11-02 17:02:47 +00:00
A simple flake setup with tests and VM support
This commit is contained in:
86
nix/configuration.nix
Normal file
86
nix/configuration.nix
Normal file
@@ -0,0 +1,86 @@
|
||||
{ config, pkgs, inputs, lib, ... }:
|
||||
|
||||
{
|
||||
imports = [
|
||||
./users/users.nix
|
||||
./modules/ssh.nix
|
||||
./hardware-configuration.nix
|
||||
./modules/zsh.nix
|
||||
];
|
||||
|
||||
# nix settings
|
||||
nix.settings.experimental-features = [ "nix-command" "flakes" ];
|
||||
|
||||
# Bootloader.
|
||||
boot.loader.grub.enable = true;
|
||||
|
||||
networking.hostName = "matrix";
|
||||
|
||||
# time zone
|
||||
time.timeZone = "Europe/Zurich";
|
||||
|
||||
# Select internationalisation properties.
|
||||
i18n.defaultLocale = "en_US.UTF-8";
|
||||
|
||||
i18n.extraLocaleSettings = {
|
||||
LC_ADDRESS = "de_DE.UTF-8";
|
||||
LC_IDENTIFICATION = "de_DE.UTF-8";
|
||||
LC_MEASUREMENT = "de_DE.UTF-8";
|
||||
LC_MONETARY = "de_DE.UTF-8";
|
||||
LC_NAME = "de_DE.UTF-8";
|
||||
LC_NUMERIC = "de_DE.UTF-8";
|
||||
LC_PAPER = "de_DE.UTF-8";
|
||||
LC_TELEPHONE = "de_DE.UTF-8";
|
||||
LC_TIME = "de_DE.UTF-8";
|
||||
};
|
||||
|
||||
# Allow unfree packages
|
||||
# nixpkgs.config.allowUnfree = true;
|
||||
|
||||
# List packages installed in system profile. To search, run:
|
||||
environment.systemPackages = with pkgs; [
|
||||
];
|
||||
|
||||
virtualisation.vmVariant = {
|
||||
# following configuration is added only when building VM with build-vm
|
||||
virtualisation = {
|
||||
memorySize = 4000;
|
||||
cores = 2;
|
||||
graphics = false;
|
||||
diskSize = 5000; # 5GB, needed to prevent docker error running out of space
|
||||
|
||||
# Networking configuration
|
||||
#forwardPorts = [
|
||||
# { from = "host"; host.port = 2222; guest.port = 22; }
|
||||
#];
|
||||
};
|
||||
|
||||
# Add VM-specific users
|
||||
users.users.smith = {
|
||||
isNormalUser = true;
|
||||
description = "VM Test User";
|
||||
extraGroups = [ "wheel" "networkmanager" ];
|
||||
shell = pkgs.zsh;
|
||||
initialPassword = "smith";
|
||||
packages = with pkgs; [ ];
|
||||
};
|
||||
|
||||
security.sudo.wheelNeedsPassword = false;
|
||||
|
||||
# VM-specific packages
|
||||
environment.systemPackages = with pkgs; [
|
||||
];
|
||||
|
||||
# in order to build VM on x86_64 host
|
||||
nixpkgs.hostPlatform = lib.mkForce "x86_64-linux";
|
||||
};
|
||||
|
||||
# This value determines the NixOS release from which the default
|
||||
# settings for stateful data, like file locations and database versions
|
||||
# on your system were taken. It‘s perfectly fine and recommended to leave
|
||||
# this value at the release version of the first install of this system.
|
||||
# Before changing this value read the documentation for this option
|
||||
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
|
||||
system.stateVersion = "25.05"; # Did you read the comment?
|
||||
|
||||
}
|
||||
38
nix/disko.nix
Normal file
38
nix/disko.nix
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
{
|
||||
disko.devices = {
|
||||
disk = {
|
||||
main = {
|
||||
type = "disk";
|
||||
device = "/dev/sda";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
boot = {
|
||||
size = "1M";
|
||||
type = "EF02";
|
||||
priority = 1;
|
||||
};
|
||||
ESP = {
|
||||
size = "512M";
|
||||
type = "EF00";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
};
|
||||
};
|
||||
root = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "ext4";
|
||||
mountpoint = "/";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
17
nix/hardware-configuration.nix
Normal file
17
nix/hardware-configuration.nix
Normal file
@@ -0,0 +1,17 @@
|
||||
{ config, lib, pkgs, modulesPath, ... }:
|
||||
|
||||
{
|
||||
imports = [
|
||||
(modulesPath + "/profiles/qemu-guest.nix")
|
||||
];
|
||||
|
||||
boot.initrd.availableKernelModules = [ "ata_piix" "virtio_pci" "virtio_blk" ];
|
||||
boot.initrd.kernelModules = [ ];
|
||||
boot.kernelModules = [ ];
|
||||
boot.extraModulePackages = [ ];
|
||||
|
||||
networking.useDHCP = lib.mkDefault true;
|
||||
|
||||
# aarch64-linux?
|
||||
nixpkgs.hostPlatform = lib.mkDefault "aarch64-linux";
|
||||
}
|
||||
8
nix/modules/ssh.nix
Normal file
8
nix/modules/ssh.nix
Normal file
@@ -0,0 +1,8 @@
|
||||
{ config, pkgs, inputs, ... }:
|
||||
|
||||
{
|
||||
services.openssh = {
|
||||
enable = true;
|
||||
# permitRootLogin = "no";
|
||||
};
|
||||
}
|
||||
40
nix/modules/zsh.nix
Normal file
40
nix/modules/zsh.nix
Normal file
@@ -0,0 +1,40 @@
|
||||
{ lib, config, pkgs, ... }:
|
||||
|
||||
{
|
||||
programs.zsh = {
|
||||
enable = true;
|
||||
enableCompletion = true;
|
||||
autosuggestions.enable = true;
|
||||
syntaxHighlighting.enable = true;
|
||||
enableLsColors = true;
|
||||
|
||||
histSize = 10000;
|
||||
histFile = "$HOME/.zsh_history";
|
||||
|
||||
shellAliases = {
|
||||
ll = "ls - l";
|
||||
};
|
||||
|
||||
ohMyZsh = {
|
||||
enable = true;
|
||||
plugins = [
|
||||
"sudo"
|
||||
#"direnv"
|
||||
#"fzf"
|
||||
];
|
||||
theme = "terminalparty";
|
||||
};
|
||||
|
||||
# custom zsh options
|
||||
setOptions = [
|
||||
"HIST_IGNORE_DUPS" # do not write dupes
|
||||
"HIST_SAVE_NO_DUPS"
|
||||
"HIST_IGNORE_ALL_DUPS"
|
||||
"HIST_FIND_NO_DUPS"
|
||||
"APPEND_HISTORY" # append rather than overwrite ...?
|
||||
"SHARE_HISTORY" # all zsh sessions share history file
|
||||
"HIST_FCNTL_LOCK" # useful to prevent lockups ...? see github
|
||||
"HIST_IGNORE_SPACE" # add space before command to not write to history
|
||||
];
|
||||
};
|
||||
}
|
||||
25
nix/tests/test1.nix
Normal file
25
nix/tests/test1.nix
Normal file
@@ -0,0 +1,25 @@
|
||||
{ pkgs ? import <nixpkgs> {} }:
|
||||
|
||||
pkgs.nixosTest {
|
||||
name = "matrix-login-test";
|
||||
|
||||
nodes = {
|
||||
machine = { config, pkgs, ... }: {
|
||||
imports = [
|
||||
../configuration.nix
|
||||
];
|
||||
|
||||
# Test configuration
|
||||
virtualisation.memorySize = 2048;
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
start_all()
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
|
||||
with subtest("SSH service test"):
|
||||
machine.wait_for_unit("sshd.service")
|
||||
machine.wait_for_open_port(22)
|
||||
'';
|
||||
}
|
||||
29
nix/users/users.nix
Normal file
29
nix/users/users.nix
Normal file
@@ -0,0 +1,29 @@
|
||||
{ config, pkgs, inputs, ... }:
|
||||
|
||||
{
|
||||
# Define user accounts
|
||||
users.defaultUserShell = pkgs.zsh;
|
||||
users.users.neo = {
|
||||
isNormalUser = true;
|
||||
description = "Matrix User 1";
|
||||
extraGroups = [ "networkmanager" "wheel" ];
|
||||
shell = pkgs.zsh;
|
||||
packages = with pkgs; [ ];
|
||||
};
|
||||
|
||||
users.users.morpheus = {
|
||||
isNormalUser = true;
|
||||
description = "Matrix User 2";
|
||||
extraGroups = [ "networkmanager" "wheel" ];
|
||||
shell = pkgs.zsh;
|
||||
packages = with pkgs; [ ];
|
||||
};
|
||||
|
||||
users.users.trinity = {
|
||||
isNormalUser = true;
|
||||
description = "Matrix User 3";
|
||||
extraGroups = [ "networkmanager" "wheel" ];
|
||||
shell = pkgs.zsh;
|
||||
packages = with pkgs; [ ];
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user