From 8157a63f9ec3d6f3f144fade6496dad00171fbe5 Mon Sep 17 00:00:00 2001 From: iFargle Date: Thu, 29 Jun 2023 15:32:19 +0900 Subject: [PATCH] Lots of NIX Teesing --- server/configuration.nix | 173 ++++++++++++++++++++++++++++++++++ server/home-manager.nix | 25 +++++ server/test-configuration.nix | 26 +++-- server/variables.nix | 15 +++ 4 files changed, 232 insertions(+), 7 deletions(-) create mode 100644 server/configuration.nix create mode 100644 server/home-manager.nix create mode 100644 server/variables.nix diff --git a/server/configuration.nix b/server/configuration.nix new file mode 100644 index 00000000..a380dc8c --- /dev/null +++ b/server/configuration.nix @@ -0,0 +1,173 @@ +{ config, pkgs, ...}: { + # Desktop/Laptop configuration.nix + # Import other files to this config: + imports = [ + ./home-manager.nix + ./variables.nix + ]; + + # Basic configs + time.timeZone = ${timezone} + + # Boot settings + boot = { + blacklistedKernelModules = [ "nouveau" ]; + cleanTmpDir = true; + }; + + # Keep the system up-to-date automatically + system = { + stateVersion = ${nixos-version} + autoUpgrade = { + enable = true; + allowReboot = false; + channel = https://channels.nixos.org/nixos-${nixos-version} + }; + }; + + # Networking: + networking = { + hostname = ${hostname}; + enableIPv6 = false; + firewall = { + enable = true; + allowedTCPPorts = [ 22 ]; + allowedUDPPorts = [ 41641 ]; + }; + networkmanager = { + enable = true; + }; + }; + + # Create a user: + # https://nixos.org/manual/nixos/stable/index.html#sec-user-management + users.users.${username} = { + isNormalUser = false; + initialPassword = "Password"; + description = "${user-full-name}"; + extraGroups = [ "wheel", "networkmanager" ]; + uid = 1000; + shell = "/bin/bash" + }; + + # Enable various services: + services = { + openssh = { + enable = true; + }; + ntp = { + enable = true; + }; + tailscale = { + enable = true; + useRoutingFeatures = "server"; + }; + # X Display Manager + # https://nixos.org/manual/nixos/stable/index.html#sec-x11 + xserver = { + enable = true; + videoDrivers = nvidia; + autorun = true; + layout = "en"; + displayManager = { + gdm = { + enable = true; + }; + }; + desktopManager = { + gnome = { + enable = true; + }; + }; + # https://nixos.org/manual/nixos/stable/index.html#sec-gnome-enable + # Adding icon themes: https://nixos.org/manual/nixos/stable/index.html#sec-gnome-icons-and-gtk-themes + gnome = { + core-utilities.enable = false; + games.enable = false; + }; + }; + pipewire = { + enable = true; + alsa.enable = true; + alsa.support32bit = true; + }; + }; + + # NixPkgs configuration + nixpkgs = { + system = "${system-arch}" + config = { + allowUnfree = true; + }; + }; + + # Install various packages + environment = { + systemPackages = with pkgs; [ + vim + git + curl + htop + tailscale + iftop + jq + zip + tar + bash + ]; + + # If a GUI is enabled, install GUI apps: + if config.services.xserver.enable then [ + pkgs.firefox + pkgs.steam + pkgs.bitwarden + pkgs.lutris + pkgs.vscodium + pkgs.vlc + ]; + }; + + # Configure programs + programs = { + bash = { + enableCompletion = true; + enableLsColors = true; + shellAliases = { + d = "docker"; + dc = "docker-compose"; + de = "docker exec -it"; + ddate = "date +%Y.%m.%d"; + dday = "date +%A"; + e = "emacsclient -nw"; # emacs in a terminal + f = "fossil"; + g = "git"; + ga = "git add -A"; + gb = "git branch"; + gc = "git commit"; + gca = "git commit -a"; + gco = "git checkout"; + gd = "git diff"; + gl = "git pull --prune"; + gp = "git push origin HEAD"; + gs = "git status -sb"; + hs = "home-manager switch"; + ll = "ls -lah"; + rm = "rm -i"; + tdate = "date +%Y.%m.%d..%H.%M"; + ttime = "date +%H.%M"; + } + }; + firefox = { + # https://nixos.org/manual/nixos/stable/options.html#opt-programs.firefox.preferences + }; + vim = { + defaultEditor = true; + }; + xwayland = { + enable = true; + }; + dconf = { + enable = true; + }; + }; +} diff --git a/server/home-manager.nix b/server/home-manager.nix new file mode 100644 index 00000000..44e432c1 --- /dev/null +++ b/server/home-manager.nix @@ -0,0 +1,25 @@ +{ config, pkgs, ... }: +# https://mipmip.github.io/home-manager-option-search/ +# https://nix-community.github.io/home-manager/index.html +let + + if ${nixos-version} == "unstable": + home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/master.tar.gz"; +in +{ + imports = [ + (import "${home-manager}/nixos") + ./variables.nix + ]; + + home-manager.users.${username} = { + /* The home.stateVersion option does not have a default and must be set */ + home.stateVersion = "${nixos-version}"; + /* Here goes the rest of your home-manager config, e.g. home.packages = [ pkgs.foo ]; */ + programs.git = { + enable = true; + userName = "${username}"; + userEmail = "${email_address}"; + };} + }; +} \ No newline at end of file diff --git a/server/test-configuration.nix b/server/test-configuration.nix index a9c32968..c4cae31f 100644 --- a/server/test-configuration.nix +++ b/server/test-configuration.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: # A pinned version of Nixpkgs passed to the configuration by Nix +{ config, pkgs, ... }: # A pinned version of Nixpkgs passed to the configuration by Nix { # Enable Nix flakes and the unified Nix CLI @@ -24,14 +24,26 @@ initialPassword = "Password"; }; + # Configure Tailscale + + # CLI tools, language runtimes, shells, and other desired packages environment.systemPackages = with pkgs; [ curl - jq - wget + vim git - python - openssl - zsh + htop + wget + tailscale ]; -}sssss \ No newline at end of file + + # Enable services: + services = { + tailscale = { + enable = true; + }; + openssh = { + enable = true; + }; + } +} \ No newline at end of file diff --git a/server/variables.nix b/server/variables.nix new file mode 100644 index 00000000..49b11e73 --- /dev/null +++ b/server/variables.nix @@ -0,0 +1,15 @@ +{ + # User configs + username = "albert"; + user-full-name = "Albert J. Copeland"; + email_address = "albert@sysctl.io"; + + # Machine configs + hostname = "p1-fedora"; + hardware-type = "desktop"; # Desktop, Laptop, Server + system-arch = "x86_64-linux"; + + # OS configs + nixos-version = "unstable"; + timezone = "Asia/Tokyo"; +} \ No newline at end of file