From 23f5aaaf45b572a93da3f45b609434f6fecc25de Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Sun, 1 Sep 2024 20:31:24 +0200 Subject: [PATCH] huge `options` refactor due to being on a wifi and my sim card not being able to do its job properly this might have some errors `nix flake check` gave me none for the current host but tbh who knows this commit moves everything from `options` to `hosts/common` and modifies the `createHost` function to import part of the files under that directory by default there's also a `hosts/common/optional` which is still being imported in `profile.nix` but now in a better way using `lib.path.append` in tandem with `lib.lists.map` --- README.md | 11 ++-- .../common/core}/binary-caches.nix | 0 .../common => hosts/common/core}/dash.nix | 0 .../common => hosts/common/core}/dbus.nix | 0 hosts/common/core/default.nix | 16 ++++++ .../common/core}/disable-nano.nix | 0 .../common => hosts/common/core}/disk.nix | 0 .../common => hosts/common/core}/docs.nix | 0 {options/common => hosts/common/core}/nix.nix | 0 .../common => hosts/common/core}/oomd.nix | 0 .../common/core}/pin-registry.nix | 0 .../common/core}/preserve-system.nix | 0 .../common/core}/switch-ng.nix | 0 .../common => hosts/common/core}/timezone.nix | 0 .../common}/desktop/bluetooth.nix | 0 hosts/common/desktop/default.nix | 9 +++ {options => hosts/common}/desktop/fonts.nix | 0 .../common/desktop}/kernel.nix | 0 hosts/common/desktop/malloc-perturb.nix | 5 ++ .../common/desktop}/systemd-boot.nix | 0 .../desktop => hosts/common/optional}/adb.nix | 0 .../common/optional}/asusd.nix | 0 .../common/optional}/cpu/amd.nix | 0 .../common/optional}/cpu/intel.nix | 0 .../common/optional}/displaylink.nix | 0 .../common/optional}/gns3.nix | 0 .../common/optional}/gpu/amd.nix | 0 .../common/optional}/libvirt.nix | 0 .../common/optional}/mullvad-vpn.nix | 0 .../common/optional}/opentabletdriver.nix | 0 .../common/optional}/power-supply.nix | 0 .../desktop => hosts/common/optional}/qmk.nix | 0 .../common/optional}/steam.nix | 0 .../common/optional}/suspend.nix | 0 .../common/optional}/v4l2.nix | 0 .../common/optional}/waydroid.nix | 0 .../common/optional}/wayland.nix | 0 .../common/optional}/wireshark.nix | 0 .../common/optional}/yubikey.nix | 0 hosts/default.nix | 18 +++--- hosts/del/profile.nix | 49 +++++++---------- hosts/hape/profile.nix | 49 +++++++---------- hosts/niks/profile.nix | 55 ++++++++----------- hosts/work/profile.nix | 35 +++++------- options/desktop/dev/malloc-perturb.nix | 5 -- 45 files changed, 121 insertions(+), 131 deletions(-) rename {options/common => hosts/common/core}/binary-caches.nix (100%) rename {options/common => hosts/common/core}/dash.nix (100%) rename {options/common => hosts/common/core}/dbus.nix (100%) create mode 100644 hosts/common/core/default.nix rename {options/common => hosts/common/core}/disable-nano.nix (100%) rename {options/common => hosts/common/core}/disk.nix (100%) rename {options/common => hosts/common/core}/docs.nix (100%) rename {options/common => hosts/common/core}/nix.nix (100%) rename {options/common => hosts/common/core}/oomd.nix (100%) rename {options/common => hosts/common/core}/pin-registry.nix (100%) rename {options/common => hosts/common/core}/preserve-system.nix (100%) rename {options/common => hosts/common/core}/switch-ng.nix (100%) rename {options/common => hosts/common/core}/timezone.nix (100%) rename {options => hosts/common}/desktop/bluetooth.nix (100%) create mode 100644 hosts/common/desktop/default.nix rename {options => hosts/common}/desktop/fonts.nix (100%) rename {options/common => hosts/common/desktop}/kernel.nix (100%) create mode 100644 hosts/common/desktop/malloc-perturb.nix rename {options/boot => hosts/common/desktop}/systemd-boot.nix (100%) rename {options/desktop => hosts/common/optional}/adb.nix (100%) rename {options/desktop => hosts/common/optional}/asusd.nix (100%) rename {options/common => hosts/common/optional}/cpu/amd.nix (100%) rename {options/common => hosts/common/optional}/cpu/intel.nix (100%) rename {options/desktop => hosts/common/optional}/displaylink.nix (100%) rename {options/desktop => hosts/common/optional}/gns3.nix (100%) rename {options/common => hosts/common/optional}/gpu/amd.nix (100%) rename {options/common => hosts/common/optional}/libvirt.nix (100%) rename {options/desktop => hosts/common/optional}/mullvad-vpn.nix (100%) rename {options/desktop => hosts/common/optional}/opentabletdriver.nix (100%) rename {options/desktop => hosts/common/optional}/power-supply.nix (100%) rename {options/desktop => hosts/common/optional}/qmk.nix (100%) rename {options/desktop => hosts/common/optional}/steam.nix (100%) rename {options/desktop => hosts/common/optional}/suspend.nix (100%) rename {options/desktop => hosts/common/optional}/v4l2.nix (100%) rename {options/desktop => hosts/common/optional}/waydroid.nix (100%) rename {options/desktop => hosts/common/optional}/wayland.nix (100%) rename {options/desktop => hosts/common/optional}/wireshark.nix (100%) rename {options/desktop => hosts/common/optional}/yubikey.nix (100%) delete mode 100644 options/desktop/dev/malloc-perturb.nix diff --git a/README.md b/README.md index 6ccd328..b61cee3 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,13 @@ niksos/ │ ├───del/ [Dell Latitude 7320 Detachable] │ ├───hape/ [HP EliteBook 840 G2] │ ├───niks/ [ASUS ROG Strix G513QY] -│ └───work/ [undisclosed model, might change] +│ ├───work/ [undisclosed model, might change] +│ └───common/ (shared configs) +│ ├───core/ (imported on all hosts) +│ ├───desktop/ (imported on all desktops) +│ ├───server/ (imported on all servers) +│ └───optional/ (imported in a host's `profile.nix`) ├───modules/ (custom modules you can enable under `poz`) -├───options/ (unconditional modules imported in `hosts/*/profile.nix`) -│ ├───common/ (options shared between most or all systems) -│ ├───desktop/ (desktop specific options + tablet / mobile) -│ └───server/ (server specific options) └───secrets/ (agenix secrets) ``` diff --git a/options/common/binary-caches.nix b/hosts/common/core/binary-caches.nix similarity index 100% rename from options/common/binary-caches.nix rename to hosts/common/core/binary-caches.nix diff --git a/options/common/dash.nix b/hosts/common/core/dash.nix similarity index 100% rename from options/common/dash.nix rename to hosts/common/core/dash.nix diff --git a/options/common/dbus.nix b/hosts/common/core/dbus.nix similarity index 100% rename from options/common/dbus.nix rename to hosts/common/core/dbus.nix diff --git a/hosts/common/core/default.nix b/hosts/common/core/default.nix new file mode 100644 index 0000000..51073da --- /dev/null +++ b/hosts/common/core/default.nix @@ -0,0 +1,16 @@ +{ + imports = [ + ./binary-caches.nix + ./dash.nix + ./dbus.nix + ./disable-nano.nix + ./disk.nix + ./docs.nix + ./nix.nix + ./oomd.nix + ./pin-registry.nix + ./preserve-system.nix + ./switch-ng.nix + ./timezone.nix + ]; +} diff --git a/options/common/disable-nano.nix b/hosts/common/core/disable-nano.nix similarity index 100% rename from options/common/disable-nano.nix rename to hosts/common/core/disable-nano.nix diff --git a/options/common/disk.nix b/hosts/common/core/disk.nix similarity index 100% rename from options/common/disk.nix rename to hosts/common/core/disk.nix diff --git a/options/common/docs.nix b/hosts/common/core/docs.nix similarity index 100% rename from options/common/docs.nix rename to hosts/common/core/docs.nix diff --git a/options/common/nix.nix b/hosts/common/core/nix.nix similarity index 100% rename from options/common/nix.nix rename to hosts/common/core/nix.nix diff --git a/options/common/oomd.nix b/hosts/common/core/oomd.nix similarity index 100% rename from options/common/oomd.nix rename to hosts/common/core/oomd.nix diff --git a/options/common/pin-registry.nix b/hosts/common/core/pin-registry.nix similarity index 100% rename from options/common/pin-registry.nix rename to hosts/common/core/pin-registry.nix diff --git a/options/common/preserve-system.nix b/hosts/common/core/preserve-system.nix similarity index 100% rename from options/common/preserve-system.nix rename to hosts/common/core/preserve-system.nix diff --git a/options/common/switch-ng.nix b/hosts/common/core/switch-ng.nix similarity index 100% rename from options/common/switch-ng.nix rename to hosts/common/core/switch-ng.nix diff --git a/options/common/timezone.nix b/hosts/common/core/timezone.nix similarity index 100% rename from options/common/timezone.nix rename to hosts/common/core/timezone.nix diff --git a/options/desktop/bluetooth.nix b/hosts/common/desktop/bluetooth.nix similarity index 100% rename from options/desktop/bluetooth.nix rename to hosts/common/desktop/bluetooth.nix diff --git a/hosts/common/desktop/default.nix b/hosts/common/desktop/default.nix new file mode 100644 index 0000000..5dc5aa2 --- /dev/null +++ b/hosts/common/desktop/default.nix @@ -0,0 +1,9 @@ +{ + imports = [ + ./bluetooth.nix + ./fonts.nix + ./kernel.nix + ./malloc-perturb.nix + ./systemd-boot.nix + ]; +} diff --git a/options/desktop/fonts.nix b/hosts/common/desktop/fonts.nix similarity index 100% rename from options/desktop/fonts.nix rename to hosts/common/desktop/fonts.nix diff --git a/options/common/kernel.nix b/hosts/common/desktop/kernel.nix similarity index 100% rename from options/common/kernel.nix rename to hosts/common/desktop/kernel.nix diff --git a/hosts/common/desktop/malloc-perturb.nix b/hosts/common/desktop/malloc-perturb.nix new file mode 100644 index 0000000..b274433 --- /dev/null +++ b/hosts/common/desktop/malloc-perturb.nix @@ -0,0 +1,5 @@ +{ + environment.sessionVariables = { + MALLOC_PERTURB_ = /*sh*/"$(($(head -200 /dev/urandom | cksum | cut -f1 -d ' ') % 255 + 1))"; + }; +} diff --git a/options/boot/systemd-boot.nix b/hosts/common/desktop/systemd-boot.nix similarity index 100% rename from options/boot/systemd-boot.nix rename to hosts/common/desktop/systemd-boot.nix diff --git a/options/desktop/adb.nix b/hosts/common/optional/adb.nix similarity index 100% rename from options/desktop/adb.nix rename to hosts/common/optional/adb.nix diff --git a/options/desktop/asusd.nix b/hosts/common/optional/asusd.nix similarity index 100% rename from options/desktop/asusd.nix rename to hosts/common/optional/asusd.nix diff --git a/options/common/cpu/amd.nix b/hosts/common/optional/cpu/amd.nix similarity index 100% rename from options/common/cpu/amd.nix rename to hosts/common/optional/cpu/amd.nix diff --git a/options/common/cpu/intel.nix b/hosts/common/optional/cpu/intel.nix similarity index 100% rename from options/common/cpu/intel.nix rename to hosts/common/optional/cpu/intel.nix diff --git a/options/desktop/displaylink.nix b/hosts/common/optional/displaylink.nix similarity index 100% rename from options/desktop/displaylink.nix rename to hosts/common/optional/displaylink.nix diff --git a/options/desktop/gns3.nix b/hosts/common/optional/gns3.nix similarity index 100% rename from options/desktop/gns3.nix rename to hosts/common/optional/gns3.nix diff --git a/options/common/gpu/amd.nix b/hosts/common/optional/gpu/amd.nix similarity index 100% rename from options/common/gpu/amd.nix rename to hosts/common/optional/gpu/amd.nix diff --git a/options/common/libvirt.nix b/hosts/common/optional/libvirt.nix similarity index 100% rename from options/common/libvirt.nix rename to hosts/common/optional/libvirt.nix diff --git a/options/desktop/mullvad-vpn.nix b/hosts/common/optional/mullvad-vpn.nix similarity index 100% rename from options/desktop/mullvad-vpn.nix rename to hosts/common/optional/mullvad-vpn.nix diff --git a/options/desktop/opentabletdriver.nix b/hosts/common/optional/opentabletdriver.nix similarity index 100% rename from options/desktop/opentabletdriver.nix rename to hosts/common/optional/opentabletdriver.nix diff --git a/options/desktop/power-supply.nix b/hosts/common/optional/power-supply.nix similarity index 100% rename from options/desktop/power-supply.nix rename to hosts/common/optional/power-supply.nix diff --git a/options/desktop/qmk.nix b/hosts/common/optional/qmk.nix similarity index 100% rename from options/desktop/qmk.nix rename to hosts/common/optional/qmk.nix diff --git a/options/desktop/steam.nix b/hosts/common/optional/steam.nix similarity index 100% rename from options/desktop/steam.nix rename to hosts/common/optional/steam.nix diff --git a/options/desktop/suspend.nix b/hosts/common/optional/suspend.nix similarity index 100% rename from options/desktop/suspend.nix rename to hosts/common/optional/suspend.nix diff --git a/options/desktop/v4l2.nix b/hosts/common/optional/v4l2.nix similarity index 100% rename from options/desktop/v4l2.nix rename to hosts/common/optional/v4l2.nix diff --git a/options/desktop/waydroid.nix b/hosts/common/optional/waydroid.nix similarity index 100% rename from options/desktop/waydroid.nix rename to hosts/common/optional/waydroid.nix diff --git a/options/desktop/wayland.nix b/hosts/common/optional/wayland.nix similarity index 100% rename from options/desktop/wayland.nix rename to hosts/common/optional/wayland.nix diff --git a/options/desktop/wireshark.nix b/hosts/common/optional/wireshark.nix similarity index 100% rename from options/desktop/wireshark.nix rename to hosts/common/optional/wireshark.nix diff --git a/options/desktop/yubikey.nix b/hosts/common/optional/yubikey.nix similarity index 100% rename from options/desktop/yubikey.nix rename to hosts/common/optional/yubikey.nix diff --git a/hosts/default.nix b/hosts/default.nix index 8df23e7..88d88c5 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -5,7 +5,7 @@ inherit (inputs) self; inherit (self) lib; - createHost = hostDir: lib.nixosSystem { + createHost' = extraModules: hostDir: lib.nixosSystem { system = null; specialArgs = { inherit lib inputs self; @@ -13,16 +13,20 @@ modules = [ hostDir ../modules - ]; + ./common/core + ] ++ extraModules; }; + + createDesktop = createHost' [ ./common/desktop ]; + createServer = createHost' []; in { - niks = createHost ./niks; + niks = createDesktop ./niks; - del = createHost ./del; + del = createDesktop ./del; - hape = createHost ./hape; + hape = createDesktop ./hape; - chmura = createHost ./chmura; + chmura = createServer ./chmura; - ${inputs.work-secrets.hostname} = createHost ./work; + ${inputs.work-secrets.hostname} = createDesktop ./work; } diff --git a/hosts/del/profile.nix b/hosts/del/profile.nix index 9691962..f934913 100644 --- a/hosts/del/profile.nix +++ b/hosts/del/profile.nix @@ -1,33 +1,22 @@ { - imports = [ - ../../options/boot/systemd-boot.nix - ../../options/common/binary-caches.nix - ../../options/common/cpu/intel.nix - ../../options/common/dash.nix - ../../options/common/dbus.nix - ../../options/common/disable-nano.nix - ../../options/common/disk.nix - ../../options/common/docs.nix - ../../options/common/kernel.nix - ../../options/common/nix.nix - ../../options/common/oomd.nix - ../../options/common/pin-registry.nix - ../../options/common/preserve-system.nix - ../../options/common/switch-ng.nix - ../../options/common/timezone.nix - ../../options/desktop/adb.nix - ../../options/desktop/bluetooth.nix - ../../options/desktop/dev/malloc-perturb.nix - ../../options/desktop/fonts.nix - ../../options/desktop/mullvad-vpn.nix - ../../options/desktop/opentabletdriver.nix - ../../options/desktop/power-supply.nix - ../../options/desktop/qmk.nix - ../../options/desktop/steam.nix - ../../options/desktop/suspend.nix - ../../options/desktop/v4l2.nix - ../../options/desktop/wayland.nix - ../../options/desktop/wireshark.nix - ../../options/desktop/yubikey.nix + lib, + ... +}: let + inherit (lib.lists) map; + inherit (lib.path) append; +in { + imports = map (append ../common/optional) [ + "adb.nix" + "cpu/intel.nix" + "mullvad-vpn.nix" + "opentabletdriver.nix" + "power-supply.nix" + "qmk.nix" + "steam.nix" + "suspend.nix" + "v4l2.nix" + "wayland.nix" + "wireshark.nix" + "yubikey.nix" ]; } diff --git a/hosts/hape/profile.nix b/hosts/hape/profile.nix index c83c9f7..cc03317 100644 --- a/hosts/hape/profile.nix +++ b/hosts/hape/profile.nix @@ -1,32 +1,23 @@ { - imports = [ - ../../options/boot/systemd-boot.nix - ../../options/common/binary-caches.nix - ../../options/common/cpu/intel.nix - ../../options/common/dash.nix - ../../options/common/dbus.nix - ../../options/common/disable-nano.nix - ../../options/common/disk.nix - ../../options/common/docs.nix - ../../options/common/kernel.nix - ../../options/common/nix.nix - ../../options/common/oomd.nix - ../../options/common/pin-registry.nix - ../../options/common/preserve-system.nix - ../../options/common/switch-ng.nix - ../../options/common/timezone.nix - ../../options/desktop/adb.nix - ../../options/desktop/bluetooth.nix - ../../options/desktop/dev/malloc-perturb.nix - ../../options/desktop/fonts.nix - ../../options/desktop/mullvad-vpn.nix - ../../options/desktop/opentabletdriver.nix - ../../options/desktop/power-supply.nix - ../../options/desktop/qmk.nix - ../../options/desktop/suspend.nix - ../../options/desktop/v4l2.nix - ../../options/desktop/wayland.nix - ../../options/desktop/wireshark.nix - ../../options/desktop/yubikey.nix + lib, + ... +}: let + inherit (lib.lists) map; + inherit (lib.path) append; +in { + imports = map (append ../common/optional) [ + "adb.nix" + "asusd.nix" + "cpu/amd.nix" + "gpu/amd.nix" + "mullvad-vpn.nix" + "opentabletdriver.nix" + "power-supply.nix" + "qmk.nix" + "suspend.nix" + "v4l2.nix" + "wayland.nix" + "wireshark.nix" + "yubikey.nix" ]; } diff --git a/hosts/niks/profile.nix b/hosts/niks/profile.nix index 831fca6..042bcba 100644 --- a/hosts/niks/profile.nix +++ b/hosts/niks/profile.nix @@ -1,36 +1,25 @@ { - imports = [ - ../../options/boot/systemd-boot.nix - ../../options/common/binary-caches.nix - ../../options/common/cpu/amd.nix - ../../options/common/dash.nix - ../../options/common/dbus.nix - ../../options/common/disable-nano.nix - ../../options/common/disk.nix - ../../options/common/docs.nix - ../../options/common/gpu/amd.nix - ../../options/common/kernel.nix - ../../options/common/libvirt.nix - ../../options/common/nix.nix - ../../options/common/oomd.nix - ../../options/common/pin-registry.nix - ../../options/common/preserve-system.nix - ../../options/common/switch-ng.nix - ../../options/common/timezone.nix - ../../options/desktop/adb.nix - ../../options/desktop/asusd.nix - ../../options/desktop/bluetooth.nix - ../../options/desktop/dev/malloc-perturb.nix - ../../options/desktop/fonts.nix - ../../options/desktop/mullvad-vpn.nix - ../../options/desktop/opentabletdriver.nix - #../../options/desktop/power-supply.nix - ../../options/desktop/qmk.nix - ../../options/desktop/steam.nix - ../../options/desktop/suspend.nix - ../../options/desktop/v4l2.nix - ../../options/desktop/wayland.nix - ../../options/desktop/wireshark.nix - ../../options/desktop/yubikey.nix + lib, + ... +}: let + inherit (lib.lists) map; + inherit (lib.path) append; +in { + imports = map (append ../common/optional) [ + "adb.nix" + "asusd.nix" + "cpu/amd.nix" + "gpu/amd.nix" + "libvirt.nix" + "mullvad-vpn.nix" + "opentabletdriver.nix" + #"power-supply.nix" + "qmk.nix" + "steam.nix" + "suspend.nix" + "v4l2.nix" + "wayland.nix" + "wireshark.nix" + "yubikey.nix" ]; } diff --git a/hosts/work/profile.nix b/hosts/work/profile.nix index b21c09d..c3cd317 100644 --- a/hosts/work/profile.nix +++ b/hosts/work/profile.nix @@ -1,25 +1,16 @@ { - imports = [ - ../../options/boot/systemd-boot.nix - ../../options/common/binary-caches.nix - ../../options/common/dash.nix - ../../options/common/disable-nano.nix - ../../options/common/cpu/intel.nix - ../../options/common/disk.nix - ../../options/common/docs.nix - ../../options/common/kernel.nix - ../../options/common/nix.nix - ../../options/common/oomd.nix - ../../options/common/pin-registry.nix - ../../options/common/preserve-system.nix - ../../options/common/timezone.nix - ../../options/desktop/bluetooth.nix - ../../options/desktop/displaylink.nix - ../../options/desktop/dev/malloc-perturb.nix - ../../options/desktop/fonts.nix - ../../options/desktop/suspend.nix - ../../options/desktop/v4l2.nix - ../../options/desktop/wayland.nix - ../../options/desktop/yubikey.nix + lib, + ... +}: let + inherit (lib.lists) map; + inherit (lib.path) append; +in { + imports = map (append ../common/optional) [ + "cpu/intel.nix" + "displaylink.nix" + "suspend.nix" + "v4l2.nix" + "wayland.nix" + "yubikey.nix" ]; } diff --git a/options/desktop/dev/malloc-perturb.nix b/options/desktop/dev/malloc-perturb.nix deleted file mode 100644 index bbc6d71..0000000 --- a/options/desktop/dev/malloc-perturb.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ - environment.sessionVariables = { - MALLOC_PERTURB_ = "$(($(head -200 /dev/urandom | cksum | cut -f1 -d ' ') % 255 + 1))"; - }; -}