feat: auto import modules and simplify configs

This commit is contained in:
2026-03-07 15:59:07 +01:00
parent f9706b2958
commit 78dd75ec88
7 changed files with 40 additions and 84 deletions

View File

@@ -71,17 +71,16 @@
nixosConfigurations = { nixosConfigurations = {
matej-nixos = mkHost "matej-nixos" { matej-nixos = mkHost "matej-nixos" {
system = "x86_64-linux"; system = "x86_64-linux";
users = [ "matej" ]; user = "matej";
}; };
matej-tower = mkHost "matej-tower" { matej-tower = mkHost "matej-tower" {
system = "x86_64-linux"; system = "x86_64-linux";
users = [ "matej" ]; user = "matej";
}; };
# nixos-rebuild build-image --image-variant install-iso --flake .#live-iso # nixos-rebuild build-image --image-variant install-iso --flake .#live-iso
live-iso = mkHost "live-iso" { live-iso = mkHost "live-iso" {
system = "x86_64-linux"; system = "x86_64-linux";
users = [ ];
}; };
}; };

View File

@@ -2,16 +2,10 @@
pkgs, pkgs,
lib, lib,
inputs, inputs,
userKeys,
... ...
}: }:
let
keys = import ../../users/matej/keys.nix;
in
{ {
imports = [
inputs.self.nixosModules.openssh
];
openssh.enable = true; openssh.enable = true;
image.modules.iso-installer = { image.modules.iso-installer = {
@@ -41,7 +35,7 @@ in
"wheel" "wheel"
"users" "users"
]; ];
openssh.authorizedKeys.keys = keys.sshAuthorizedKeys; openssh.authorizedKeys.keys = userKeys.sshAuthorizedKeys or [ ];
}; };
}; };

View File

@@ -4,6 +4,7 @@
pkgs, pkgs,
inputs, inputs,
options, options,
userKeys,
... ...
}: }:
@@ -15,31 +16,14 @@ in
imports = [ imports = [
inputs.nixos-hardware.nixosModules.framework-16-amd-ai-300-series inputs.nixos-hardware.nixosModules.framework-16-amd-ai-300-series
inputs.stylix.nixosModules.stylix inputs.stylix.nixosModules.stylix
inputs.self.nixosModules.yubikey
inputs.self.nixosModules.sway
inputs.self.nixosModules.openssh
inputs.self.nixosModules.desktop
inputs.self.nixosModules.printing
inputs.self.nixosModules.zsh
inputs.self.nixosModules.gnupg
inputs.self.nixosModules.tuigreet
inputs.self.nixosModules.workstation
inputs.self.nixosModules.localisation
]; ];
yubikey.enable = true; profiles.desktop.enable = true;
openssh.enable = true;
desktop.enable = true;
printing.enable = true;
zsh.enable = true;
gnupg.enable = true;
workstation.enable = true;
tuigreet = {
enable = true;
command = "sway";
};
sway.enable = true; localisation = {
timeZone = "Europe/Ljubljana";
defaultLocale = "en_US.UTF-8";
};
stylix = { stylix = {
enable = true; enable = true;
@@ -51,12 +35,6 @@ in
boot.loader.systemd-boot.enable = true; boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true; boot.loader.efi.canTouchEfiVariables = true;
localisation = {
enable = true;
timeZone = "Europe/Ljubljana";
defaultLocale = "en_US.UTF-8";
};
# WARN:(@janezicmatej) nix-ld for running pip-installed binaries outside nix, probably want to drop this # WARN:(@janezicmatej) nix-ld for running pip-installed binaries outside nix, probably want to drop this
programs.nix-ld.enable = true; programs.nix-ld.enable = true;
programs.nix-ld.libraries = options.programs.nix-ld.libraries.default; programs.nix-ld.libraries = options.programs.nix-ld.libraries.default;

View File

@@ -4,44 +4,27 @@
pkgs, pkgs,
inputs, inputs,
options, options,
userKeys,
... ...
}: }:
{ {
networking.hostName = "matej-tower";
imports = [ imports = [
inputs.stylix.nixosModules.stylix inputs.stylix.nixosModules.stylix
inputs.lanzaboote.nixosModules.lanzaboote inputs.lanzaboote.nixosModules.lanzaboote
inputs.self.nixosModules.yubikey
inputs.self.nixosModules.sway
inputs.self.nixosModules.openssh
inputs.self.nixosModules.desktop
inputs.self.nixosModules.printing
inputs.self.nixosModules.zsh
inputs.self.nixosModules.gnupg
inputs.self.nixosModules.tuigreet
inputs.self.nixosModules.workstation
inputs.self.nixosModules.initrd-ssh
inputs.self.nixosModules.localisation
]; ];
yubikey.enable = true; profiles.desktop.enable = true;
openssh.enable = true;
desktop.enable = true;
printing.enable = true;
zsh.enable = true;
gnupg.enable = true;
workstation.enable = true;
tuigreet = {
enable = true;
command = "sway";
};
sway.enable = true;
initrd-ssh = { initrd-ssh = {
enable = true; enable = true;
networkModule = "r8169"; networkModule = "r8169";
authorizedKeys = userKeys.sshAuthorizedKeys;
};
localisation = {
timeZone = "Europe/Ljubljana";
defaultLocale = "en_US.UTF-8";
}; };
stylix = { stylix = {
@@ -60,12 +43,6 @@
pkiBundle = "/var/lib/sbctl"; pkiBundle = "/var/lib/sbctl";
}; };
localisation = {
enable = true;
timeZone = "Europe/Ljubljana";
defaultLocale = "en_US.UTF-8";
};
services.udisks2.enable = true; services.udisks2.enable = true;
programs._1password.enable = true; programs._1password.enable = true;
@@ -83,6 +60,8 @@
easyeffects easyeffects
]; ];
networking.hostName = "matej-tower";
xdg.mime.defaultApplications = { xdg.mime.defaultApplications = {
"application/pdf" = "org.pwmt.zathura.desktop"; "application/pdf" = "org.pwmt.zathura.desktop";
}; };

