From 236cd9dd1865d8ec1c869d4db91db57860d68428 Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Tue, 13 Feb 2024 17:30:28 +0300 Subject: [PATCH] Flake : Generalize host creation with mkHost. --- .config/linux/system/flake.lock | 21 ++++++ .config/linux/system/flake.nix | 74 +++++++++++-------- .../linux/system/host/dasha/Configuration.nix | 9 +-- .../system/host/desktop/Configuration.nix | 7 -- .../system/host/fsight/Configuration.nix | 9 +-- .../linux/system/host/home/Configuration.nix | 17 ++--- .config/linux/system/host/home/GnomeRdp.nix | 8 ++ .../system/host/laptop/Configuration.nix | 7 -- .../linux/system/host/work/Configuration.nix | 7 -- .config/linux/system/module/HomeManager.nix | 8 -- .../system/module/common/HomeManager.nix | 9 +++ .config/linux/system/module/common/Root.nix | 5 +- .config/linux/system/user/Voronind.nix | 6 +- 13 files changed, 94 insertions(+), 93 deletions(-) create mode 100644 .config/linux/system/host/home/GnomeRdp.nix delete mode 100644 .config/linux/system/module/HomeManager.nix create mode 100644 .config/linux/system/module/common/HomeManager.nix diff --git a/.config/linux/system/flake.lock b/.config/linux/system/flake.lock index 581619f..94d62ad 100644 --- a/.config/linux/system/flake.lock +++ b/.config/linux/system/flake.lock @@ -1,5 +1,25 @@ { "nodes": { + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1707683400, + "narHash": "sha256-Zc+J3UO1Xpx+NL8UB6woPHyttEy9cXXtm+0uWwzuYDc=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "21b078306a2ab68748abf72650db313d646cf2ca", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1707092692, @@ -18,6 +38,7 @@ }, "root": { "inputs": { + "home-manager": "home-manager", "nixpkgs": "nixpkgs" } } diff --git a/.config/linux/system/flake.nix b/.config/linux/system/flake.nix index 3a88285..bf8e3f9 100644 --- a/.config/linux/system/flake.nix +++ b/.config/linux/system/flake.nix @@ -5,7 +5,14 @@ home-manager.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs } @inputs: { + outputs = { self, nixpkgs, home-manager } @inputs: { + # Constant values. + nixosModules.const = { + hashedPassword = "$y$j9T$oqCB16i5E2t1t/HAWaFd5.$tTaHtAcifXaDVpTcRv.yH2/eWKxKE9xM8KcqXHfHrD7"; # Use `mkpasswd`. + stateVersion = "23.11"; + }; + + # Common modules used across all hosts. nixosModules.common.imports = [ ./module/common/Bootloader.nix ./module/common/Distrobox.nix @@ -22,10 +29,27 @@ ./module/common/Users.nix ]; - nixosConfigurations.dasha = nixpkgs.lib.nixosSystem { + # Function to create a host. + mkHost = { system, hostname, modules }: nixpkgs.lib.nixosSystem { + inherit system; + + modules = [ + ./host/${hostname}/Configuration.nix + ./host/${hostname}/HardwareConfiguration.nix + { networking.hostName = hostname; } + { system.stateVersion = inputs.self.nixosModules.const.stateVersion; } + inputs.self.nixosModules.common + ] ++ modules; + + specialArgs.inputs = inputs; + specialArgs.const = self.nixosModules.const; + }; + + # List of all hosts bellow. + nixosConfigurations.dasha = self.mkHost { + hostname = "dasha"; + system = "x86_64-linux"; modules = [ - self.nixosModules.common - ./host/dasha/Configuration.nix ./module/AmdGpu.nix ./module/Flatpak.nix ./module/Gnome.nix @@ -33,14 +57,12 @@ ./module/Print.nix ./user/Dasha.nix ]; - specialArgs.inputs = inputs; - system = "x86_64-linux"; }; - nixosConfigurations.desktop = nixpkgs.lib.nixosSystem { + nixosConfigurations.desktop = self.mkHost { + hostname = "desktop"; + system = "x86_64-linux"; modules = [ - self.nixosModules.common - ./host/desktop/Configuration.nix ./module/AmdGpu.nix ./module/Flatpak.nix ./module/Gnome.nix @@ -49,24 +71,20 @@ ./module/VirtManager.nix ./user/Voronind.nix ]; - specialArgs.inputs = inputs; - system = "x86_64-linux"; }; - nixosConfigurations.fsight = nixpkgs.lib.nixosSystem { + nixosConfigurations.fsight = self.mkHost { + hostname = "fsight"; + system = "x86_64-linux"; modules = [ - self.nixosModules.common - ./host/fsight/Configuration.nix ./module/Docker.nix ]; - specialArgs.inputs = inputs; - system = "x86_64-linux"; }; - nixosConfigurations.home = nixpkgs.lib.nixosSystem { + nixosConfigurations.home = self.mkHost { + hostname = "home"; + system = "x86_64-linux"; modules = [ - self.nixosModules.common - ./host/home/Configuration.nix ./module/AmdGpu.nix ./module/Docker.nix ./module/Flatpak.nix @@ -75,14 +93,12 @@ ./module/PowersaveAmd.nix ./user/Voronind.nix ]; - specialArgs.inputs = inputs; - system = "x86_64-linux"; }; - nixosConfigurations.laptop = nixpkgs.lib.nixosSystem { + nixosConfigurations.laptop = self.mkHost { + hostname = "laptop"; + system = "x86_64-linux"; modules = [ - self.nixosModules.common - ./host/laptop/Configuration.nix ./module/AmdGpu.nix ./module/Flatpak.nix ./module/Gnome.nix @@ -91,14 +107,12 @@ ./user/Dasha.nix ./user/Voronind.nix ]; - specialArgs.inputs = inputs; - system = "x86_64-linux"; }; - nixosConfigurations.work = nixpkgs.lib.nixosSystem { + nixosConfigurations.work = self.mkHost { + hostname = "work"; + system = "x86_64-linux"; modules = [ - self.nixosModules.common - ./host/work/Configuration.nix ./module/Flatpak.nix ./module/Gnome.nix ./module/PowersaveIntel.nix @@ -106,8 +120,6 @@ ./module/Print.nix ./user/Voronind.nix ]; - specialArgs.inputs = inputs; - system = "x86_64-linux"; }; }; } diff --git a/.config/linux/system/host/dasha/Configuration.nix b/.config/linux/system/host/dasha/Configuration.nix index fa2b6d8..4afe50a 100644 --- a/.config/linux/system/host/dasha/Configuration.nix +++ b/.config/linux/system/host/dasha/Configuration.nix @@ -1,14 +1,10 @@ -{ config, pkgs, ... }: +{ ... }: { imports = [ - ./HardwareConfiguration.nix ./Tablet.nix ]; - # Network. - networking.hostName = "dasha"; - # Filesystems. fileSystems."/storage/hot" = { device = "/dev/storage/hot"; @@ -21,7 +17,4 @@ fsType = "ext4"; options = [ "nofail" ]; }; - - # Do not touch ever. - system.stateVersion = "23.11"; } diff --git a/.config/linux/system/host/desktop/Configuration.nix b/.config/linux/system/host/desktop/Configuration.nix index e80cb9f..1e67552 100644 --- a/.config/linux/system/host/desktop/Configuration.nix +++ b/.config/linux/system/host/desktop/Configuration.nix @@ -2,12 +2,8 @@ { imports = [ - ./HardwareConfiguration.nix ]; - # Network. - networking.hostName = "desktop"; - # Filesystems. fileSystems."/storage/hot" = { device = "/dev/storage/hot"; @@ -26,7 +22,4 @@ fsType = "ext4"; options = [ "noauto" "nofail" ]; }; - - # Do not touch ever. - system.stateVersion = "23.11"; } diff --git a/.config/linux/system/host/fsight/Configuration.nix b/.config/linux/system/host/fsight/Configuration.nix index f6be877..145a246 100644 --- a/.config/linux/system/host/fsight/Configuration.nix +++ b/.config/linux/system/host/fsight/Configuration.nix @@ -1,8 +1,7 @@ -{ config, pkgs, lib, ... }: +{ lib, ... }: { imports = [ - ./HardwareConfiguration.nix ]; # Grub. @@ -14,10 +13,4 @@ # Root password. users.users.root.hashedPassword = lib.mkForce "$y$j9T$d4HfwutZr.eNHuLJYRuro/$7swZfgCNS6jEXHFCxsW5um/68jX9BRiiZD1BYcm/gD/"; - - # Network. - networking.hostName = "fsight"; - - # Do not touch ever. - system.stateVersion = "23.11"; } diff --git a/.config/linux/system/host/home/Configuration.nix b/.config/linux/system/host/home/Configuration.nix index ff76b00..b2e8c6c 100644 --- a/.config/linux/system/host/home/Configuration.nix +++ b/.config/linux/system/host/home/Configuration.nix @@ -2,21 +2,23 @@ { imports = [ - ./HardwareConfiguration.nix ./Backup.nix + ./GnomeRdp.nix ./Nextcloud.nix ./PhotosProcess.nix ./YandexMusic.nix ]; # Network. - networking.hostName = "home"; + networking.networkmanager.insertNameservers = [ + "1.1.1.1" + "8.8.8.8" + ]; networking.extraHosts = '' 10.1.0.2 git.voronind.com 10.1.0.2 iot.voronind.com 10.1.0.2 pass.voronind.com ''; - networking.networkmanager.insertNameservers = [ "1.1.1.1" "8.8.8.8" ]; # Filesystems. fileSystems."/storage/cold_1" = { @@ -43,13 +45,4 @@ # Disable ftpd autostart. systemd.services.vsftpd.wantedBy = lib.mkForce [ ]; - - # Gnome RDP. - environment.systemPackages = with pkgs; [ - openssl - gnome.gnome-remote-desktop - ]; - - # Do not touch ever. - system.stateVersion = "23.11"; } diff --git a/.config/linux/system/host/home/GnomeRdp.nix b/.config/linux/system/host/home/GnomeRdp.nix new file mode 100644 index 0000000..0698296 --- /dev/null +++ b/.config/linux/system/host/home/GnomeRdp.nix @@ -0,0 +1,8 @@ +{ pkgs, ... }: + +{ + environment.systemPackages = with pkgs; [ + openssl + gnome.gnome-remote-desktop + ]; +} diff --git a/.config/linux/system/host/laptop/Configuration.nix b/.config/linux/system/host/laptop/Configuration.nix index af35ef0..dccc3ab 100644 --- a/.config/linux/system/host/laptop/Configuration.nix +++ b/.config/linux/system/host/laptop/Configuration.nix @@ -2,20 +2,13 @@ { imports = [ - ./HardwareConfiguration.nix # ./MsiKeyboard.nix ]; - # Network. - networking.hostName = "laptop"; - # Filesystems. fileSystems."/storage/hot" = { device = "/dev/storage/hot"; fsType = "ext4"; options = [ "nofail" ]; }; - - # Do not touch ever. - system.stateVersion = "23.11"; } diff --git a/.config/linux/system/host/work/Configuration.nix b/.config/linux/system/host/work/Configuration.nix index d7f5a28..ad53a86 100644 --- a/.config/linux/system/host/work/Configuration.nix +++ b/.config/linux/system/host/work/Configuration.nix @@ -2,13 +2,6 @@ { imports = [ - ./HardwareConfiguration.nix ./Fprint.nix ]; - - # Network. - networking.hostName = "work"; - - # Do not touch ever. - system.stateVersion = "23.11"; } diff --git a/.config/linux/system/module/HomeManager.nix b/.config/linux/system/module/HomeManager.nix deleted file mode 100644 index fd6dfa6..0000000 --- a/.config/linux/system/module/HomeManager.nix +++ /dev/null @@ -1,8 +0,0 @@ -{ ... }: - -{ - home-manager.nixosModules.home-manager = { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - }; -} diff --git a/.config/linux/system/module/common/HomeManager.nix b/.config/linux/system/module/common/HomeManager.nix new file mode 100644 index 0000000..24c970c --- /dev/null +++ b/.config/linux/system/module/common/HomeManager.nix @@ -0,0 +1,9 @@ +{ inputs, ... }: + +{ + imports = [ + inputs.home-manager.nixosModules.home-manager + ]; + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; +} diff --git a/.config/linux/system/module/common/Root.nix b/.config/linux/system/module/common/Root.nix index cfda446..82337cb 100644 --- a/.config/linux/system/module/common/Root.nix +++ b/.config/linux/system/module/common/Root.nix @@ -1,6 +1,5 @@ -{ ... }: +{ specialArgs, ... }: { - # TODO: Set in one place with Voronind. - users.users.root.hashedPassword = "$y$j9T$oqCB16i5E2t1t/HAWaFd5.$tTaHtAcifXaDVpTcRv.yH2/eWKxKE9xM8KcqXHfHrD7"; # Use `mkpasswd`. + users.users.root.hashedPassword = specialArgs.const.hashedPassword; } diff --git a/.config/linux/system/user/Voronind.nix b/.config/linux/system/user/Voronind.nix index 547b7c1..b741771 100644 --- a/.config/linux/system/user/Voronind.nix +++ b/.config/linux/system/user/Voronind.nix @@ -1,8 +1,8 @@ -{ pkgs, ... }: +{ pkgs, specialArgs, ... }: { users.users.voronind = { - hashedPassword = "$y$j9T$oqCB16i5E2t1t/HAWaFd5.$tTaHtAcifXaDVpTcRv.yH2/eWKxKE9xM8KcqXHfHrD7"; + hashedPassword = specialArgs.const.hashedPassword; uid = 1000; createHome = true; isNormalUser = true; @@ -13,5 +13,7 @@ home-manager.users.voronind = { programs.firefox.enable = true; + + home.stateVersion = "23.11"; }; }