From 4c89c45e3e1a1a5152c4fc70e1f29b0b349934d0 Mon Sep 17 00:00:00 2001 From: transcaffeine Date: Sun, 30 Mar 2025 19:43:10 +0000 Subject: [PATCH] feat: initial commit, add flake and host 'backstage' --- flake.lock | 44 ++++++++++ flake.nix | 17 ++++ hosts/backstage/configuration.nix | 94 ++++++++++++++++++++++ hosts/backstage/default.nix | 9 +++ hosts/backstage/hardware-configuration.nix | 57 +++++++++++++ hosts/backstage/network.nix | 10 +++ services/sshd/default.nix | 10 +++ 7 files changed, 241 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 hosts/backstage/configuration.nix create mode 100644 hosts/backstage/default.nix create mode 100644 hosts/backstage/hardware-configuration.nix create mode 100644 hosts/backstage/network.nix create mode 100644 services/sshd/default.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..005d94f --- /dev/null +++ b/flake.lock @@ -0,0 +1,44 @@ +{ + "nodes": { + "nixos-hardware": { + "locked": { + "lastModified": 1743420942, + "narHash": "sha256-b/exDDQSLmENZZgbAEI3qi9yHkuXAXCPbormD8CSJXo=", + "owner": "NixOS", + "repo": "nixos-hardware", + "rev": "de6fc5551121c59c01e2a3d45b277a6d05077bc4", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "master", + "repo": "nixos-hardware", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1743501102, + "narHash": "sha256-7PCBQ4aGVF8OrzMkzqtYSKyoQuU2jtpPi4lmABpe5X4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "02f2af8c8a8c3b2c05028936a1e84daefa1171d4", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixos-hardware": "nixos-hardware", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d79b5a0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,17 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; + nixos-hardware.url = "github:NixOS/nixos-hardware/master"; + }; + + outputs = inputs @ { self, nixpkgs, ... }: { + nixosConfigurations.backstage = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./hosts/backstage + ]; + specialArgs = { inherit inputs; }; + }; + }; +} + diff --git a/hosts/backstage/configuration.nix b/hosts/backstage/configuration.nix new file mode 100644 index 0000000..44d1ad3 --- /dev/null +++ b/hosts/backstage/configuration.nix @@ -0,0 +1,94 @@ +{ config, lib, pkgs, ... }: + +{ + imports = + [ + ../../services/sshd + ]; + + # Use the systemd-boot EFI boot loader. + boot = { + loader = { + systemd-boot.enable = true; + efi = { + canTouchEfiVariables = true; + efiSysMountPoint = "/boot/efi"; + }; + }; + initrd = { + network = { + enable = true; + ssh = { + enable = true; + port = 22; + authorizedKeys = config.users.users.root.openssh.authorizedKeys.keys; + hostKeys = [ + "/boot/efi/initrd_id_ed25519" + "/boot/efi/initrd_id_rsa4096" + ]; + }; + }; + systemd = { + enable = true; + network = { + enable = true; + networks."10-dhcp" = { + matchConfig.Name = "enp1s0"; + DHCP = "yes"; + }; + }; + targets.initrd.wants = [ + "systemd-networkd-wait-online@enp1s0.service" + ]; + users.root.shell = "/bin/systemd-tty-ask-password-agent"; + }; + }; + }; + + # Set your time zone. + time.timeZone = "Europe/Berlin"; + + # Select internationalisation properties. + # i18n.defaultLocale = "en_US.UTF-8"; + # console = { + # font = "Lat2-Terminus16"; + # keyMap = "us"; + # useXkbConfig = true; # use xkb.options in tty. + # }; + + environment.systemPackages = with pkgs; [ + vim + git + tmux + htop + ]; + + users.users.root = { + openssh.authorizedKeys.keys = [ + ''ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCnjrKWYc0bcIsTkdpyC+yAsxSeY9M1WxVDNm3I/R3BYqyvfFuzJMQyh5APhM52yKGMN9UOuJPNPz0C4P6EY3iC3ZqUHFJ6ILrZZxdLZBVxdy2F19Xv6XcZkZxLpRKWapVFECF5z/Bi0rg1uzNRyrHjfZWcHfHIvlqxUYiitvvTbbSMQKqEV8wlnshSzBoYzaKtV1+crwlgz6wCnXq8HIupEeWfUc9kc+zunpYnuHnU5Z3HhzQGBuIiPoVritDjOo7qYREftV4qQ15xFWdezsMZlR15edwZeyNdAEx044QgaGddC8uEMoi5cp4APIqH1cEkIvSU6Y+esdgZ4CHU6M5G5ub5PTT2TaKoUMLLFtpW6QImjVApixFTHWR7tUhqInplWWLqvviS4MoI1ppxgcDUg/bgPdeDBsoRkbESr2uT8ResNi9DlPlN2rlUjlb28awzHm7agFhwfPQZ1afnFSUh0tTFz1WeR7xIGhxR1xXc8sapJhgLnYYWpR2NaJzbYYdk7CWW/3rgEsJem7Kvll6HevnFgRP/uVhEyGZl9hw+tECzvwB/LEmQ/4raDMxqOB9XO9kusJX/jTnQIObrFubfKn3ToXlYbQxZX9+QobANvQ8huILz1bBeH8aKjf9RXu+j4VNyoCKhzU/v0MIdRCsgVWgjuYXMGRo0MFMFyMqQiw=='' + ]; + }; + + # 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 + # ]; + # }; + + # List services that you want to enable: + + # Open ports in the firewall. + # networking.firewall.allowedTCPPorts = [ ... ]; + # networking.firewall.allowedUDPPorts = [ ... ]; + + # 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; + + system.stateVersion = "24.11"; # Did you read the comment? +} + diff --git a/hosts/backstage/default.nix b/hosts/backstage/default.nix new file mode 100644 index 0000000..39a4e28 --- /dev/null +++ b/hosts/backstage/default.nix @@ -0,0 +1,9 @@ +{ config, lib, pkgs, modulesPath, ...}: + +{ + imports = [ + ./hardware-configuration.nix + ./configuration.nix + ./network.nix + ]; +} diff --git a/hosts/backstage/hardware-configuration.nix b/hosts/backstage/hardware-configuration.nix new file mode 100644 index 0000000..3d94fc9 --- /dev/null +++ b/hosts/backstage/hardware-configuration.nix @@ -0,0 +1,57 @@ +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = + [ (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot = { + initrd = { + availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usbhid" "usb_storage" "sd_mod" "virtio_pci" "r8169" ]; + kernelModules = [ "dm-snapshot" ]; + luks.devices."backstage" = { + preLVM = true; + device = "/dev/disk/by-uuid/7f3ccd2d-8022-491e-baa1-675805919fd7"; + }; + }; + kernelModules = [ "kvm-intel" ]; + kernelParams = [ + "zfs.zfs_arc_max=1024000000" + ]; + }; + + fileSystems."/" = + { device = "zpool/root"; + fsType = "zfs"; + }; + + fileSystems."/home" = + { device = "zpool/home"; + fsType = "zfs"; + }; + + fileSystems."/nix" = + { device = "zpool/nix"; + fsType = "zfs"; + }; + + fileSystems."/nix/store" = + { device = "zpool/nix/store"; + fsType = "zfs"; + }; + + fileSystems."/boot/efi" = + { device = "/dev/disk/by-uuid/4E32-FA6E"; + fsType = "vfat"; + options = [ "fmask=0022" "dmask=0022" ]; + }; + + swapDevices = [ + { + device = "/dev/mapper/backstage-swap"; + } + ]; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/hosts/backstage/network.nix b/hosts/backstage/network.nix new file mode 100644 index 0000000..e228c1e --- /dev/null +++ b/hosts/backstage/network.nix @@ -0,0 +1,10 @@ +{ config, lib, pkgs, modulesPath, ... }: + +{ + networking = { + useNetworkd = true; + useDHCP = lib.mkDefault true; + hostName = "backstage"; + hostId = "0ccd2304"; + }; +} diff --git a/services/sshd/default.nix b/services/sshd/default.nix new file mode 100644 index 0000000..a7b61c1 --- /dev/null +++ b/services/sshd/default.nix @@ -0,0 +1,10 @@ +{pkgs, ...}: +{ + services.openssh = { + enable = true; + settings = { + PasswordAuthentication = true; + PermitRootLogin = "yes"; + }; + }; +}