From a7a3cbbc7a8f0c0c91f74c4f0dcfc69d9639ca82 Mon Sep 17 00:00:00 2001 From: JuliusFreudenberger Date: Fri, 8 Aug 2025 16:56:37 +0200 Subject: [PATCH] Add basic new server config Includes sshd for easy connecting in local virtualized environment. --- flake.lock | 30 +++++------ flake.nix | 12 +++++ hosts/nixos-server-test/default.nix | 51 +++++++++++++++++++ .../hardware-configuration.nix | 31 +++++++++++ modules/sshd.nix | 13 +++++ 5 files changed, 122 insertions(+), 15 deletions(-) create mode 100644 hosts/nixos-server-test/default.nix create mode 100644 hosts/nixos-server-test/hardware-configuration.nix create mode 100644 modules/sshd.nix diff --git a/flake.lock b/flake.lock index 000b4f1..88bab71 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1748372346, - "narHash": "sha256-7y7NZ6uW0GbT0h4gqfD2xvRuJj5IlPGw32oIc9Twga8=", + "lastModified": 1752998173, + "narHash": "sha256-ZlYpBp2WOe03UrpjJGz5KTOL/pp7A452hJO/Vc8C4/0=", "owner": "AdnanHodzic", "repo": "auto-cpufreq", - "rev": "becd5b89963fa54fef3566147f3fd2087f8a5842", + "rev": "562278377ffa96f3c1af49c7b499df028ce8d8bd", "type": "github" }, "original": { @@ -65,11 +65,11 @@ ] }, "locked": { - "lastModified": 1749154018, - "narHash": "sha256-gjN3j7joRvT3a8Zgcylnd4NFsnXeDBumqiu4HmY1RIg=", + "lastModified": 1753592768, + "narHash": "sha256-oV695RvbAE4+R9pcsT9shmp6zE/+IZe6evHWX63f2Qg=", "owner": "nix-community", "repo": "home-manager", - "rev": "7aae0ee71a17b19708b93b3ed448a1a0952bf111", + "rev": "fc3add429f21450359369af74c2375cb34a2d204", "type": "github" }, "original": { @@ -87,11 +87,11 @@ "pre-commit-hooks": "pre-commit-hooks" }, "locked": { - "lastModified": 1746906641, - "narHash": "sha256-b6few4tkqN2TWdrZTwWOjsWxA11rle7y9pcc0/ynuoE=", + "lastModified": 1752585957, + "narHash": "sha256-ogQo/MMNSIM4U4VQMieIrpLhjkgSbev3VR24foJ/h/U=", "owner": "~rycee", "repo": "lazy-apps", - "rev": "0b30a0bf524a661f9657c441d021aaa5724f12ff", + "rev": "3c3ce5001e24b6c12496a5920eee28a96f8d49d6", "type": "sourcehut" }, "original": { @@ -102,11 +102,11 @@ }, "nixos-hardware": { "locked": { - "lastModified": 1749195551, - "narHash": "sha256-W5GKQHgunda/OP9sbKENBZhMBDNu2QahoIPwnsF6CeM=", + "lastModified": 1754229794, + "narHash": "sha256-yOl7REX6O/1mh+tpscJPKgjK6nmXSMOB1xhmDNAMUZM=", "owner": "NixOS", "repo": "nixos-hardware", - "rev": "4602f7e1d3f197b3cb540d5accf5669121629628", + "rev": "a872d985392ee5b19d8409bfcc3f106de2070070", "type": "github" }, "original": { @@ -118,11 +118,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1749086602, - "narHash": "sha256-DJcgJMekoxVesl9kKjfLPix2Nbr42i7cpEHJiTnBUwU=", + "lastModified": 1754028485, + "narHash": "sha256-IiiXB3BDTi6UqzAZcf2S797hWEPCRZOwyNThJIYhUfk=", "owner": "nixos", "repo": "nixpkgs", - "rev": "4792576cb003c994bd7cc1edada3129def20b27d", + "rev": "59e69648d345d6e8fef86158c555730fa12af9de", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 558ac71..8adf2e8 100644 --- a/flake.nix +++ b/flake.nix @@ -90,6 +90,18 @@ ./hosts/backup-raspberrypi ]; }; + + server = nixpkgs.lib.nixosSystem rec { + system = "x86_64-linux"; + + specialArgs = { + inherit inputs outputs; + }; + + modules = [ + ./hosts/nixos-server-test + ]; + }; }; }; } diff --git a/hosts/nixos-server-test/default.nix b/hosts/nixos-server-test/default.nix new file mode 100644 index 0000000..a4421da --- /dev/null +++ b/hosts/nixos-server-test/default.nix @@ -0,0 +1,51 @@ +{ inputs, outputs, config, lib, pkgs, ... }: + +{ + imports = + [ + ../../modules/nix.nix + ../../modules/network-server.nix + ../../modules/locale.nix + ../../modules/server-cli.nix + ../../modules/nix.nix + ../../modules/sshd.nix + # Include the results of the hardware scan. + ./hardware-configuration.nix + ]; + # Use the GRUB 2 boot loader. + boot = { + loader.grub = { + enable = true; + device = "/dev/vda"; + }; + tmp.useTmpfs = true; + }; + networking.hostName = "nixos-server"; # Define your hostname. + users = { + users = { + julius = { + isNormalUser = true; + uid = 1000; + extraGroups = [ "wheel" "julius" ]; + }; + }; + groups = { + julius = { + gid = 1000; + }; + }; + }; + # 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 = "25.05"; # Did you read the comment? +} diff --git a/hosts/nixos-server-test/hardware-configuration.nix b/hosts/nixos-server-test/hardware-configuration.nix new file mode 100644 index 0000000..6dfd7c4 --- /dev/null +++ b/hosts/nixos-server-test/hardware-configuration.nix @@ -0,0 +1,31 @@ +# 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 + "/profiles/qemu-guest.nix") + ]; + + boot.initrd.availableKernelModules = [ "ahci" "xhci_pci" "virtio_pci" "sr_mod" "virtio_blk" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/e46c412a-8b6d-41b8-b53c-65d7a8fc39ed"; + fsType = "ext4"; + }; + + swapDevices = [ ]; + + # 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.enp1s0.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; +} diff --git a/modules/sshd.nix b/modules/sshd.nix new file mode 100644 index 0000000..49af4a5 --- /dev/null +++ b/modules/sshd.nix @@ -0,0 +1,13 @@ +{ + pkgs, + lib, + ... +}: { + services.openssh = { + enable = true; + settings = { + PasswordAuthentication = false; + PermitRootLogin = "no"; + }; + }; +}