From 889742c4026dcb087fca71ac7f515899ceb483fe Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Mon, 6 Dec 2021 15:27:51 +0800 Subject: [PATCH] Add library and desktop modules --- hosts/ni/default.nix | 11 ++----- lib/default.nix | 54 ++++++-------------------------- modules/home-manager/desktop.nix | 3 ++ modules/nixos/desktop.nix | 13 ++++++++ 4 files changed, 27 insertions(+), 54 deletions(-) diff --git a/hosts/ni/default.nix b/hosts/ni/default.nix index 5fbbf858..b43e254f 100644 --- a/hosts/ni/default.nix +++ b/hosts/ni/default.nix @@ -17,6 +17,7 @@ enable = true; audio.enable = true; fonts.enable = true; + hardware.enable = true; }; dev = { enable = true; @@ -35,6 +36,7 @@ # Use the systemd-boot EFI boot loader. boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; + # Set your time zone. time.timeZone = "Asia/Manila"; @@ -51,15 +53,6 @@ networking.interfaces.enp1s0.useDHCP = true; networking.interfaces.wlp2s0.useDHCP = true; - # Enable CUPS to print documents. - services.printing.enable = true; - - # More power optimizations! - powerManagement.powertop.enable = true; - - # Enable touchpad support (enabled default in most desktopManager). - hardware.opentabletdriver.enable = true; - environment.systemPackages = with pkgs; [ git wget brave lf fd ripgrep ]; # Some programs need SUID wrappers, can be configured further or are diff --git a/lib/default.nix b/lib/default.nix index 057ab43e..63987249 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -93,48 +93,8 @@ in rec { let paths = lib.collect builtins.isPath attrs; in builtins.map (path: import path) paths; - /* Create a NixOS system through a given host folder. - It will automate some of the things such as making the last component - of the path as the hostname. - - Signature: - path -> attrset -> NixOS configuration - Where: - - `path` is a path to a Nix file for the host; the basename of the file - is also used as the hostname - - `attrset` is the attribute set to be included in the host configuration - Returns: - An attribute set from the `lib.nixosSystem` from `nixpkgs` flake. - - Example: - mkHost ./hosts/june {} - => { ... } # NixOS configuration attrset - */ - mkHost = file: - attrs@{ system ? sys, ... }: - lib.nixosSystem { - inherit system; - - # Additional attributes to be referred to our modules. - specialArgs = { inherit lib system inputs; }; - - # We also set the following in order for priority. - # Later modules will override previously imported modules. - modules = [ - # Set the hostname. - { networking.hostName = builtins.baseNameOf file; } - - # Put the given attribute set (except for the system). - (lib.filterAttrs (n: v: !lib.elem n [ "system" ]) attrs) - - # The entry point of the module. - file - ] - # Append with our custom modules from the modules folder. - ++ (lib.modulesToList (filesToAttr ../modules)); - }; - /* Return an attribute set of valid users from a given list of users. + This is a convenience function for getting users from the `./users` directory. Signature: list -> attrset @@ -143,12 +103,13 @@ in rec { - `attrset` is a set of valid users with the name as the key and the path as the value. Example: # Assuming only 'foo-dogsquared' is the existing user. - getUsers [ "foo-dogsquared" "archie" "brad" ] + # Get valid users from home-manager. + getUsers "home-manager" [ "foo-dogsquared" "archie" "brad" ] => { foo-dogsquared = /home/foo-dogsquared/projects/nixos-config/users/foo-dogsquared; } */ - getUsers = users: + getUsers = type: users: let - userModules = filesToAttr ../users; + userModules = filesToAttr ../users/${type}; invalidUsernames = [ "config" "modules" ]; in lib.filterAttrs (n: _: !lib.elem n invalidUsernames) userModules; @@ -169,7 +130,10 @@ in rec { Examples: countAttrs (name: value: value) { d = true; f = true; a = false; } - => 2 + => 2 + + countAttrs (name: value: value.enable) { d = { enable = true; }; f = { enable = false; package = [ ]; }; } + => 1 */ countAttrs = pred: attrs: lib.count (attr: pred attr.name attr.value) diff --git a/modules/home-manager/desktop.nix b/modules/home-manager/desktop.nix index 31af4b8a..3748b26d 100644 --- a/modules/home-manager/desktop.nix +++ b/modules/home-manager/desktop.nix @@ -19,6 +19,9 @@ in inkscape # Illustration wannabe tool. gimp # Photo editing wannabe tool. krita # Digital art wannabe tool. + + imagemagick # Ah yes, everyman's image manipulation tool. + gmic # Don't let the gimmicks fool you, it's a magical image framework. ]; }) diff --git a/modules/nixos/desktop.nix b/modules/nixos/desktop.nix index a093e6e8..ae1a6a5a 100644 --- a/modules/nixos/desktop.nix +++ b/modules/nixos/desktop.nix @@ -11,6 +11,8 @@ in { audio.enable = lib.mkEnableOption "Enables all desktop audio-related services such as Pipewire."; fonts.enable = lib.mkEnableOption "Enables font-related config."; + hardware.enable = lib.mkEnableOption + "Enables the common hardware-related configuration."; }; config = lib.mkIf cfg.enable (lib.mkMerge [ @@ -88,5 +90,16 @@ in { ]; }; }) + + (lib.mkIf cfg.hardware.enable { + # Enable tablet support with OpenTabletDriver. + hardware.opentabletdriver.enable = true; + + # More power optimizations! + powerManagement.powertop.enable = true; + + # Welp, this is surprising... + services.printing.enable = true; + }) ]); }