new file: common/configuration.nix

new file:   common/hardware-configuration.nix
	new file:   common/home.nix
	new file:   flake.nix
	new file:   hosts/docker/configuration.nix
	new file:   hosts/nixos/configuration.nix
	new file:   hosts/nixos/home.nix
	new file:   hosts/server/configuration.nix
	new file:   install.sh
	new file:   prepare.sh
This commit is contained in:
2025-07-16 13:33:23 +10:00
parent dccd499d3e
commit a670aedce1
10 changed files with 597 additions and 0 deletions

View File

@@ -0,0 +1,124 @@
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page, on
# https://search.nixos.org/options and in the NixOS manual (`nixos-help`).
{ config, lib, pkgs, inputs, ... }:
let
pythonEnv = pkgs.python3.withPackages (ps: with ps; [
docker
pytz
]);
in
{
imports =
[ # Include the results of the hardware scan.
../../common/configuration.nix
];
networking.hostName = "docker"; # Define your hostname.
virtualisation.docker.enable = true;
# Enable docker-compose
environment.systemPackages = with pkgs; [
docker-compose
];
# Mount docker persistent data
fileSystems."/mnt/docker-persistent-data" = {
device = "/dev/disk/by-label/docker-data";
fsType = "ext4";
options = [ "defaults" "nofail" "noatime" ];
};
# Create nextcloud cron scheduled task
systemd.services.nextcloud = {
description = "Nextcloud scheduled task";
script = ''docker-compose -f ~/docker/nextcloud/docker-compose.yml exec -u 33 webapp php ./cron.php'';
serviceConfig = {
Type = "oneshot";
User = "nixos";
};
path = with pkgs; [ docker docker-compose ];
};
systemd.timers.nextcloud = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "*:0/5";
Persistent = true;
};
};
# create update task
systemd.services.update-containers = {
description = "Update Docker Compose Containers";
after = [ "docker.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
User = "nixos";
WorkingDirectory = "/home/nixos/docker";
ExecStart = "${pythonEnv}/bin/python3 /home/nixos/docker/update-containers.py";
StandardOutput = "journal";
StandardError = "journal";
};
path = [ pkgs.docker pkgs.docker-compose ]; # Ensures docker CLI is available in $PATH
};
systemd.timers.update-containers = {
description = "Weekly + Reboot container update";
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "5min"; # Run 5 minutes after boot
OnUnitActiveSec = "1w"; # Run every week after last run
Persistent = true; # Catch up if system was off
};
};
#Add sym links to data on users home folder
system.userActivationScripts.createDockerSymlink.text = ''
ln -sf /mnt/docker-persistent-data/docker /home/nixos/docker
'';
system.userActivationScripts.createSetupSymlink.text = ''
ln -sf /mnt/docker-persistent-data/setup /home/nixos/setup
'';
users.users.nixos.extraGroups = [ "docker" ];
services.openssh.settings.PermitRootLogin = "yes";
# Open ports in the firewall.
networking.firewall.allowedTCPPorts = [ 80 8080 443 ];
# networking.firewall.allowedUDPPorts = [ ... ];
# Or disable the firewall altogether.
# networking.firewall.enable = false;
# Copy the NixOS configuration file and link it from the resulting system
# (/run/current-system/configuration.nix). This is useful in case you
# accidentally delete configuration.nix.
# system.copySystemConfiguration = true;
# This option defines the first version of NixOS you have installed on this particular machine,
# and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
#
# Most users should NEVER change this value after the initial install, for any reason,
# even if you've upgraded your system to a new NixOS release.
#
# This value does NOT affect the Nixpkgs version your packages and OS are pulled from,
# so changing it will NOT upgrade your system - see https://nixos.org/manual/nixos/stable/#sec-upgrading for how
# to actually do that.
#
# This value being lower than the current NixOS release does NOT mean your system is
# out of date, out of support, or vulnerable.
#
# Do NOT change this value unless you have manually inspected all the changes it would make to your configuration,
# and migrated your data accordingly.
#
# For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.sta>
system.stateVersion = "25.05"; # Did you read the comment?
}

View File

