From 7347183da7b5ff1bde96ac1987a3018b2704b4ef Mon Sep 17 00:00:00 2001 From: Grigory Shipunov Date: Thu, 2 Jan 2025 19:32:39 +0000 Subject: [PATCH] add minime --- flake.nix | 11 +++ hosts/minime/configuration.nix | 121 ++++++++++++++++++++++++ hosts/minime/default.nix | 7 ++ hosts/minime/hardware-configuration.nix | 72 ++++++++++++++ hosts/minime/zfs.nix | 31 ++++++ modules/server/default.nix | 5 +- modules/server/ssh.nix | 1 + 7 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 hosts/minime/configuration.nix create mode 100644 hosts/minime/default.nix create mode 100644 hosts/minime/hardware-configuration.nix create mode 100644 hosts/minime/zfs.nix diff --git a/flake.nix b/flake.nix index 6b18a48..6efad80 100644 --- a/flake.nix +++ b/flake.nix @@ -79,6 +79,17 @@ ./modules/basic-tools ]; }; + minime = nixpkgs-stable.lib.nixosSystem { + system = "x86_64-linux"; + specialArgs = { inherit inputs; }; + modules = [ + sops-nix.nixosModules.sops + + ./hosts/minime + ./modules/basic-tools + ./modules/server + ]; + }; }; }; } diff --git a/hosts/minime/configuration.nix b/hosts/minime/configuration.nix new file mode 100644 index 0000000..b169a06 --- /dev/null +++ b/hosts/minime/configuration.nix @@ -0,0 +1,121 @@ +# 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, ... }: + +{ + imports = + [ # Include the results of the hardware scan. + ./hardware-configuration.nix + ]; + + # Use the systemd-boot EFI boot loader. + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + networking.hostName = "minime"; # Define your hostname. + # 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/Amsterdam"; + + # 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 = false; + + + # 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 + # services.pipewire = { + # enable = true; + # pulse.enable = true; + # }; + + # 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.alice = { + # isNormalUser = true; + # extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user. + # packages = with pkgs; [ + # tree + # ]; + # }; + + # programs.firefox.enable = true; + + # List packages installed in system profile. To search, run: + # $ nix search wget + # environment.systemPackages = with pkgs; [ + # vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default. + # wget + # ]; + + # 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; + + # 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/minime/default.nix b/hosts/minime/default.nix new file mode 100644 index 0000000..8d6fb09 --- /dev/null +++ b/hosts/minime/default.nix @@ -0,0 +1,7 @@ +{ ... }: { + imports = [ + ./configuration.nix + ./hardware-configuration.nix + ./zfs.nix + ]; +} diff --git a/hosts/minime/hardware-configuration.nix b/hosts/minime/hardware-configuration.nix new file mode 100644 index 0000000..49ba6d6 --- /dev/null +++ b/hosts/minime/hardware-configuration.nix @@ -0,0 +1,72 @@ +# 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 + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "xhci_pci" "thunderbolt" "nvme" "usbhid" "usb_storage" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "zpool/nixos/root"; + fsType = "zfs"; + options = [ "zfsutil" ]; + }; + + fileSystems."/boot" = + { device = "/dev/disk/by-uuid/12CE-A600"; + fsType = "vfat"; + options = [ "fmask=0022" "dmask=0022" ]; + }; + + fileSystems."/nix" = + { device = "zpool/nixos/nix"; + fsType = "zfs"; + options = [ "zfsutil" ]; + }; + + fileSystems."/home" = + { device = "zpool/data/home"; + fsType = "zfs"; + options = [ "zfsutil" ]; + }; + + fileSystems."/var" = + { device = "zpool/data/var"; + fsType = "zfs"; + options = [ "zfsutil" ]; + }; + + fileSystems."/var/lib" = + { device = "zpool/data/var/lib"; + fsType = "zfs"; + options = [ "zfsutil" ]; + }; + + swapDevices = + [ { + device = "/dev/disk/by-partuuid/5c3e37ec-c277-4487-8169-813446a5f723"; + randomEncryption = 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.enp0s13f0u1u1.useDHCP = lib.mkDefault true; + # networking.interfaces.enp2s0f0.useDHCP = lib.mkDefault true; + # networking.interfaces.enp2s0f1.useDHCP = lib.mkDefault true; + # networking.interfaces.enp87s0.useDHCP = lib.mkDefault true; + # networking.interfaces.enp90s0.useDHCP = lib.mkDefault true; + # networking.interfaces.wlp91s0.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/hosts/minime/zfs.nix b/hosts/minime/zfs.nix new file mode 100644 index 0000000..a2a1acd --- /dev/null +++ b/hosts/minime/zfs.nix @@ -0,0 +1,31 @@ +{ pkgs, lib, config, ... }: { + services.fstrim.enable = true; + services.zfs = { + autoSnapshot.enable = true; + trim.enable = true; + autoScrub = { + enable = true; + pools = [ "zpool" ]; + }; + }; + networking.hostId = "41ba28ff"; + boot = { + kernelPackages = let + zfsCompatibleKernelPackages = lib.filterAttrs ( + name: kernelPackages: + (builtins.match "linux_[0-9]+_[0-9]+" name) != null + && (builtins.tryEval kernelPackages).success + && (!kernelPackages.${config.boot.zfs.package.kernelModuleAttribute}.meta.broken) + ) pkgs.linuxKernel.packages; + latestKernelPackage = lib.last ( + lib.sort (a: b: (lib.versionOlder a.kernel.version b.kernel.version)) ( + builtins.attrValues zfsCompatibleKernelPackages + ) + ); +in latestKernelPackage; + supportedFilesystems = [ "zfs" ]; + kernelParams = [ "nohibernate" ]; + plymouth.enable = false; + tmp.useTmpfs = true; + }; +} diff --git a/modules/server/default.nix b/modules/server/default.nix index 319d0cc..c20efcd 100644 --- a/modules/server/default.nix +++ b/modules/server/default.nix @@ -8,17 +8,18 @@ # unpriviliged user security.sudo.enable = true; - users.users.g = { + users.users."0xa" = { openssh.authorizedKeys.keys = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHv82n6F6kwJ3/EMYlOoCc1/NaYFW7QHC5F8jKVzdlio gshipunov@toaster" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA3to/h8Myn+zXAkjboaRVqOfmtDz7VpIHhHbaRoYyPX g.shipunov@uva.nl" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICPPG1va3CG8uAXV+ACRFPdi8FicpdOyXqb7eSZJCPXx pixel" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl9iYG5oHBq/poBn7Jf1/FGWWbAnbx+NKjs7qtT3uAK 0xa@toaster 2024-12-31" ]; extraGroups = [ "wheel" ]; group = "users"; - home = "/home/g"; + home = "/home/0xa"; isNormalUser = true; uid = 1000; }; diff --git a/modules/server/ssh.nix b/modules/server/ssh.nix index fae0682..1eefdd3 100644 --- a/modules/server/ssh.nix +++ b/modules/server/ssh.nix @@ -13,5 +13,6 @@ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHv82n6F6kwJ3/EMYlOoCc1/NaYFW7QHC5F8jKVzdlio gshipunov@toaster" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA3to/h8Myn+zXAkjboaRVqOfmtDz7VpIHhHbaRoYyPX g.shipunov@uva.nl" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAlRhs/h3zTfonh/8wTZPEHnLAWXtedpF3ulJOwDbTGL owner@pixel" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl9iYG5oHBq/poBn7Jf1/FGWWbAnbx+NKjs7qtT3uAK 0xa@toaster 2024-12-31" ]; }