Flake : Generalize host creation with mkHost.

This commit is contained in:
Dmitry Voronin 2024-02-13 17:30:28 +03:00
parent 3327cb5983
commit 236cd9dd18
13 changed files with 94 additions and 93 deletions

View file

@ -1,5 +1,25 @@
{ {
"nodes": { "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": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1707092692, "lastModified": 1707092692,
@ -18,6 +38,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"home-manager": "home-manager",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
} }

View file

@ -5,7 +5,14 @@
home-manager.inputs.nixpkgs.follows = "nixpkgs"; 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 = [ nixosModules.common.imports = [
./module/common/Bootloader.nix ./module/common/Bootloader.nix
./module/common/Distrobox.nix ./module/common/Distrobox.nix
@ -22,10 +29,27 @@
./module/common/Users.nix ./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 = [ modules = [
self.nixosModules.common
./host/dasha/Configuration.nix
./module/AmdGpu.nix ./module/AmdGpu.nix
./module/Flatpak.nix ./module/Flatpak.nix
./module/Gnome.nix ./module/Gnome.nix
@ -33,14 +57,12 @@
./module/Print.nix ./module/Print.nix
./user/Dasha.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 = [ modules = [
self.nixosModules.common
./host/desktop/Configuration.nix
./module/AmdGpu.nix ./module/AmdGpu.nix
./module/Flatpak.nix ./module/Flatpak.nix
./module/Gnome.nix ./module/Gnome.nix
@ -49,24 +71,20 @@
./module/VirtManager.nix ./module/VirtManager.nix
./user/Voronind.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 = [ modules = [
self.nixosModules.common
./host/fsight/Configuration.nix
./module/Docker.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 = [ modules = [
self.nixosModules.common
./host/home/Configuration.nix
./module/AmdGpu.nix ./module/AmdGpu.nix
./module/Docker.nix ./module/Docker.nix
./module/Flatpak.nix ./module/Flatpak.nix
@ -75,14 +93,12 @@
./module/PowersaveAmd.nix ./module/PowersaveAmd.nix
./user/Voronind.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 = [ modules = [
self.nixosModules.common
./host/laptop/Configuration.nix
./module/AmdGpu.nix ./module/AmdGpu.nix
./module/Flatpak.nix ./module/Flatpak.nix
./module/Gnome.nix ./module/Gnome.nix
@ -91,14 +107,12 @@
./user/Dasha.nix ./user/Dasha.nix
./user/Voronind.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 = [ modules = [
self.nixosModules.common
./host/work/Configuration.nix
./module/Flatpak.nix ./module/Flatpak.nix
./module/Gnome.nix ./module/Gnome.nix
./module/PowersaveIntel.nix ./module/PowersaveIntel.nix
@ -106,8 +120,6 @@
./module/Print.nix ./module/Print.nix
./user/Voronind.nix ./user/Voronind.nix
]; ];
specialArgs.inputs = inputs;
system = "x86_64-linux";
}; };
}; };
} }

View file

@ -1,14 +1,10 @@
{ config, pkgs, ... }: { ... }:
{ {
imports = [ imports = [
./HardwareConfiguration.nix
./Tablet.nix ./Tablet.nix
]; ];
# Network.
networking.hostName = "dasha";
# Filesystems. # Filesystems.
fileSystems."/storage/hot" = { fileSystems."/storage/hot" = {
device = "/dev/storage/hot"; device = "/dev/storage/hot";
@ -21,7 +17,4 @@
fsType = "ext4"; fsType = "ext4";
options = [ "nofail" ]; options = [ "nofail" ];
}; };
# Do not touch ever.
system.stateVersion = "23.11";
} }

View file

@ -2,12 +2,8 @@
{ {
imports = [ imports = [
./HardwareConfiguration.nix
]; ];
# Network.
networking.hostName = "desktop";
# Filesystems. # Filesystems.
fileSystems."/storage/hot" = { fileSystems."/storage/hot" = {
device = "/dev/storage/hot"; device = "/dev/storage/hot";
@ -26,7 +22,4 @@
fsType = "ext4"; fsType = "ext4";
options = [ "noauto" "nofail" ]; options = [ "noauto" "nofail" ];
}; };
# Do not touch ever.
system.stateVersion = "23.11";
} }

View file

@ -1,8 +1,7 @@
{ config, pkgs, lib, ... }: { lib, ... }:
{ {
imports = [ imports = [
./HardwareConfiguration.nix
]; ];
# Grub. # Grub.
@ -14,10 +13,4 @@
# Root password. # Root password.
users.users.root.hashedPassword = lib.mkForce "$y$j9T$d4HfwutZr.eNHuLJYRuro/$7swZfgCNS6jEXHFCxsW5um/68jX9BRiiZD1BYcm/gD/"; 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";
} }

View file

@ -2,21 +2,23 @@
{ {
imports = [ imports = [
./HardwareConfiguration.nix
./Backup.nix ./Backup.nix
./GnomeRdp.nix
./Nextcloud.nix ./Nextcloud.nix
./PhotosProcess.nix ./PhotosProcess.nix
./YandexMusic.nix ./YandexMusic.nix
]; ];
# Network. # Network.
networking.hostName = "home"; networking.networkmanager.insertNameservers = [
"1.1.1.1"
"8.8.8.8"
];
networking.extraHosts = '' networking.extraHosts = ''
10.1.0.2 git.voronind.com 10.1.0.2 git.voronind.com
10.1.0.2 iot.voronind.com 10.1.0.2 iot.voronind.com
10.1.0.2 pass.voronind.com 10.1.0.2 pass.voronind.com
''; '';
networking.networkmanager.insertNameservers = [ "1.1.1.1" "8.8.8.8" ];
# Filesystems. # Filesystems.
fileSystems."/storage/cold_1" = { fileSystems."/storage/cold_1" = {
@ -43,13 +45,4 @@
# Disable ftpd autostart. # Disable ftpd autostart.
systemd.services.vsftpd.wantedBy = lib.mkForce [ ]; 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";
} }

View file

@ -0,0 +1,8 @@
{ pkgs, ... }:
{
environment.systemPackages = with pkgs; [
openssl
gnome.gnome-remote-desktop
];
}

View file

@ -2,20 +2,13 @@
{ {
imports = [ imports = [
./HardwareConfiguration.nix
# ./MsiKeyboard.nix # ./MsiKeyboard.nix
]; ];
# Network.
networking.hostName = "laptop";
# Filesystems. # Filesystems.
fileSystems."/storage/hot" = { fileSystems."/storage/hot" = {
device = "/dev/storage/hot"; device = "/dev/storage/hot";
fsType = "ext4"; fsType = "ext4";
options = [ "nofail" ]; options = [ "nofail" ];
}; };
# Do not touch ever.
system.stateVersion = "23.11";
} }

View file

@ -2,13 +2,6 @@
{ {
imports = [ imports = [
./HardwareConfiguration.nix
./Fprint.nix ./Fprint.nix
]; ];
# Network.
networking.hostName = "work";
# Do not touch ever.
system.stateVersion = "23.11";
} }

View file

@ -1,8 +0,0 @@
{ ... }:
{
home-manager.nixosModules.home-manager = {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
};
}

View file

@ -0,0 +1,9 @@
{ inputs, ... }:
{
imports = [
inputs.home-manager.nixosModules.home-manager
];
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
}

View file

@ -1,6 +1,5 @@
{ ... }: { specialArgs, ... }:
{ {
# TODO: Set in one place with Voronind. users.users.root.hashedPassword = specialArgs.const.hashedPassword;
users.users.root.hashedPassword = "$y$j9T$oqCB16i5E2t1t/HAWaFd5.$tTaHtAcifXaDVpTcRv.yH2/eWKxKE9xM8KcqXHfHrD7"; # Use `mkpasswd`.
} }

View file

@ -1,8 +1,8 @@
{ pkgs, ... }: { pkgs, specialArgs, ... }:
{ {
users.users.voronind = { users.users.voronind = {
hashedPassword = "$y$j9T$oqCB16i5E2t1t/HAWaFd5.$tTaHtAcifXaDVpTcRv.yH2/eWKxKE9xM8KcqXHfHrD7"; hashedPassword = specialArgs.const.hashedPassword;
uid = 1000; uid = 1000;
createHome = true; createHome = true;
isNormalUser = true; isNormalUser = true;
@ -13,5 +13,7 @@
home-manager.users.voronind = { home-manager.users.voronind = {
programs.firefox.enable = true; programs.firefox.enable = true;
home.stateVersion = "23.11";
}; };
} }