From 1d0209fac361238802fa1dc9105ad2adbba61ccc Mon Sep 17 00:00:00 2001 From: KoenDR06 Date: Thu, 27 Feb 2025 22:12:26 +0100 Subject: [PATCH] First test of all machines --- flake.lock | 18 ++++++------ flake.nix | 15 ++++++++-- machines/luna/configuration.nix | 4 +++ machines/luna/modules.nix | 13 ++++++--- machines/solis/configuration.nix | 28 +++++++++++++++++- machines/solis/modules.nix | 37 +++++++++++++++++++++++ machines/terra/configuration.nix | 10 ++++++- machines/terra/modules.nix | 50 ++++++++++++++++++++++++++++++++ modules/boot/default.nix | 6 ++-- modules/boot/loader/grub.nix | 23 +++++++++++++++ modules/boot/refind.nix | 24 +++++++++++++++ modules/default.nix | 4 +-- modules/empty.nix | 11 +++++++ modules/terminal/zsh.nix | 2 +- modules/users/default.nix | 50 +++++++++++++++++++++++++++++--- modules/users/horseman.nix | 46 ----------------------------- 16 files changed, 268 insertions(+), 73 deletions(-) create mode 100644 machines/solis/modules.nix create mode 100644 machines/terra/modules.nix create mode 100644 modules/boot/loader/grub.nix create mode 100644 modules/boot/refind.nix create mode 100644 modules/empty.nix delete mode 100644 modules/users/horseman.nix diff --git a/flake.lock b/flake.lock index 46ac38f..bd2c7d2 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1736373539, - "narHash": "sha256-dinzAqCjenWDxuy+MqUQq0I4zUSfaCvN9rzuCmgMZJY=", + "lastModified": 1739757849, + "narHash": "sha256-Gs076ot1YuAAsYVcyidLKUMIc4ooOaRGO0PqTY7sBzA=", "owner": "nix-community", "repo": "home-manager", - "rev": "bd65bc3cde04c16755955630b344bc9e35272c56", + "rev": "9d3d080aec2a35e05a15cedd281c2384767c2cfe", "type": "github" }, "original": { @@ -23,11 +23,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1739055578, - "narHash": "sha256-2MhC2Bgd06uI1A0vkdNUyDYsMD0SLNGKtD8600mZ69A=", + "lastModified": 1740603184, + "narHash": "sha256-t+VaahjQAWyA+Ctn2idyo1yxRIYpaDxMgHkgCNiMJa4=", "owner": "nixos", "repo": "nixpkgs", - "rev": "a45fa362d887f4d4a7157d95c28ca9ce2899b70e", + "rev": "f44bd8ca21e026135061a0a57dcf3d0775b67a49", "type": "github" }, "original": { @@ -47,11 +47,11 @@ ] }, "locked": { - "lastModified": 1736549395, - "narHash": "sha256-XzwkB62Tt5UYoL1jXiHzgk/qz2fUpGHExcSIbyGTtI0=", + "lastModified": 1740569341, + "narHash": "sha256-WV8nY2IOfWdzBF5syVgCcgOchg/qQtpYh6LECYS9XkY=", "owner": "pjones", "repo": "plasma-manager", - "rev": "a53af7f1514ef4cce8620a9d6a50f238cdedec8b", + "rev": "5eeb0172fb74392053b66a8149e61b5e191b2845", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 274e294..6299428 100644 --- a/flake.nix +++ b/flake.nix @@ -41,7 +41,10 @@ nixosConfigurations = { luna = nixpkgs.lib.nixosSystem { - specialArgs = {inherit inputs outputs;}; + specialArgs = { + inherit inputs outputs; + headless = false; + }; modules = [ ./machines/luna/configuration.nix home-manager.nixosModules.home-manager @@ -52,7 +55,10 @@ ]; }; terra = nixpkgs.lib.nixosSystem { - specialArgs = {inherit inputs outputs;}; + specialArgs = { + inherit inputs outputs; + headless = false; + }; modules = [ ./machines/terra/configuration.nix home-manager.nixosModules.home-manager @@ -63,7 +69,10 @@ ]; }; solis = nixpkgs.lib.nixosSystem { - specialArgs = {inherit inputs outputs;}; + specialArgs = { + inherit inputs outputs; + headless = true; + }; modules = [ ./machines/solis/configuration.nix sops-nix.nixosModules.sops diff --git a/machines/luna/configuration.nix b/machines/luna/configuration.nix index 159912a..03dc122 100644 --- a/machines/luna/configuration.nix +++ b/machines/luna/configuration.nix @@ -9,8 +9,12 @@ imports = [ ./hardware-configuration.nix ./modules.nix + ../../modules ]; + horseman.username = "horseman"; + + networking.hostName = "luna"; system.stateVersion = "24.11"; diff --git a/machines/luna/modules.nix b/machines/luna/modules.nix index 9a54e7a..d080577 100644 --- a/machines/luna/modules.nix +++ b/machines/luna/modules.nix @@ -6,12 +6,13 @@ pkgs, ... }: { - imports = [../../modules]; + imports = [ + ../../modules + ../../modules/boot/loader/systemd.nix + ]; config.horseman = { - username = "horseman"; - - users.horseman.enable = true; + users.default.enable = true; base = { nix.enable = true; @@ -45,5 +46,9 @@ visual.enable = true; terminal.enable = true; }; + + terminal = { + zsh.enable = true; + }; }; } diff --git a/machines/solis/configuration.nix b/machines/solis/configuration.nix index c57ed6d..91087d9 100644 --- a/machines/solis/configuration.nix +++ b/machines/solis/configuration.nix @@ -6,7 +6,33 @@ pkgs, ... }: { - imports = []; + imports = [ + ./hardware-configuration.nix + ./modules.nix + ../../modules + ]; + + horseman.username = "horseman"; networking.hostName = "solis"; + + systemd.timers."backupSyncthing" = { + wantedBy = [ "timers.target" ]; + timerConfig = { + OnCalendar = "weekly"; + Persistent = true; + }; + }; + + systemd.services."backupSyncthing" = { + script = '' + /home/horseman/nix-config/misc/backup.sh + ''; + serviceConfig = { + Type = "oneshot"; + User = "horseman"; + }; + }; + + system.stateVersion = "24.11"; } diff --git a/machines/solis/modules.nix b/machines/solis/modules.nix new file mode 100644 index 0000000..aa955f5 --- /dev/null +++ b/machines/solis/modules.nix @@ -0,0 +1,37 @@ +{ + inputs, + outputs, + lib, + config, + pkgs, + ... +}: { + imports = [ + ../../modules + ../../modules/boot/loader/grub.nix + ]; + + config.horseman = { + users.default.enable = true; + + base = { + nix.enable = true; + locale.enable = true; + }; + + boot = { + loader.grub.enable = true; + }; + + network = { + mullvad.enable = true; + ssh.enable = true; + syncthing.enable = true; + tailscale.enable = true; + }; + + apps = { + terminal.enable = true; + }; + }; +} diff --git a/machines/terra/configuration.nix b/machines/terra/configuration.nix index 4b20042..a4a6d22 100644 --- a/machines/terra/configuration.nix +++ b/machines/terra/configuration.nix @@ -6,7 +6,15 @@ pkgs, ... }: { - imports = []; + imports = [ + ./hardware-configuration.nix + ./modules.nix + ../../modules + ]; + + horseman.username = "horseman"; networking.hostName = "terra"; + + system.stateVersion = "24.11"; } diff --git a/machines/terra/modules.nix b/machines/terra/modules.nix new file mode 100644 index 0000000..586c646 --- /dev/null +++ b/machines/terra/modules.nix @@ -0,0 +1,50 @@ +{ + inputs, + outputs, + lib, + config, + pkgs, + ... +}: { + imports = [ + ../../modules + ../../modules/boot/loader/systemd.nix + ]; + + config.horseman = { + users.default.enable = true; + + base = { + nix.enable = true; + locale.enable = true; + }; + + boot = { + loader.systemd.enable = true; + greeter.sddm.enable = true; + refind.enable = true; + }; + + wm = { + plasma.enable = true; + }; + + hardware = { + gpu.nvidia.enable = true; + audio.enable = true; + }; + + network = { + mullvad.enable = true; + ssh.enable = true; + syncthing.enable = true; + tailscale.enable = true; + }; + + apps = { + dev.enable = true; + visual.enable = true; + terminal.enable = true; + }; + }; +} diff --git a/modules/boot/default.nix b/modules/boot/default.nix index 01712e3..4864ce0 100644 --- a/modules/boot/default.nix +++ b/modules/boot/default.nix @@ -1,6 +1,8 @@ -{inputs, ...}: { +{inputs, headless, ...}: { imports = [ - ./loader/systemd.nix ./greeter/sddm.nix + ./refind.nix + + ( if headless then ./loader/grub.nix else ./loader/systemd.nix ) ]; } diff --git a/modules/boot/loader/grub.nix b/modules/boot/loader/grub.nix new file mode 100644 index 0000000..cb18c2f --- /dev/null +++ b/modules/boot/loader/grub.nix @@ -0,0 +1,23 @@ +{ + inputs, + outputs, + lib, + config, + pkgs, + ... +}: let + inherit (lib) mkEnableOption mkIf mkOption types; + cfg = config.horseman.boot.loader.grub; +in { + options = { + horseman.boot.loader.grub = { + enable = mkEnableOption "Sets grub as the bootloader"; + }; + }; + + config = { + boot.loader.grub.enable = true; + boot.loader.grub.device = "/dev/sda"; + boot.loader.grub.configurationLimit = 10; + }; +} diff --git a/modules/boot/refind.nix b/modules/boot/refind.nix new file mode 100644 index 0000000..c05f7d0 --- /dev/null +++ b/modules/boot/refind.nix @@ -0,0 +1,24 @@ +{ + inputs, + outputs, + lib, + config, + pkgs, + ... +}: let + inherit (lib) mkEnableOption mkIf mkOption types; + cfg = config.horseman.boot.refind; +in { + options = { + horseman.boot.refind = { + enable = mkEnableOption "Enables rEFInd, the boot manager"; + }; + }; + + config = { + environment.systemPackages = with pkgs; [ + refind + efibootmgr + ]; + }; +} diff --git a/modules/default.nix b/modules/default.nix index 6d47878..5a0eef5 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,10 +1,10 @@ -{inputs, ...}: { +{inputs, headless, ...}: { imports = [ ./apps ./hardware ./network ./terminal - ./wm + ( if !headless then ./wm else ./empty.nix ) ./users ./boot ./base diff --git a/modules/empty.nix b/modules/empty.nix new file mode 100644 index 0000000..258d1e8 --- /dev/null +++ b/modules/empty.nix @@ -0,0 +1,11 @@ +{ + inputs, + outputs, + lib, + config, + pkgs, + ... +}: let + inherit (lib) mkEnableOption mkIf mkOption types; +in { +} diff --git a/modules/terminal/zsh.nix b/modules/terminal/zsh.nix index 9080812..0ec0dfc 100644 --- a/modules/terminal/zsh.nix +++ b/modules/terminal/zsh.nix @@ -27,7 +27,7 @@ in { shellAliases = { clone-dotfiles = "cp -r /home/horseman/nix-config/config/dotfiles/.\* /home/horseman/"; - rebuild = "clone-dotfiles && sudo nixos-rebuild switch --flake"; + rebuild = "nix fmt && clone-dotfiles && sudo nixos-rebuild switch --flake"; update = "sudo nix flake update && rebuild"; compose = "sudo docker compose"; wolpc = "wakeonlan D8:5E:D3:A8:B1:0A"; diff --git a/modules/users/default.nix b/modules/users/default.nix index 0adcd76..9c49d99 100644 --- a/modules/users/default.nix +++ b/modules/users/default.nix @@ -1,5 +1,47 @@ -{inputs, ...}: { - imports = [ - ./horseman.nix - ]; +{ + inputs, + outputs, + lib, + config, + pkgs, + ... +}: let + inherit (lib) mkEnableOption mkIf mkOption types; + cfg = config.horseman.users.default; + homeCfg = config.horseman; +in { + options = { + horseman.users.default = { + enable = mkEnableOption "Default user"; + }; + }; + + config = { + home-manager = { + extraSpecialArgs = {inherit inputs outputs;}; + users.${homeCfg.username} = { + home = { + username = "${homeCfg.username}"; + homeDirectory = "/home/${homeCfg.username}"; + stateVersion = "24.11"; + }; + + programs = { + home-manager.enable = true; + }; + }; + }; + + users.users.horseman = { + initialPassword = "1234"; + isNormalUser = true; + openssh.authorizedKeys.keyFiles = [ + ../../config/ssh/authorized_keys + ]; + extraGroups = [ + "wheel" + "docker" + ]; + }; + }; } diff --git a/modules/users/horseman.nix b/modules/users/horseman.nix deleted file mode 100644 index 6d24b68..0000000 --- a/modules/users/horseman.nix +++ /dev/null @@ -1,46 +0,0 @@ -{ - inputs, - outputs, - lib, - config, - pkgs, - ... -}: let - inherit (lib) mkEnableOption mkIf mkOption types; - cfg = config.horseman.users.horseman; -in { - options = { - horseman.users.horseman = { - enable = mkEnableOption "Default user"; - }; - }; - - config = { - home-manager = { - extraSpecialArgs = {inherit inputs outputs;}; - users.horseman = { - home = { - username = "horseman"; - homeDirectory = "/home/horseman"; - stateVersion = "24.11"; - }; - - programs = { - home-manager.enable = true; - }; - }; - }; - - users.users.horseman = { - initialPassword = "1234"; - isNormalUser = true; - openssh.authorizedKeys.keyFiles = [ - ../../config/ssh/authorized_keys - ]; - extraGroups = [ - "wheel" - "docker" - ]; - }; - }; -}