From 71dc7e809a55b9ce6383ec7ce9211e2a0be2c2ac Mon Sep 17 00:00:00 2001 From: iFargle Date: Sat, 1 Jul 2023 16:48:31 +0900 Subject: [PATCH] Let's see what breaks! reorganize everything --- README.md | 20 +- common/dotfiles/git.nix | 8 + laptop/configuration.nix => configuration.nix | 6 +- {laptop => desktops}/gnome.nix | 0 flake.nix | 101 +++++++++++ .../lenovo-p1.nix | 0 laptop/home-manager.nix => home-manager.nix | 0 laptop/flake.nix | 46 ----- raspberry-pi/rpi4-configuration.nix | 51 ------ laptop/secureboot.nix => secureboot.nix | 0 {laptop => software}/promtail.nix | 0 testing/configuration.nix | 171 ------------------ testing/home-manager.nix | 25 --- testing/test-configuration.nix | 49 ----- testing/variables.nix | 15 -- {laptop => users/albert}/dconf.nix | 3 +- users/albert/home.nix | 15 ++ users/root/home.nix | 15 ++ 18 files changed, 162 insertions(+), 363 deletions(-) create mode 100644 common/dotfiles/git.nix rename laptop/configuration.nix => configuration.nix (98%) rename {laptop => desktops}/gnome.nix (100%) create mode 100644 flake.nix rename laptop/hardware-configuration.nix => hardware/lenovo-p1.nix (100%) rename laptop/home-manager.nix => home-manager.nix (100%) delete mode 100644 laptop/flake.nix delete mode 100644 raspberry-pi/rpi4-configuration.nix rename laptop/secureboot.nix => secureboot.nix (100%) rename {laptop => software}/promtail.nix (100%) delete mode 100644 testing/configuration.nix delete mode 100644 testing/home-manager.nix delete mode 100644 testing/test-configuration.nix delete mode 100644 testing/variables.nix rename {laptop => users/albert}/dconf.nix (99%) create mode 100644 users/albert/home.nix create mode 100644 users/root/home.nix diff --git a/README.md b/README.md index 9061ee10..91a94b3a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,21 @@ # nix -Repo for nix configuration files \ No newline at end of file +Repo for nix configuration files +# Information +## Common +* Used to house all common configurations, including dotfiles + +## Desktops +* Used to house DWM configurations, such as Gnome + +## Hardware +* Contains hardware configurations + +## Software +* Contains pieces of software, such as Promtail + +## users +* Contains user configurations via home-manager + +## Root +* `flake.nix` - The main configuration file for all systems \ No newline at end of file diff --git a/common/dotfiles/git.nix b/common/dotfiles/git.nix new file mode 100644 index 00000000..26d51817 --- /dev/null +++ b/common/dotfiles/git.nix @@ -0,0 +1,8 @@ + programs.git = { + enable = true; + userName = "albert"; + userEmail = "albert@sysctl.io"; + extraConfig = { + credential.helper = "cache --timeout=25920000"; + }; + }; \ No newline at end of file diff --git a/laptop/configuration.nix b/configuration.nix similarity index 98% rename from laptop/configuration.nix rename to configuration.nix index 99f3a6de..7359b3d9 100644 --- a/laptop/configuration.nix +++ b/configuration.nix @@ -13,12 +13,10 @@ { lib, config, pkgs, ... }: { imports = [ - # Home-Manager Nix configuration file. - ./home-manager.nix # Gnome configuration file. - ./gnome.nix + ./desktops/gnome.nix # Promtail logging - ./promtail.nix + ./software/promtail.nix ]; # Keep the system up-to-date automatically diff --git a/laptop/gnome.nix b/desktops/gnome.nix similarity index 100% rename from laptop/gnome.nix rename to desktops/gnome.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..d2db5951 --- /dev/null +++ b/flake.nix @@ -0,0 +1,101 @@ +{ + description = "NixOS System Config"; + + inputs = { + # NixOS packages + nixpkgs.url = "nixpkgs/nixos-23.05"; + + # Manage dotfiles in a home directory + home-manager.url = "github:nix-community/home-manager/release-23.05"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + + # Secureboot Configuration + lanzaboote.url = "github:nix-community/lanzaboote"; + lanzaboote.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { nixpkgs, home-manager, lanzaboote, ... }: + let + system = "x86_64-linux"; + hostname = "nixos-p1"; + pkgs = import nixpkgs { + # Tells Flake what OS version we are using + inherit system; + config = { allowUnfree = true; }; + }; + + lib = nixpkgs.lib; + in { + # Set up users with home-manager + homeManagerConfigurations = { + # Configuration for user "Albert" + albert = home-manager.lib.homeManagerConfiguration { + inherit system pkgs; + username = "albert"; + homeDirectory = "/home/albert"; + configuration = { + imports = [ + ./users/albert/home.nix; + ]; + }; + }; + # Configuration for user "root" + root = home-manager.lib.homeManagerConfiguration { + inherit system pkgs; + username = "root"; + homeDirectory = "/root"; + configuration = { + imports = [ + ./users/root/home.nix; + ]; + }; + }; + }; + + # NixOS Configuration files: + nixosConfigurations = { + # Declare the configuration for "nixos-laptop": + nixos-laptop = lib.nixosSystem { + inherit system hostname; + modules = [ + # Hardware Configuration + ./laptop/lenovo-p1.nix + + # SecureBoot Configuration + lanzaboote.nixosModules.lanzaboote + + # NixOS Configuration file + ./configuration.nix + + # Tell home-manager to use both global and user packages: + home-manager.nixosModules.home-manager { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + } + ]; # modules + }; # lib.nixosSystem - nixos-laptop + + # Declare the configuration for "nixos-p1", my laptop: + nixos-desktop = lib.nixosSystem { + inherit system hostname; + modules = [ + # Hardware Configuration + ./desktop/desktop.nix + + # SecureBoot Configuration + lanzaboote.nixosModules.lanzaboote + + # NixOS Configuration file + ./configuration.nix + + # Tell home-manager to use both global and user packages: + home-manager.nixosModules.home-manager { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + } + ]; # modules + }; # lib.nixosSystem - nixos-laptop + + }; # nixosConfiguration + }; +} \ No newline at end of file diff --git a/laptop/hardware-configuration.nix b/hardware/lenovo-p1.nix similarity index 100% rename from laptop/hardware-configuration.nix rename to hardware/lenovo-p1.nix diff --git a/laptop/home-manager.nix b/home-manager.nix similarity index 100% rename from laptop/home-manager.nix rename to home-manager.nix diff --git a/laptop/flake.nix b/laptop/flake.nix deleted file mode 100644 index 32ef9c43..00000000 --- a/laptop/flake.nix +++ /dev/null @@ -1,46 +0,0 @@ -{ - description = "Laptop System Config"; - - inputs = { - # NixOS packages - nixpkgs.url = "nixpkgs/nixos-23.05"; - - # Manage dotfiles in a home directory - home-manager.url = "github:nix-community/home-manager/release-23.05"; - home-manager.inputs.nixpkgs.follows = "nixpkgs"; - - # Secureboot Configuration - lanzaboote.url = "github:nix-community/lanzaboote"; - lanzaboote.inputs.nixpkgs.follows = "nixpkgs"; - }; - - outputs = { nixpkgs, home-manager, lanzaboote, ... }: - let - system = "x86_64-linux"; - pkgs = import nixpkgs { - # Tells Flake what OS version we are using - inherit system; - config = { allowUnfree = true; }; - }; - - lib = nixpkgs.lib; - in { - nixosConfigurations = { - # Declare the configuration for "nixos-p1", my laptop: - nixos-p1 = lib.nixosSystem { - inherit system; - - modules = [ - ./hardware-configuration.nix - lanzaboote.nixosModules.lanzaboote - ./configuration.nix - - home-manager.nixosModules.home-manager { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - } - ]; - }; - }; - }; -} \ No newline at end of file diff --git a/raspberry-pi/rpi4-configuration.nix b/raspberry-pi/rpi4-configuration.nix deleted file mode 100644 index 0fef991b..00000000 --- a/raspberry-pi/rpi4-configuration.nix +++ /dev/null @@ -1,51 +0,0 @@ -{ config, pkgs, lib, ... }: - -{ - # This configuration worked on 09-03-2021 nixos-unstable @ commit 102eb68ceec - # The image used https://hydra.nixos.org/build/134720986 - - boot = { - kernelPackages = pkgs.linuxPackages_rpi4; - tmpOnTmpfs = true; - initrd.availableKernelModules = [ "usbhid" "usb_storage" ]; - # ttyAMA0 is the serial console broken out to the GPIO - kernelParams = [ - "8250.nr_uarts=1" - "console=ttyAMA0,115200" - "console=tty1" - # A lot GUI programs need this, nearly all wayland applications - "cma=128M" - ]; - }; - - boot.loader.raspberryPi = { - enable = true; - version = 4; - }; - boot.loader.grub.enable = false; - - # Required for the Wireless firmware - hardware.enableRedistributableFirmware = true; - - networking = { - hostName = "nixos-raspi-4"; # Define your hostname. - networkmanager = { - enable = true; - }; - }; - - nix = { - autoOptimiseStore = true; - gc = { - automatic = true; - dates = "weekly"; - options = "--delete-older-than 30d"; - }; - # Free up to 1GiB whenever there is less than 100MiB left. - extraOptions = '' - min-free = ${toString (100 * 1024 * 1024)} - max-free = ${toString (1024 * 1024 * 1024)} - ''; - }; - system.stateVersion = "20.09"; -} \ No newline at end of file diff --git a/laptop/secureboot.nix b/secureboot.nix similarity index 100% rename from laptop/secureboot.nix rename to secureboot.nix diff --git a/laptop/promtail.nix b/software/promtail.nix similarity index 100% rename from laptop/promtail.nix rename to software/promtail.nix diff --git a/testing/configuration.nix b/testing/configuration.nix deleted file mode 100644 index a8fb4b05..00000000 --- a/testing/configuration.nix +++ /dev/null @@ -1,171 +0,0 @@ -{ 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"; - 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/testing/home-manager.nix b/testing/home-manager.nix deleted file mode 100644 index 44e432c1..00000000 --- a/testing/home-manager.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ 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/testing/test-configuration.nix b/testing/test-configuration.nix deleted file mode 100644 index c4cae31f..00000000 --- a/testing/test-configuration.nix +++ /dev/null @@ -1,49 +0,0 @@ -{ config, pkgs, ... }: # A pinned version of Nixpkgs passed to the configuration by Nix - -{ - # Enable Nix flakes and the unified Nix CLI - nix.settings = { - experimental-features = "nix-command flakes"; - }; - - # Networking configuration - networking.hostName = "fedora-p1"; - - # Enable OpenSSH - services.openssh.enable = true; - - # Root filesystem - fileSystems."/" = { - device = "/dev/sda1"; - fsType = "ext4"; - }; - - # Create a user - users.users.albert = { - isNormalUser = false; - initialPassword = "Password"; - }; - - # Configure Tailscale - - - # CLI tools, language runtimes, shells, and other desired packages - environment.systemPackages = with pkgs; [ - curl - vim - git - htop - wget - tailscale - ]; - - # Enable services: - services = { - tailscale = { - enable = true; - }; - openssh = { - enable = true; - }; - } -} \ No newline at end of file diff --git a/testing/variables.nix b/testing/variables.nix deleted file mode 100644 index 49b11e73..00000000 --- a/testing/variables.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ - # 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 diff --git a/laptop/dconf.nix b/users/albert/dconf.nix similarity index 99% rename from laptop/dconf.nix rename to users/albert/dconf.nix index 7ed49751..a32b6838 100644 --- a/laptop/dconf.nix +++ b/users/albert/dconf.nix @@ -1,6 +1,7 @@ # Generated via dconf2nix: https://github.com/gvolpe/dconf2nix { lib, ... }: - + # dconf settings: + # https://github.com/gvolpe/dconf2nix with lib.hm.gvariant; { diff --git a/users/albert/home.nix b/users/albert/home.nix new file mode 100644 index 00000000..45e2c572 --- /dev/null +++ b/users/albert/home.nix @@ -0,0 +1,15 @@ +{ config, pkgs, ... }: { +# Home-Manager Manual +# https://nix-community.github.io/home-manager/index.html + +# Home-Manager Options Search +# https://mipmip.github.io/home-manager-option-search/ + + home-manager.users.albert = { + home.stateVersion = "23.05"; + imports = [ + ./dconf.nix + ../../common/dotfiles/git.nix + ]; + }; +} \ No newline at end of file diff --git a/users/root/home.nix b/users/root/home.nix new file mode 100644 index 00000000..39c3d5dd --- /dev/null +++ b/users/root/home.nix @@ -0,0 +1,15 @@ +{ config, pkgs, ... }: { +# Home-Manager Manual +# https://nix-community.github.io/home-manager/index.html + +# Home-Manager Options Search +# https://mipmip.github.io/home-manager-option-search/ + + home-manager.users.root = { + home.stateVersion = "23.05"; + imports = [ + ./dconf.nix + ../../common/dotfiles/git.nix + ]; + }; +}