From 855b932cbd4a085d9418de60d96e2e599cddcd7b Mon Sep 17 00:00:00 2001 From: Ranomier <> Date: Sat, 14 Jun 2025 21:43:23 +0200 Subject: [PATCH] feat: introduction of system_profiles --- hosts/crocoite/default.nix | 22 +--------------- hosts/crocoite/hardware-configuration.nix | 1 + lib/hostHelper.nix | 5 +++- modules/default.nix | 7 ++++- modules/dhcp-all-interfaces.nix | 9 +++++++ readme.md | 23 ++++++++++++++++ .../container.nix} | 4 +-- system_profiles/components/minify.nix | 16 ++++++++++++ .../nix-defaults.nix} | 18 +++++-------- system_profiles/desktop.nix | 8 ++++++ system_profiles/importers/desktop.nix | 22 ++++++++++++++++ system_profiles/importers/general.nix | 7 +++++ system_profiles/importers/server.nix | 7 +++++ system_profiles/mini.nix | 26 ------------------- system_profiles/server.nix | 9 +++---- 15 files changed, 117 insertions(+), 67 deletions(-) create mode 100644 modules/dhcp-all-interfaces.nix create mode 100644 readme.md rename system_profiles/{mini-container.nix => components/container.nix} (54%) create mode 100644 system_profiles/components/minify.nix rename system_profiles/{defaults.nix => components/nix-defaults.nix} (68%) create mode 100644 system_profiles/desktop.nix create mode 100644 system_profiles/importers/desktop.nix create mode 100644 system_profiles/importers/general.nix create mode 100644 system_profiles/importers/server.nix delete mode 100644 system_profiles/mini.nix diff --git a/hosts/crocoite/default.nix b/hosts/crocoite/default.nix index bd867fa..9275f72 100644 --- a/hosts/crocoite/default.nix +++ b/hosts/crocoite/default.nix @@ -28,32 +28,12 @@ }; imports = [ - # steam and other stuff seems to depend on perl - #"${modulesPath}/profiles/perlless.nix" - #nixos-hardware.nixosModules.lenovo-thinkpad-t14-amd-gen1 ./hardware-configuration.nix ./boot.nix - ../../modules - ../../modules/users - - ../../modules/hardware - - ../../modules/sec_auth - - ../../modules/software - ../../modules/software/browser - ../../modules/software/nix-helper - ../../modules/software/shells - ../../modules/software/office - - ../../modules/wm_and_de - - ../../modules/pkg_mgrmnt - - ../../system_profiles/defaults.nix + ../../system_profiles/desktop.nix # ../../experiments ]; } diff --git a/hosts/crocoite/hardware-configuration.nix b/hosts/crocoite/hardware-configuration.nix index 99cf29f..50cf88e 100644 --- a/hosts/crocoite/hardware-configuration.nix +++ b/hosts/crocoite/hardware-configuration.nix @@ -10,6 +10,7 @@ }: { imports = [ (modulesPath + "/installer/scan/not-detected.nix") + #nixos-hardware.nixosModules.lenovo-thinkpad-t14-amd-gen1 ]; boot.initrd.availableKernelModules = ["nvme" "ehci_pci" "xhci_pci" "usb_storage" "sd_mod" "rtsx_pci_sdmmc"]; diff --git a/lib/hostHelper.nix b/lib/hostHelper.nix index 21eace4..e4ab867 100644 --- a/lib/hostHelper.nix +++ b/lib/hostHelper.nix @@ -5,7 +5,10 @@ inArgs: hostname: hostOptions: let else inArgs.nixpkgs.lib.nixosSystem; in nixosSystem { - specialArgs = {inArgs = inArgs;}; + specialArgs = { + inArgs = inArgs; + rootPath = inArgs.self; + }; modules = [ ../hosts/${hostname} #./debug.nix diff --git a/modules/default.nix b/modules/default.nix index 745b4c0..e1045b5 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -2,11 +2,16 @@ imports = [ ./accessibility.nix ./customisation.nix + + # should only be imported directly or via system_profiles + #./dhcp-all-interfaces.nix + ./environment.nix ./firewall.nix ./locale.nix ./networking.nix - #./plymouth.nix + #./plymouth.nix # increases boot time too much + #./serial-console.nix # probably only for servers ./theming.nix ]; } diff --git a/modules/dhcp-all-interfaces.nix b/modules/dhcp-all-interfaces.nix new file mode 100644 index 0000000..a009914 --- /dev/null +++ b/modules/dhcp-all-interfaces.nix @@ -0,0 +1,9 @@ +{ + # Enables DHCP on each ethernet and wireless interface. + # In case of scripted networking (the default) this is the recommended approach. + # When using systemd-networkd it's still possible to use this option, + # but it's recommended to use it in conjunction with + # explicit per-interface declarations with: + # `networking.interfaces..useDHCP`. + networking.useDHCP = lib.mkDefault true; +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..6b38d20 --- /dev/null +++ b/readme.md @@ -0,0 +1,23 @@ +# My flake config + +Some awesome descriptive text here + +## folder structure + +### system_profiles + +This whole folder is for the most part just a system to clean up importing + +- In files in this (`system_profiles`) directory: + - should never import anything from parent directories + - can import things from the child directories +- The `importers` directory: + - Should only import things outside (above/parent) of the `system_profiles` directories. + - Probably only from the module directory or maybe a future nix-modules directory, + this rule is not set in stone yet + - should **not** import anything outside of this repository +- The `components` directory: + - Should never import anything from this repository + - It can import things from nixpkgs + - Should set only basic "system" settings + ("system" is not well defined) diff --git a/system_profiles/mini-container.nix b/system_profiles/components/container.nix similarity index 54% rename from system_profiles/mini-container.nix rename to system_profiles/components/container.nix index ce05d95..529d942 100644 --- a/system_profiles/mini-container.nix +++ b/system_profiles/components/container.nix @@ -1,6 +1,6 @@ +# For when to deploy to a container, +# can be used with minify to make things smaller {lib, ...}: { boot.isContainer = lib.mkDefault true; boot.kernel.enable = lib.mkDefault false; - - imports = [./mini.nix]; } diff --git a/system_profiles/components/minify.nix b/system_profiles/components/minify.nix new file mode 100644 index 0000000..429faa5 --- /dev/null +++ b/system_profiles/components/minify.nix @@ -0,0 +1,16 @@ +# This makes an installation smaller at the cost of +# features (and maybe even stability) +{lib, modulesPath, ...}: { + imports = [ + (modulesPath + "/profiles/minimal.nix") + #(modulesPath + "/profiles/perlless.nix") + ]; + + disabledModules = [ + (modulesPath + "/profiles/all-hardware.nix") + (modulesPath + "/profiles/base.nix") + ]; + + environment.defaultPackages = lib.mkDefault []; + nixpkgs.overlays = lib.mkDefault [(self: super: {})]; +} diff --git a/system_profiles/defaults.nix b/system_profiles/components/nix-defaults.nix similarity index 68% rename from system_profiles/defaults.nix rename to system_profiles/components/nix-defaults.nix index 442281f..13be0a2 100644 --- a/system_profiles/defaults.nix +++ b/system_profiles/components/nix-defaults.nix @@ -1,8 +1,6 @@ -{ - lib, - pkgs, - ... -}: { +# This loads some nix and nixpkgs specific settints +# i often need +{lib, pkgs, ...}: { # Disable if you don't want unfree packages nixpkgs.config.allowUnfree = lib.mkDefault true; @@ -15,11 +13,9 @@ channel.enable = lib.mkDefault false; - settings.experimental-features = lib.mkDefault ["nix-command" "flakes"]; + settings.experimental-features = lib.mkDefault [ + "nix-command" + "flakes" + ]; }; - - imports = [ - ../modules/locale.nix - ../modules/sec_auth/sudo-rs.nix - ]; } diff --git a/system_profiles/desktop.nix b/system_profiles/desktop.nix new file mode 100644 index 0000000..c2da4f2 --- /dev/null +++ b/system_profiles/desktop.nix @@ -0,0 +1,8 @@ +{ + imports = [ + ./components/nix-defaults.nix + + ./importers/desktop.nix + ./importers/general.nix + ]; +} diff --git a/system_profiles/importers/desktop.nix b/system_profiles/importers/desktop.nix new file mode 100644 index 0000000..6fc76ec --- /dev/null +++ b/system_profiles/importers/desktop.nix @@ -0,0 +1,22 @@ +# This basicly imports the whole modules folder +{rootPath, ...}: { + imports = [ + (rootPath + /modules) + + (rootPath + /modules/hardware) + + (rootPath + /modules/pkg_mgrmnt) + + (rootPath + /modules/sec_auth) + + (rootPath + /modules/software) + (rootPath + /modules/software/browser) + (rootPath + /modules/software/nix-helper) + (rootPath + /modules/software/office) + (rootPath + /modules/software/shells) + + (rootPath + /modules/users) + + (rootPath + /modules/wm_and_de) + ]; +} diff --git a/system_profiles/importers/general.nix b/system_profiles/importers/general.nix new file mode 100644 index 0000000..d9ccb24 --- /dev/null +++ b/system_profiles/importers/general.nix @@ -0,0 +1,7 @@ +# This loads some "general" defaults +{rootPath, ...}: { + imports = [ + (rootPath + /modules/locale.nix) + (rootPath + /modules/sec_auth/sudo-rs.nix) + ]; +} diff --git a/system_profiles/importers/server.nix b/system_profiles/importers/server.nix new file mode 100644 index 0000000..66f1e60 --- /dev/null +++ b/system_profiles/importers/server.nix @@ -0,0 +1,7 @@ +{rootPath, ...}: { + imports = [ + (rootPath + /modules/customisation.nix) + (rootPath + /modules/software/neovim.nix) + (rootPath + /modules/software/packages/core.nix) + ]; +} diff --git a/system_profiles/mini.nix b/system_profiles/mini.nix deleted file mode 100644 index e50e14a..0000000 --- a/system_profiles/mini.nix +++ /dev/null @@ -1,26 +0,0 @@ -{ - lib, - modulesPath, - ... -}: { - imports = [ - (modulesPath + "/profiles/minimal.nix") - #(modulesPath + "/profiles/perlless.nix") - - { - environment.defaultPackages = lib.mkDefault []; - nixpkgs.overlays = lib.mkDefault [(self: super: {})]; - - # Enables DHCP on each ethernet and wireless interface. In case of scripted networking - # (the default) this is the recommended approach. When using systemd-networkd it's - # still possible to use this option, but it's recommended to use it in conjunction - # with explicit per-interface declarations with `networking.interfaces..useDHCP`. - networking.useDHCP = lib.mkDefault true; - } - ]; - - disabledModules = [ - (modulesPath + "/profiles/all-hardware.nix") - (modulesPath + "/profiles/base.nix") - ]; -} diff --git a/system_profiles/server.nix b/system_profiles/server.nix index 65d54d6..8810958 100644 --- a/system_profiles/server.nix +++ b/system_profiles/server.nix @@ -1,10 +1,9 @@ { imports = [ - ./defaults.nix - ./mini.nix + ./components/minify.nix + ./components/nix-defaults.nix - ../modules/customisation.nix - ../modules/software/neovim.nix - ../modules/software/packages/core.nix + ./importers/general.nix + ./importers/server.nix ]; }