View File

@@ -7,19 +7,23 @@
name: name:
{ {
system, system,
users ? [ ], user ? null,
}: }:
let let
hostConfig = ../hosts/${name}/configuration.nix; hostConfig = ../hosts/${name}/configuration.nix;
hostHWConfig = ../hosts/${name}/hardware-configuration.nix; hostHWConfig = ../hosts/${name}/hardware-configuration.nix;
hasHWConfig = builtins.pathExists hostHWConfig; hasHWConfig = builtins.pathExists hostHWConfig;
hasUser = user != null;
userNixosConfigs = map (user: ../users/${user}/nixos.nix) ( userKeys = if hasUser then import ../users/${user}/keys.nix else { };
builtins.filter (user: builtins.pathExists ../users/${user}/nixos.nix) users
);
userHMConfigs = nixpkgs.lib.genAttrs users (user: import ../users/${user}/home-manager.nix); # auto-import all nixos modules and profiles
nixosModuleList = builtins.attrValues inputs.self.nixosModules;
nixosProfileList = builtins.attrValues inputs.self.nixosProfiles;
# auto-import all home-manager modules
hmModuleList = builtins.attrValues inputs.self.homeManagerModules;
in in
nixpkgs.lib.nixosSystem { nixpkgs.lib.nixosSystem {
@@ -33,16 +37,23 @@ nixpkgs.lib.nixosSystem {
hostConfig hostConfig
] ]
++ nixpkgs.lib.optional hasHWConfig hostHWConfig ++ nixpkgs.lib.optional hasHWConfig hostHWConfig
++ userNixosConfigs ++ nixosModuleList
++ nixosProfileList
++ nixpkgs.lib.optional (
hasUser && builtins.pathExists ../users/${user}/nixos.nix
) ../users/${user}/nixos.nix
++ [ ++ [
inputs.home-manager.nixosModules.home-manager inputs.home-manager.nixosModules.home-manager
{ {
home-manager.useGlobalPkgs = true; home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true; home-manager.useUserPackages = true;
home-manager.backupFileExtension = "backup"; home-manager.backupFileExtension = "backup";
home-manager.users = userHMConfigs; home-manager.users = nixpkgs.lib.mkIf hasUser {
${user} = import ../users/${user}/home-manager.nix;
};
home-manager.sharedModules = hmModuleList;
home-manager.extraSpecialArgs = { inherit inputs; }; home-manager.extraSpecialArgs = { inherit inputs; };
} }
]; ];
specialArgs = { inherit inputs; }; specialArgs = { inherit inputs userKeys; };
} }

View File

@@ -4,9 +4,6 @@
... ...
}: }:
let let
# TODO:(@janezicmatej) restructure keys import
keys = import ../../users/matej/keys.nix;
# generate host keys for new machines: ./scripts/initrd-ssh-keygen.sh # generate host keys for new machines: ./scripts/initrd-ssh-keygen.sh
keyDir = "/etc/secrets/initrd"; keyDir = "/etc/secrets/initrd";
@@ -51,7 +48,7 @@ in
authorizedKeys = lib.mkOption { authorizedKeys = lib.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
default = keys.sshAuthorizedKeys; default = [ ];
}; };
networkModule = lib.mkOption { networkModule = lib.mkOption {

View File

@@ -8,11 +8,9 @@
let let
packages = inputs.self.outputs.packages.${pkgs.stdenv.hostPlatform.system}; packages = inputs.self.outputs.packages.${pkgs.stdenv.hostPlatform.system};
hmModules = inputs.self.outputs.homeManagerModules;
in in
{ {
imports = [ hmModules.claude ];
claude = { claude = {
enable = true; enable = true;
package = inputs.claude-code-overlay.packages.${pkgs.stdenv.hostPlatform.system}.default; package = inputs.claude-code-overlay.packages.${pkgs.stdenv.hostPlatform.system}.default;