@@ -0,0 +1,111 @@
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running nixos-help).
{ config, pkgs, lib, inputs,... }:
let
nixosConfEditor = builtins.getFlake "github:snowfallorg/nixos-conf-editor";
in {
#{
environment.systemPackages = with pkgs; [
inputs.nixos-conf-editor.packages.${pkgs.system}.nixos-conf-editor
nodejs
appimage-run
seahorse
];
imports =
[ # Include the results of the hardware scan.
../../common/configuration.nix
];
# Bootloader.
boot.loader.grub.useOSProber = true;
networking.hostName = "nixos"; # Define your hostname.
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
# Select internationalisation properties.
i18n.defaultLocale = "en_AU.UTF-8";
i18n.extraLocaleSettings = {
LC_ADDRESS = "en_AU.UTF-8";
LC_IDENTIFICATION = "en_AU.UTF-8";
LC_MEASUREMENT = "en_AU.UTF-8";
LC_MONETARY = "en_AU.UTF-8";
LC_NAME = "en_AU.UTF-8";
LC_NUMERIC = "en_AU.UTF-8";
LC_PAPER = "en_AU.UTF-8";
LC_TELEPHONE = "en_AU.UTF-8";
LC_TIME = "en_AU.UTF-8";
};
# Enable the X11 windowing system.
services.xserver.enable = true;
# Enable the Cinnamon Desktop Environment.
services.xserver.displayManager.lightdm.enable = true;
services.xserver.desktopManager.cinnamon.enable = true;
# services.xserver.desktopManager.xfce.enable = true;
# Configure keymap in X11
services.xserver.xkb = {
layout = "au";
variant = "";
};
# Enable CUPS to print documents.
services.printing.enable = true;
# Enable sound with pipewire.
# services.pulseaudio.enable = false;
security.rtkit.enable = true;
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
# If you want to use JACK applications, uncomment this
#jack.enable = true;
# use the example session manager (no others are packaged yet so this is enabled by default,
# no need to redefine it in your config for now)
#media-session.enable = true;
};
# Enable touchpad support (enabled default in most desktopManager).
# services.xserver.libinput.enable = true;
users.users.nixos.extraGroups = [ "networkmanager" ]; # Enable sudo for the user.
# Install firefox.
programs.firefox.enable = true;
system.stateVersion = "25.05"; # Did you read the comment?
nix.settings.experimental-features = "nix-command flakes";
services.xrdp.enable = true;
services.xrdp.defaultWindowManager = "cinnamon-session";
services.xrdp.openFirewall = true;
# systemd.services.nextcloud-appimage = {
# enable = true;
# Unit = {
# Description = "Nextcloud AppImage client";
# After = [ "graphical-session.target" ];
# Wants = [ "graphical-session.target" ]; # optional but helpful
# };
# Service = {
# ExecStart = "/run/current-system/sw/bin/appimage-run /home/nixos/Applications/Nextcloud.AppImage --background";
# Restart = "on-failure";
# # You can add RestartSec = "5s"; if you like
# };
# Install = {
# WantedBy = [ "default.target" ];
# };
# };
}

31
hosts/nixos/home.nix Normal file
View File

@@ -0,0 +1,31 @@
{ config, pkgs, lib, ... }:
{
home.username = "nixos"; # your actual username
home.homeDirectory = "/home/nixos";
home.stateVersion = "25.05"; # match your NixOS stateVersion
programs.home-manager.enable = true; # mandatory to activate HM
# Optional: packages
home.packages = with pkgs; [
git
vim
tmux
nextcloud-client
];
# Optional: set environment vars
home.sessionVariables = {
EDITOR = "vim";
};
# Optional: enable bash (or zsh, fish...)
programs.bash.enable = true;
services.nextcloud-client = {
enable = true;
# Optionally start in background directly
startInBackground = true;
};
}

View File

@@ -0,0 +1,117 @@
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page, on
# https://search.nixos.org/options and in the NixOS manual (`nixos-help`).
{ config, lib, pkgs, inputs,... }:
{
imports =
[ # Include the results of the hardware scan.
../../common/configuration.nix
];
networking.hostName = "server"; # Define your hostname.
# Pick only one of the below networking options.
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
# Mount server data
fileSystems."/srv" = {
device = "/dev/disk/by-label/server-data";
fsType = "ext4";
options = [ "defaults" ];
};
fileSystems."/backup" = {
device = "/dev/disk/by-label/backup-data";
fsType = "ext4";
options = [ "defaults" ];
};
#Add sym links to data on users home folder
system.userActivationScripts.createDockerSymlink.text = ''
ln -sf /srv/scripts /home/nixos/scripts
'';
#system.userActivationScripts.createSetupSymlink.text = ''
# ln -sf /mnt/docker-persistent-data/setup /home/nixos/setup
#'';
services.nfs.server = {
enable = true;
exports = ''
/srv/ 192.168.2.0/24(rw,sync,no_subtree_check)
/backup 192.168.2.0/24(rw,sync,no_subtree_check)
'';
};
security.sudo = {
enable = true;
extraRules = [
{
users = [ "nixos" ];
commands = [
{
command = "/run/current-system/sw/bin/rsync";
options = [ "NOPASSWD" ];
}
];
}
];
};
systemd.services.backup = {
description = "Backup data";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
User = "root";
# WorkingDirectory = "/home/nixos/scripts";
ExecStart = "${pkgs.bash}/bin/bash -e /srv/scripts/rsync.sh";
StandardOutput = "journal";
StandardError = "journal";
};
path = with pkgs; [ bash rsync openssh coreutils ];
};
systemd.timers.backup = {
description = "Daily backup";
wantedBy = [ "timers.target" ];
timerConfig = {
OnUnitActiveSec = "1d"; # Run every day after last run
Persistent = true; # Catch up if system was off
};
};
# Open ports in the firewall.
networking.firewall.allowedTCPPorts = [ 2049 ];
# networking.firewall.allowedUDPPorts = [ 111 2049 20048 ];
# Or disable the firewall altogether.
# networking.firewall.enable = false;
# Copy the NixOS configuration file and link it from the resulting system
# (/run/current-system/configuration.nix). This is useful in case you
# accidentally delete configuration.nix.
# system.copySystemConfiguration = true;
# This option defines the first version of NixOS you have installed on this particular machine,
# and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
#
# Most users should NEVER change this value after the initial install, for any reason,
# even if you've upgraded your system to a new NixOS release.
#
# This value does NOT affect the Nixpkgs version your packages and OS are pulled from,
# so changing it will NOT upgrade your system - see https://nixos.org/manual/nixos/stable/#sec-upgrading for how
# to actually do that.
#
# This value being lower than the current NixOS release does NOT mean your system is
# out of date, out of support, or vulnerable.
#
# Do NOT change this value unless you have manually inspected all the changes it would make to your configuration,
# and migrated your data accordingly.
#
# For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.sta>
system.stateVersion = "25.05"; # Did you read the comment?
}