From 3bffa8760ea1bd2d5472b6fe5395c735fb5eba4d Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Mon, 7 Jul 2025 19:04:17 +0800 Subject: [PATCH] feat(nixos): add machine module with virtualisation and usb options --- nix/manifest.nix | 9 ++++- nix/modules/options/bluetooth.nix | 16 -------- nix/modules/options/machine/default.nix | 37 +++++++++++++++++++ .../options/machine/virtualisation.nix | 36 ++++++++++++++++++ nix/modules/options/virtualisation.nix | 37 ------------------- 5 files changed, 81 insertions(+), 54 deletions(-) delete mode 100644 nix/modules/options/bluetooth.nix create mode 100644 nix/modules/options/machine/default.nix create mode 100644 nix/modules/options/machine/virtualisation.nix delete mode 100644 nix/modules/options/virtualisation.nix diff --git a/nix/manifest.nix b/nix/manifest.nix index a06a45e..e644a38 100644 --- a/nix/manifest.nix +++ b/nix/manifest.nix @@ -2,8 +2,15 @@ let testCfg = { hostName, ... }: { - boot.loader.systemd-boot.enable = true; networking = { inherit hostName; }; + machine = { + bluetooth.enable = true; + usb.automount = true; + virtualisation.podman = { + enable = true; + distrobox.enable = true; + }; + }; }; in { diff --git a/nix/modules/options/bluetooth.nix b/nix/modules/options/bluetooth.nix deleted file mode 100644 index 1c28f82..0000000 --- a/nix/modules/options/bluetooth.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ lib, ... }: -let - inherit (lib.options) mkEnableOption; -in -{ - flake.modules.nixos.default = { - options.bluetooth.enable = mkEnableOption ""; - config = { - persistDirs = [ "/var/lib/bluetooth" ]; - hardware.bluetooth = { - enable = true; - settings.General.Experimental = true; - }; - }; - }; -} diff --git a/nix/modules/options/machine/default.nix b/nix/modules/options/machine/default.nix new file mode 100644 index 0000000..48adc2a --- /dev/null +++ b/nix/modules/options/machine/default.nix @@ -0,0 +1,37 @@ +{ lib, ... }: +let + inherit (lib.options) mkEnableOption; + inherit (lib.modules) mkIf mkMerge; +in +{ + flake.modules.nixos.default = + { config, ... }: + let + cfg = config.machine; + in + { + options.machine.bluetooth.enable = mkEnableOption ""; + options.machine.usb.automount = mkEnableOption ""; + config = mkMerge [ + (mkIf cfg.usb.automount { + services.udisks2.enable = true; + home-manager.sharedModules = [ + { + services.udiskie = { + enable = true; + automount = true; + notify = true; + }; + } + ]; + }) + (mkIf cfg.bluetooth.enable { + persistDirs = [ "/var/lib/bluetooth" ]; + hardware.bluetooth = { + enable = true; + settings.General.Experimental = true; + }; + }) + ]; + }; +} diff --git a/nix/modules/options/machine/virtualisation.nix b/nix/modules/options/machine/virtualisation.nix new file mode 100644 index 0000000..81b586e --- /dev/null +++ b/nix/modules/options/machine/virtualisation.nix @@ -0,0 +1,36 @@ +{ lib, config, ... }: +let + inherit (lib.modules) mkIf; + inherit (lib.options) mkEnableOption; + inherit (lib.lists) optional; + inherit (config.flake.lib.modules) forAllUsers; +in +{ + flake.modules.nixos.default = + { pkgs, config, ... }: + let + cfg = config.machine.virtualisation; + in + { + options.machine.virtualisation = { + podman.enable = mkEnableOption ""; + podman.distrobox.enable = mkEnableOption ""; + }; + config = mkIf cfg.podman.enable { + virtualisation.containers.enable = true; + virtualisation.podman = { + enable = true; + dockerCompat = true; + defaultNetwork.settings.dns_enabled = true; + }; + users.users = forAllUsers { + extraGroups = [ "podman" ]; + autoSubUidGidRange = cfg.podman.distrobox.enable; + }; + home-manager.sharedModules = optional cfg.podman.distrobox.enable { + home.packages = [ pkgs.distrobox ]; + persistDirs = [ ".local/share/containers" ]; + }; + }; + }; +} diff --git a/nix/modules/options/virtualisation.nix b/nix/modules/options/virtualisation.nix deleted file mode 100644 index f01e3c2..0000000 --- a/nix/modules/options/virtualisation.nix +++ /dev/null @@ -1,37 +0,0 @@ -{ lib, config, ... }: -let - inherit (lib.modules) mkIf; - inherit (lib.options) mkEnableOption; - inherit (cfg.lib.modules) forAllUsers; - cfg = config.flake; -in -{ - flake.modules.nixos.default = - { pkgs, config, ... }: - { - options = { - podman.enable = mkEnableOption ""; - podman.distrobox.enable = mkEnableOption ""; - }; - config = mkIf config.podman.enable { - virtualisation = { - containers.enable = true; - podman = { - enable = true; - dockerCompat = true; - defaultNetwork.settings.dns_enabled = true; - }; - }; - users.users = forAllUsers { - extraGroups = [ "podman" ]; - autoSubUidGidRange = true; - }; - home-manager.sharedModules = [ - { - home.packages = [ pkgs.distrobox ]; - persistDirs = [ ".local/share/containers" ]; - } - ]; - }; - }; -}