refactor: dynamic imports

This commit is contained in:
Leon Schwarzäugl 2025-01-07 17:54:46 +01:00
parent 0da982831f
commit 0f8051cf4a
Signed by: swarsel
GPG key ID: 26A54C31F2A4FD84
6 changed files with 36 additions and 216 deletions

View file

@ -4444,6 +4444,8 @@ A breakdown of each function:
}) })
names); names);
mkImports = names: baseDir: lib.map (name: "${self}/${baseDir}/${name}") names;
eachMonitor = _: monitor: { eachMonitor = _: monitor: {
inherit (monitor) name; inherit (monitor) name;
value = builtins.removeAttrs monitor [ "workspace" "name" "output" ]; value = builtins.removeAttrs monitor [ "workspace" "name" "output" ];
@ -4478,49 +4480,12 @@ These are system-level settings specific to NixOS machines. All settings that ar
This section is for setting things that should be used on hosts that are using the default NixOS configuration. This means that servers should NOT import this, as much of these imported modules are user-configured. This section is for setting things that should be used on hosts that are using the default NixOS configuration. This means that servers should NOT import this, as much of these imported modules are user-configured.
#+begin_src nix :tangle profiles/nixos/common/default.nix #+begin_src nix :tangle profiles/nixos/common/default.nix
_: { lib, ... }:
let
importNames = lib.swarselsystems.readNix "profiles/nixos/common";
in
{ {
imports = [ imports = lib.swarselsystems.mkImports importNames "profiles/nixos/common";
./settings.nix
./home-manager.nix
./xserver.nix
./users.nix
./env.nix
./stylix.nix
./polkit.nix
./gc.nix
./store.nix
./systemd.nix
./network.nix
./time.nix
./hardware.nix
./pipewire.nix
./sops.nix
./packages.nix
./programs.nix
./zsh.nix
./syncthing.nix
./blueman.nix
./networkdevices.nix
./gvfs.nix
./interceptiontools.nix
./hardwarecompatibility.nix
./login.nix
./stylix.nix
./power-profiles-daemon.nix
# ./impermanence.nix
./nvd-rebuild.nix
./nix-ld.nix
./gnome-keyring.nix
./sway.nix
./xdg-portal.nix
# ./yubikey-touch-detector.nix
# ./safeeyes.nix
./distrobox.nix
./lid.nix
./lowbattery.nix
./lanzaboote.nix
];
nixpkgs.config.permittedInsecurePackages = [ nixpkgs.config.permittedInsecurePackages = [
"jitsi-meet-1.0.8043" "jitsi-meet-1.0.8043"
@ -6159,12 +6124,13 @@ Also, we disable the warnings that trigger when rebuilding with a dirty flake. A
Also, the system state version is set here. No need to touch it. Also, the system state version is set here. No need to touch it.
#+begin_src nix :tangle profiles/nixos/server/default.nix #+begin_src nix :tangle profiles/nixos/server/default.nix
{ self, ... }: { self, lib, ... }:
let let
importNames = lib.swarselsystems.readNix "profiles/nixos/server";
profilesPath = "${self}/profiles"; profilesPath = "${self}/profiles";
in in
{ {
imports = [ imports = lib.swarselsystems.mkImports importNames "profiles/nixos/server" ++ [
"${profilesPath}/nixos/common/settings.nix" "${profilesPath}/nixos/common/settings.nix"
"${profilesPath}/nixos/common/home-manager.nix" "${profilesPath}/nixos/common/home-manager.nix"
"${profilesPath}/nixos/common/xserver.nix" "${profilesPath}/nixos/common/xserver.nix"
@ -6173,31 +6139,6 @@ Also, the system state version is set here. No need to touch it.
"${profilesPath}/nixos/common/time.nix" "${profilesPath}/nixos/common/time.nix"
"${profilesPath}/nixos/common/users.nix" "${profilesPath}/nixos/common/users.nix"
"${profilesPath}/nixos/common/nix-ld.nix" "${profilesPath}/nixos/common/nix-ld.nix"
./settings.nix
./packages.nix
./sops.nix
./ssh.nix
./nfs.nix
./nginx.nix
./kavita.nix
./jellyfin.nix
./navidrome.nix
./spotifyd.nix
./mpd.nix
./matrix.nix
./pipewire.nix
./nextcloud.nix
./immich.nix
./paperless.nix
./transmission.nix
./syncthing.nix
./restic.nix
./monitoring.nix
./jenkins.nix
./emacs.nix
./forgejo.nix
./ankisync.nix
./freshrss.nix
]; ];
} }
#+end_src #+end_src
@ -8308,43 +8249,12 @@ The general structure is the same as in the [[#h:6da812f5-358c-49cb-aff2-0a94f20
This section sets up all the imports that are used in the home-manager section. This section sets up all the imports that are used in the home-manager section.
#+begin_src nix :tangle profiles/home/common/default.nix #+begin_src nix :tangle profiles/home/common/default.nix
_: { lib, ... }:
let
importNames = lib.swarselsystems.readNix "profiles/home/common";
in
{ {
imports = [ imports = lib.swarselsystems.mkImports importNames "profiles/home/common";
./settings.nix
./packages.nix
./custom-packages.nix
./sops.nix
./ssh.nix
./stylix.nix
./desktop.nix
./symlink.nix
./env.nix
./programs.nix
./nix-index.nix
./password-store.nix
./direnv.nix
./eza.nix
./git.nix
./fuzzel.nix
./starship.nix
./kitty.nix
./zsh.nix
./mail.nix
./emacs.nix
./waybar.nix
./firefox.nix
./gnome-keyring.nix
./kdeconnect.nix
./mako.nix
./sway.nix
./gpg-agent.nix
./gammastep.nix
# ./safeeyes.nix
./yubikey-touch-detector.nix
./zellij.nix
./tmux.nix
];
} }
#+end_src #+end_src
@ -10975,14 +10885,14 @@ This service changes the screen hue at night. I am not sure if that really does
This section sets up all the imports that are used in the home-manager section. This section sets up all the imports that are used in the home-manager section.
#+begin_src nix :tangle profiles/home/server/default.nix #+begin_src nix :tangle profiles/home/server/default.nix
{ self, ... }: { self, lib, ... }:
let let
importNames = lib.swarselsystems.readNix "profiles/home/server";
profilesPath = "${self}/profiles"; profilesPath = "${self}/profiles";
in in
{ {
imports = [ imports = lib.swarselsystems.mkImports importNames "profiles/home/server" ++ [
"${profilesPath}/home/common/settings.nix" "${profilesPath}/home/common/settings.nix"
./symlink.nix
]; ];
} }
#+end_src #+end_src

View file

@ -89,6 +89,8 @@
}) })
names); names);
mkImports = names: baseDir: lib.map (name: "${self}/${baseDir}/${name}") names;
eachMonitor = _: monitor: { eachMonitor = _: monitor: {
inherit (monitor) name; inherit (monitor) name;
value = builtins.removeAttrs monitor [ "workspace" "name" "output" ]; value = builtins.removeAttrs monitor [ "workspace" "name" "output" ];

View file

@ -1,38 +1,7 @@
_: { lib, ... }:
let
importNames = lib.swarselsystems.readNix "profiles/home/common";
in
{ {
imports = [ imports = lib.swarselsystems.mkImports importNames "profiles/home/common";
./settings.nix
./packages.nix
./custom-packages.nix
./sops.nix
./ssh.nix
./stylix.nix
./desktop.nix
./symlink.nix
./env.nix
./programs.nix
./nix-index.nix
./password-store.nix
./direnv.nix
./eza.nix
./git.nix
./fuzzel.nix
./starship.nix
./kitty.nix
./zsh.nix
./mail.nix
./emacs.nix
./waybar.nix
./firefox.nix
./gnome-keyring.nix
./kdeconnect.nix
./mako.nix
./sway.nix
./gpg-agent.nix
./gammastep.nix
# ./safeeyes.nix
./yubikey-touch-detector.nix
./zellij.nix
./tmux.nix
];
} }

View file

@ -1,10 +1,10 @@
{ self, ... }: { self, lib, ... }:
let let
importNames = lib.swarselsystems.readNix "profiles/home/server";
profilesPath = "${self}/profiles"; profilesPath = "${self}/profiles";
in in
{ {
imports = [ imports = lib.swarselsystems.mkImports importNames "profiles/home/server" ++ [
"${profilesPath}/home/common/settings.nix" "${profilesPath}/home/common/settings.nix"
./symlink.nix
]; ];
} }

View file

@ -1,46 +1,9 @@
_: { lib, ... }:
let
importNames = lib.swarselsystems.readNix "profiles/nixos/common";
in
{ {
imports = [ imports = lib.swarselsystems.mkImports importNames "profiles/nixos/common";
./settings.nix
./home-manager.nix
./xserver.nix
./users.nix
./env.nix
./stylix.nix
./polkit.nix
./gc.nix
./store.nix
./systemd.nix
./network.nix
./time.nix
./hardware.nix
./pipewire.nix
./sops.nix
./packages.nix
./programs.nix
./zsh.nix
./syncthing.nix
./blueman.nix
./networkdevices.nix
./gvfs.nix
./interceptiontools.nix
./hardwarecompatibility.nix
./login.nix
./stylix.nix
./power-profiles-daemon.nix
# ./impermanence.nix
./nvd-rebuild.nix
./nix-ld.nix
./gnome-keyring.nix
./sway.nix
./xdg-portal.nix
# ./yubikey-touch-detector.nix
# ./safeeyes.nix
./distrobox.nix
./lid.nix
./lowbattery.nix
./lanzaboote.nix
];
nixpkgs.config.permittedInsecurePackages = [ nixpkgs.config.permittedInsecurePackages = [
"jitsi-meet-1.0.8043" "jitsi-meet-1.0.8043"

View file

@ -1,9 +1,10 @@
{ self, ... }: { self, lib, ... }:
let let
importNames = lib.swarselsystems.readNix "profiles/nixos/server";
profilesPath = "${self}/profiles"; profilesPath = "${self}/profiles";
in in
{ {
imports = [ imports = lib.swarselsystems.mkImports importNames "profiles/nixos/server" ++ [
"${profilesPath}/nixos/common/settings.nix" "${profilesPath}/nixos/common/settings.nix"
"${profilesPath}/nixos/common/home-manager.nix" "${profilesPath}/nixos/common/home-manager.nix"
"${profilesPath}/nixos/common/xserver.nix" "${profilesPath}/nixos/common/xserver.nix"
@ -12,30 +13,5 @@ in
"${profilesPath}/nixos/common/time.nix" "${profilesPath}/nixos/common/time.nix"
"${profilesPath}/nixos/common/users.nix" "${profilesPath}/nixos/common/users.nix"
"${profilesPath}/nixos/common/nix-ld.nix" "${profilesPath}/nixos/common/nix-ld.nix"
./settings.nix
./packages.nix
./sops.nix
./ssh.nix
./nfs.nix
./nginx.nix
./kavita.nix
./jellyfin.nix
./navidrome.nix
./spotifyd.nix
./mpd.nix
./matrix.nix
./pipewire.nix
./nextcloud.nix
./immich.nix
./paperless.nix
./transmission.nix
./syncthing.nix
./restic.nix
./monitoring.nix
./jenkins.nix
./emacs.nix
./forgejo.nix
./ankisync.nix
./freshrss.nix
]; ];
} }