From 57cdfec543577934a4979aca81b1eeaca52000ce Mon Sep 17 00:00:00 2001 From: m3tam3re Date: Thu, 27 Mar 2025 15:21:42 +0100 Subject: [PATCH] first --- flake.lock | 85 ++++++++++++ flake.nix | 59 +++++++++ hosts/m3-zelda/configuration.nix | 122 ++++++++++++++++++ hosts/m3-zelda/default.nix | 16 +++ hosts/m3-zelda/disko-config.nix | 39 ++++++ .../m3-zelda/hardware-configuration-image.nix | 32 +++++ hosts/m3-zelda/hardware-configuration.nix | 34 +++++ .../m3-zelda/services/containers/default.nix | 5 + hosts/m3-zelda/services/containers/slash.nix | 26 ++++ hosts/m3-zelda/services/default.nix | 7 + hosts/m3-zelda/services/podman.nix | 20 +++ hosts/m3-zelda/services/traefik.nix | 77 +++++++++++ 12 files changed, 522 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 hosts/m3-zelda/configuration.nix create mode 100644 hosts/m3-zelda/default.nix create mode 100644 hosts/m3-zelda/disko-config.nix create mode 100644 hosts/m3-zelda/hardware-configuration-image.nix create mode 100644 hosts/m3-zelda/hardware-configuration.nix create mode 100644 hosts/m3-zelda/services/containers/default.nix create mode 100644 hosts/m3-zelda/services/containers/slash.nix create mode 100644 hosts/m3-zelda/services/default.nix create mode 100644 hosts/m3-zelda/services/podman.nix create mode 100644 hosts/m3-zelda/services/traefik.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0c18f28 --- /dev/null +++ b/flake.lock @@ -0,0 +1,85 @@ +{ + "nodes": { + "disko": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1741786315, + "narHash": "sha256-VT65AE2syHVj6v/DGB496bqBnu1PXrrzwlw07/Zpllc=", + "owner": "nix-community", + "repo": "disko", + "rev": "0d8c6ad4a43906d14abd5c60e0ffe7b587b213de", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "disko", + "type": "github" + } + }, + "nixlib": { + "locked": { + "lastModified": 1736643958, + "narHash": "sha256-tmpqTSWVRJVhpvfSN9KXBvKEXplrwKnSZNAoNPf/S/s=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "1418bc28a52126761c02dd3d89b2d8ca0f521181", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixos-generators": { + "inputs": { + "nixlib": "nixlib", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1742568034, + "narHash": "sha256-QaMEhcnscfF2MqB7flZr+sLJMMYZPnvqO4NYf9B4G38=", + "owner": "nix-community", + "repo": "nixos-generators", + "rev": "42ee229088490e3777ed7d1162cb9e9d8c3dbb11", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixos-generators", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1742889210, + "narHash": "sha256-hw63HnwnqU3ZQfsMclLhMvOezpM7RSB0dMAtD5/sOiw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "698214a32beb4f4c8e3942372c694f40848b360d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "disko": "disko", + "nixos-generators": "nixos-generators", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..52d482e --- /dev/null +++ b/flake.nix @@ -0,0 +1,59 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + disko = { + url = "github:nix-community/disko"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + nixos-generators = { + url = "github:nix-community/nixos-generators"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { + self, + nixpkgs, + nixos-generators, + ... + } @ inputs: let + inherit (self) outputs; + in { + nixosConfigurations = { + m3-zelda = nixpkgs.lib.nixosSystem { + specialArgs = { + inherit inputs outputs; + isImageTarget = false; + }; + system = "x86_64-linux"; + modules = [ + ./hosts/m3-zelda + inputs.disko.nixosModules.disko + ]; + }; + }; + qcow = nixos-generators.nixosGenerate { + specialArgs = { + inherit inputs outputs; + isImageTarget = true; + }; + system = "x86_64-linux"; + modules = [ + ./hosts/m3-zelda + ]; + format = "qcow-efi"; + }; + proxmox = nixos-generators.nixosGenerate { + specialArgs = { + inherit inputs outputs; + isImageTarget = true; + }; + system = "x86_64-linux"; + modules = [ + ./hosts/m3-zelda + ]; + format = "proxmox-lxc"; + }; + }; +} diff --git a/hosts/m3-zelda/configuration.nix b/hosts/m3-zelda/configuration.nix new file mode 100644 index 0000000..a4cb215 --- /dev/null +++ b/hosts/m3-zelda/configuration.nix @@ -0,0 +1,122 @@ +# 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`). +{ + isImageTarget, + pkgs, + ... +}: { + imports = + if isImageTarget + then [ + ./hardware-configuration-image.nix + ] + else [ + ./hardware-configuration.nix + ./disko-config.nix + ]; + + networking.hostName = "m3-zelda"; # CHANGE ME. + # Pick only one of the below networking options. + # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. + networking.networkmanager.enable = + true; # Easiest to use and most distros use this by default. + # Set your time zone. + time.timeZone = "Europe/Berlin"; + + # Configure network proxy if necessary + # networking.proxy.default = "http://user:password@proxy:port/"; + # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; + + # Select internationalisation properties. + i18n.defaultLocale = "en_US.UTF-8"; + # console = { + # font = "Lat2-Terminus16"; + # keyMap = "us"; + # useXkbConfig = true; # use xkb.options in tty. + # }; + + # Enable the X11 windowing system. + # services.xserver.enable = true; + + # Enable the GNOME Desktop Environment. + # services.xserver.displayManager.gdm.enable = true; + # services.xserver.desktopManager.gnome.enable = true; + + # Configure keymap in X11 + # services.xserver.xkb.layout = "us"; + # services.xserver.xkb.options = "eurosign:e,caps:escape"; + + # Enable CUPS to print documents. + # services.printing.enable = true; + + # Enable sound. + # hardware.pulseaudio.enable = true; + # OR + + # Enable touchpad support (enabled default in most desktopManager). + # services.libinput.enable = true; + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.users.m3tam3re = { + #initialHashedPassword = "$y$j9T$IoChbWGYRh.rKfmm0G86X0$bYgsWqDRkvX.EBzJTX.Z0RsTlwspADpvEF3QErNyCMC"; + password = "12345"; + isNormalUser = true; + description = "m3tam3re"; + extraGroups = [ + "wheel" + ]; + openssh.authorizedKeys.keys = [ + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC3YEmpYbM+cpmyD10tzNRHEn526Z3LJOzYpWEKdJg8DaYyPbDn9iyVX30Nja2SrW4Wadws0Y8DW+Urs25/wVB6mKl7jgPJVkMi5hfobu3XAz8gwSdjDzRSWJrhjynuaXiTtRYED2INbvjLuxx3X8coNwMw58OuUuw5kNJp5aS2qFmHEYQErQsGT4MNqESe3jvTP27Z5pSneBj45LmGK+RcaSnJe7hG+KRtjuhjI7RdzMeDCX73SfUsal+rHeuEw/mmjYmiIItXhFTDn8ZvVwpBKv7xsJG90DkaX2vaTk0wgJdMnpVIuIRBa4EkmMWOQ3bMLGkLQeK/4FUkNcvQ/4+zcZsg4cY9Q7Fj55DD41hAUdF6SYODtn5qMPsTCnJz44glHt/oseKXMSd556NIw2HOvihbJW7Rwl4OEjGaO/dF4nUw4c9tHWmMn9dLslAVpUuZOb7ykgP0jk79ldT3Dv+2Hj0CdAWT2cJAdFX58KQ9jUPT3tBnObSF1lGMI7t77VU= m3tam3re@m3-nix" + ]; + }; + # List packages installed in system profile. To search, run: + # $ nix search wget + environment.systemPackages = with pkgs; [neovim git]; + + # Some programs need SUID wrappers, can be configured further or are + # started in user sessions. + # programs.mtr.enable = true; + # programs.gnupg.agent = { + # enable = true; + # enableSSHSupport = true; + # }; + + # List services that you want to enable: + + # Enable the OpenSSH daemon. + services.openssh = { + enable = true; + settings.PermitRootLogin = "no"; + }; + + # [[Open ports in the firewall. + # networking.firewall.allowedTCPPorts = [ ... ]; + # 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.stateVersion . + system.stateVersion = "24.11"; # Did you read the comment? +} diff --git a/hosts/m3-zelda/default.nix b/hosts/m3-zelda/default.nix new file mode 100644 index 0000000..70374b2 --- /dev/null +++ b/hosts/m3-zelda/default.nix @@ -0,0 +1,16 @@ +{ + imports = [ + ./configuration.nix + ./services + ]; + + nix = { + settings = { + experimental-features = "nix-command flakes"; + trusted-users = [ + "root" + "m3tam3re" + ]; # Set users that are allowed to use the flake command + }; + }; +} diff --git a/hosts/m3-zelda/disko-config.nix b/hosts/m3-zelda/disko-config.nix new file mode 100644 index 0000000..324d0aa --- /dev/null +++ b/hosts/m3-zelda/disko-config.nix @@ -0,0 +1,39 @@ +{ + disko.devices = { + disk = { + main = { + type = "disk"; + device = "/dev/sda"; # CHANGE ME + content = { + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; # for GRUB MBR + priority = 1; + }; + esp = { + size = "512M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = ["defaults" "umask=0077"]; + }; + }; + root = { + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + mountOptions = ["noatime" "nodiratime" "discard"]; + }; + }; + }; + }; + }; + }; + }; +} diff --git a/hosts/m3-zelda/hardware-configuration-image.nix b/hosts/m3-zelda/hardware-configuration-image.nix new file mode 100644 index 0000000..f4f1bed --- /dev/null +++ b/hosts/m3-zelda/hardware-configuration-image.nix @@ -0,0 +1,32 @@ +# 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. +{ + lib, + modulesPath, + ... +}: { + imports = [ + (modulesPath + "/profiles/qemu-guest.nix") + ]; + + boot.initrd.availableKernelModules = ["ata_piix" "uhci_hcd" "virtio_pci" "virtio_scsi" "sd_mod" "sr_mod"]; + boot.initrd.kernelModules = []; + boot.kernelModules = []; + boot.extraModulePackages = []; + + fileSystems."/" = { + device = "/dev/disk/by-label/nixos"; + fsType = "ext4"; + options = ["noatime" "nodiratime" "discard"]; + }; + + # 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..useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.ens18.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; +} diff --git a/hosts/m3-zelda/hardware-configuration.nix b/hosts/m3-zelda/hardware-configuration.nix new file mode 100644 index 0000000..8531129 --- /dev/null +++ b/hosts/m3-zelda/hardware-configuration.nix @@ -0,0 +1,34 @@ +# 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. +{ + lib, + modulesPath, + ... +}: { + imports = [ + (modulesPath + "/profiles/qemu-guest.nix") + ./disko-config.nix + ]; + + boot.initrd.availableKernelModules = ["ata_piix" "uhci_hcd" "virtio_pci" "virtio_scsi" "sd_mod" "sr_mod"]; + boot.initrd.kernelModules = []; + boot.kernelModules = []; + boot.extraModulePackages = []; + + boot.loader.grub = { + enable = true; + device = "nodev"; + efiSupport = true; + efiInstallAsRemovable = true; + }; + + # 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..useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.ens18.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; +} diff --git a/hosts/m3-zelda/services/containers/default.nix b/hosts/m3-zelda/services/containers/default.nix new file mode 100644 index 0000000..4110fae --- /dev/null +++ b/hosts/m3-zelda/services/containers/default.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./slash.nix + ]; +} diff --git a/hosts/m3-zelda/services/containers/slash.nix b/hosts/m3-zelda/services/containers/slash.nix new file mode 100644 index 0000000..7a58032 --- /dev/null +++ b/hosts/m3-zelda/services/containers/slash.nix @@ -0,0 +1,26 @@ +{ + virtualisation.oci-containers.containers."slash" = { + image = "docker.io/yourselfhosted/slash:latest"; + ports = ["127.0.0.1:3010:5231"]; + volumes = [ + "slash_data:/var/opt/slash" + ]; + }; + # Traefik configuration specific to littlelink + services.traefik.dynamicConfigOptions.http = { + services.slash.loadBalancer.servers = [ + { + url = "http://localhost:3010/"; + } + ]; + + routers.slash = { + rule = "Host(`slash.tr.m3ta.dev`)"; + tls = { + certResolver = "godaddy"; + }; + service = "slash"; + entrypoints = "websecure"; + }; + }; +} diff --git a/hosts/m3-zelda/services/default.nix b/hosts/m3-zelda/services/default.nix new file mode 100644 index 0000000..b526548 --- /dev/null +++ b/hosts/m3-zelda/services/default.nix @@ -0,0 +1,7 @@ +{ + imports = [ + ./containers + ./podman.nix + ./traefik.nix + ]; +} diff --git a/hosts/m3-zelda/services/podman.nix b/hosts/m3-zelda/services/podman.nix new file mode 100644 index 0000000..ab0a896 --- /dev/null +++ b/hosts/m3-zelda/services/podman.nix @@ -0,0 +1,20 @@ +{pkgs, ...}: { + virtualisation = { + podman = { + enable = true; + dockerCompat = true; + autoPrune = { + enable = true; + dates = "weekly"; + flags = [ + "--filter=until=24h" + "--filter=label!=important" + ]; + }; + defaultNetwork.settings.dns_enabled = true; + }; + }; + environment.systemPackages = with pkgs; [ + podman-compose + ]; +} diff --git a/hosts/m3-zelda/services/traefik.nix b/hosts/m3-zelda/services/traefik.nix new file mode 100644 index 0000000..e7126da --- /dev/null +++ b/hosts/m3-zelda/services/traefik.nix @@ -0,0 +1,77 @@ +{ + services.traefik = { + enable = true; + staticConfigOptions = { + log = { + level = "WARN"; + }; + api = {}; # enable API handler + entryPoints = { + web = { + address = ":80"; + http.redirections.entryPoint = { + to = "websecure"; + scheme = "https"; + }; + }; + websecure = { + address = ":443"; + }; + }; + certificatesResolvers = { + godaddy = { + acme = { + email = "letsencrypt.org.btlc2@passmail.net"; + storage = "/var/lib/traefik/acme.json"; + caserver = "https://acme-v02.api.letsencrypt.org/directory"; + dnsChallenge = { + provider = "godaddy"; + resolvers = ["1.1.1.1:53" "8.8.8.8:53"]; + propagation.delayBeforeChecks = 120; # Important: Increase delay for slow DNS propagation + }; + }; + }; + }; + }; + dynamicConfigOptions = { + http = { + middlewares = { + auth = { + basicAuth = { + users = ["m3tam3re:$apr1$6LQhXb/m$xUqwJYKJwFarhnga5cM.n/"]; + }; + }; + }; + routers = { + api = { + rule = "Host(`p.tr.m3ta.dev`)"; + service = "api@internal"; + entrypoints = ["websecure"]; + middlewares = ["auth"]; + tls = { + certResolver = "godaddy"; + }; + }; + }; + }; + }; + }; + + system.activationScripts.traefikEnv = { + text = '' + echo "Creating Traefik env file..." + cat > /var/lib/traefik/env << 'EOF' + GODADDY_API_KEY=supersecretkey + GODADDY_API_SECRET=supersecretsecret + EOF + chmod 600 /var/lib/traefik/env + ''; + deps = []; + }; + + systemd.services.traefik.serviceConfig = { + EnvironmentFile = ["/var/lib/traefik/env"]; + }; + + networking.firewall.allowedTCPPorts = [80 443]; +}