From adf04a93931e65d3451a77aa788e81e96b10eb49 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 11 Dec 2021 13:37:27 +0800 Subject: [PATCH] Update various configurations Flake outputs, hosts, users, and formatting of Nix files. et cetera, et cetera. --- flake.nix | 5 ++ hosts/ni/default.nix | 61 ++----------------- hosts/ni/hardware-configuration.nix | 25 ++++---- lib/flake-utils.nix | 52 ++++++++-------- modules/README.adoc | 22 +++++++ pkgs/doggo.nix | 2 +- pkgs/gnome-shell-extension-pop-shell.nix | 20 +++--- users/home-manager/foo-dogsquared/default.nix | 21 ++----- 8 files changed, 88 insertions(+), 120 deletions(-) create mode 100644 modules/README.adoc diff --git a/flake.nix b/flake.nix index 9f47caee..75bb6348 100644 --- a/flake.nix +++ b/flake.nix @@ -3,9 +3,11 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + # Managing home configurations. home-manager.url = "github:nix-community/home-manager"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; + # Managing your secrets. agenix.url = "github:ryantm/agenix"; agenix.inputs.nixpkgs.follows = "nixpkgs"; @@ -82,6 +84,9 @@ # Stallman-senpai will be disappointed. :( nixpkgs.config.allowUnfree = true; + + # Let home-manager to manage itself. + programs.home-manager.enable = true; }; in { # Exposes only my library with the custom functions to make it easier to include in other flakes. diff --git a/hosts/ni/default.nix b/hosts/ni/default.nix index b176afae..7187049c 100644 --- a/hosts/ni/default.nix +++ b/hosts/ni/default.nix @@ -5,7 +5,8 @@ { config, pkgs, ... }: { - imports = [ # Include the results of the hardware scan. + imports = [ + # Include the results of the hardware scan. ./hardware-configuration.nix ]; @@ -18,6 +19,7 @@ audio.enable = true; fonts.enable = true; hardware.enable = true; + cleanup.enable = true; }; dev = { enable = true; @@ -27,6 +29,7 @@ editors.neovim.enable = true; themes.a-happy-gnome.enable = true; users.users = [ "foo-dogsquared" ]; + hardware-setup.backup-archive.enable = true; }; # Use the systemd-boot EFI boot loader. @@ -71,61 +74,5 @@ # Before changing this value read the documentation for this option # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). system.stateVersion = "21.11"; # Did you read the comment? - - # This is my external hard disk so it has to be non-blocking. - fileSystems."/mnt/external-storage" = { - device = "/dev/disk/by-uuid/665A391C5A38EB07"; - fsType = "ntfs"; - noCheck = true; - options = [ - "nofail" - "noauto" - "user" - - # See systemd.mount.5 and systemd.automount.5 manual page for more - # details. - "x-systemd.automount" - "x-systemd.device-timeout=2" - "x-systemd.idle-timeout=2" - ]; - }; - - # Automated backup for my external storage. - services.borgbackup.jobs = { - personal_archive = { - exclude = [ - "/home/*/.cache" - - # The usual NodeJS shenanigans. - "*/node_modules" - "*/.next" - - # Rust-related files. - "projects/software/*/result" - "projects/software/*/build" - "projects/software/*/target" - ]; - doInit = false; - removableDevice = true; - repo = "/mnt/external-storage/backups"; - paths = [ "~/dotfiles" "~/library" "~/writings" ]; - encryption = { - mode = "repokey"; - passCommand = "${pkgs.gopass}/bin/gopass show misc/BorgBackup_pass"; - }; - compression = "auto,lzma"; - startAt = "daily"; - prune = { - prefix = "{hostname}-"; - keep = { - within = "1d"; - daily = 30; - weekly = 4; - monthly = 6; - yearly = 4; - }; - }; - }; - }; } diff --git a/hosts/ni/hardware-configuration.nix b/hosts/ni/hardware-configuration.nix index ade25094..3fcce692 100644 --- a/hosts/ni/hardware-configuration.nix +++ b/hosts/ni/hardware-configuration.nix @@ -4,26 +4,25 @@ { config, lib, pkgs, modulesPath, ... }: { - imports = - [ (modulesPath + "/installer/scan/not-detected.nix") - ]; + imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; - boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" ]; + boot.initrd.availableKernelModules = + [ "xhci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" ]; boot.initrd.kernelModules = [ ]; boot.kernelModules = [ "kvm-intel" ]; boot.extraModulePackages = [ ]; - fileSystems."/" = - { device = "/dev/disk/by-uuid/f52c2729-2036-4bdf-8d54-21f929f3447b"; - fsType = "ext4"; - }; + fileSystems."/" = { + device = "/dev/disk/by-uuid/f52c2729-2036-4bdf-8d54-21f929f3447b"; + fsType = "ext4"; + }; - fileSystems."/boot" = - { device = "/dev/disk/by-uuid/AB3A-34BC"; - fsType = "vfat"; - }; + fileSystems."/boot" = { + device = "/dev/disk/by-uuid/AB3A-34BC"; + fsType = "vfat"; + }; - swapDevices = [ { label = "swap"; } ]; + swapDevices = [{ label = "swap"; }]; powerManagement.cpuFreqGovernor = lib.mkDefault "powersave"; } diff --git a/lib/flake-utils.nix b/lib/flake-utils.nix index d3bb7de9..12730ca3 100644 --- a/lib/flake-utils.nix +++ b/lib/flake-utils.nix @@ -50,32 +50,36 @@ in rec { ++ (lib.modulesToList (lib.filesToAttr ../modules/nixos)); }; - /* Create a home-manager configuration for use in flakes. + /* Create a home-manager configuration for use in flakes. - This is a wrapper for `home-manager.lib.homeManagerConfiguration`. + This is a wrapper for `home-manager.lib.homeManagerConfiguration`. - Signature: - file -> attrset -> homeManagerConfiguration - Where: - - `file` is the entry point to the home-manager configuration. - - `attrset` is the additional attribute set to be insert as one of the imported modules minus the attributes used for `home-manager.lib.homeManagerConfiguration`. - Returns: - A home-manager configuration to be exported in flakes. + Signature: + file -> attrset -> homeManagerConfiguration + Where: + - `file` is the entry point to the home-manager configuration. + - `attrset` is the additional attribute set to be insert as one of the imported modules minus the attributes used for `home-manager.lib.homeManagerConfiguration`. + Returns: + A home-manager configuration to be exported in flakes. - Example: - mkUser ./users/foo-dogsquared {} - => { ... } # A home-manager configuration set. + Example: + mkUser ./users/foo-dogsquared {} + => { ... } # A home-manager configuration set. */ - mkUser = file: attrs@{ username ? (builtins.baseNameOf file), system ? sys, extraModules ? [], ... }: - let - hmConfigFunctionArgs = builtins.attrNames (builtins.functionArgs inputs.home-manager.lib.homeManagerConfiguration); - hmModules = lib.map (path: import path) (lib.modulesToList (lib.filesToAttrRec ../modules/home-manager)); - in - inputs.home-manager.lib.homeManagerConfiguration { - inherit system username; - configuration = import file; - homeDirectory = "/home/${username}"; - extraModules = hmModules ++ extraModules ++ [ (lib.filterAttrs (n: _: !lib.elem n hmConfigFunctionArgs) attrs) ]; - extraSpecialArgs = { inherit lib system; }; - }; + mkUser = file: + attrs@{ username ? (builtins.baseNameOf file), system ? sys + , extraModules ? [ ], ... }: + let + hmConfigFunctionArgs = builtins.attrNames (builtins.functionArgs + inputs.home-manager.lib.homeManagerConfiguration); + hmModules = lib.map (path: import path) + (lib.modulesToList (lib.filesToAttrRec ../modules/home-manager)); + in inputs.home-manager.lib.homeManagerConfiguration { + inherit system username; + configuration = import file; + homeDirectory = "/home/${username}"; + extraModules = hmModules ++ extraModules + ++ [ (lib.filterAttrs (n: _: !lib.elem n hmConfigFunctionArgs) attrs) ]; + extraSpecialArgs = { inherit lib system; }; + }; } diff --git a/modules/README.adoc b/modules/README.adoc new file mode 100644 index 00000000..b869d120 --- /dev/null +++ b/modules/README.adoc @@ -0,0 +1,22 @@ += Modules +:toc: + +This directory contains modules for different components such as link:https://nixos.org/manual/nixos/stable/index.html#sec-writing-modules[NixOS modules] and link:https://github.com/nix-community/home-manager/[home-manager modules]. + + + + +== Importing the modules + +Usually, you'll see no `default.nix` in place since it is imported through other means. +One of the most common way is through `filesToAttr` defined in link:../lib[my custom library]. + +For example, to easily get a list of imported custom NixOS modules, here's one way with the custom library. + +[source, nix] +---- +lib.map (path: import path) (lib.modulesToList (lib.filesToAttr ./modules/nixos)) +---- + +Each modules may have to be imported differently. +Please see the respective documentation (i.e., `man:configuration.nix(5)`, `man:home-configuration.nix` ) for more details. diff --git a/pkgs/doggo.nix b/pkgs/doggo.nix index 26915f54..e6f0fa95 100644 --- a/pkgs/doggo.nix +++ b/pkgs/doggo.nix @@ -25,7 +25,7 @@ buildGoModule rec { ''; meta = with lib; { - description = "HTTP DNS client for humans."; + description = "HTTP DNS client for humans"; homepage = "https://github.com/mr-karan/doggo"; license = licenses.mit; }; diff --git a/pkgs/gnome-shell-extension-pop-shell.nix b/pkgs/gnome-shell-extension-pop-shell.nix index dc1b3e9b..aba9fa02 100644 --- a/pkgs/gnome-shell-extension-pop-shell.nix +++ b/pkgs/gnome-shell-extension-pop-shell.nix @@ -22,16 +22,18 @@ stdenv.mkDerivation rec { ]; postInstall = '' - install -Dm644 $out/share/gnome-shell/extensions/${passthru.extensionUuid}/schemas/* -t "${glib.makeSchemaPath "$out" "${pname}-${version}"}" + install -Dm644 $out/share/gnome-shell/extensions/${passthru.extensionUuid}/schemas/* -t "${ + glib.makeSchemaPath "$out" "${pname}-${version}" + }" - # TODO: Uncomment once custom gsettings works. - # Unfortunately custom gsettings seems to be not properly integrated with NixOS yet. - # - # For more information, please track the following issue: - # https://github.com/NixOS/nixpkgs/issues/92265 - # - # It also contains additional links to related issues and whatnot. - #install -Dm644 keybindings/*.xml -t $out/share/gnome-control-center/keybindings + # TODO: Uncomment once custom gsettings works. + # Unfortunately custom gsettings seems to be not properly integrated with NixOS yet. + # + # For more information, please track the following issue: + # https://github.com/NixOS/nixpkgs/issues/92265 + # + # It also contains additional links to related issues and whatnot. + #install -Dm644 keybindings/*.xml -t $out/share/gnome-control-center/keybindings ''; passthru.extensionUuid = "pop-shell@system76.com"; diff --git a/users/home-manager/foo-dogsquared/default.nix b/users/home-manager/foo-dogsquared/default.nix index feb8ddc7..a11d5df1 100644 --- a/users/home-manager/foo-dogsquared/default.nix +++ b/users/home-manager/foo-dogsquared/default.nix @@ -3,11 +3,12 @@ { home.packages = with pkgs; [ brave - mpv + emacs + github-cli + ncmpcpp ] # Doom Emacs dependencies. ++ (with pkgs; [ - git ripgrep gnutls emacs-all-the-icons-fonts @@ -46,24 +47,11 @@ enable = true; musicDirectory = "$HOME/library/music"; }; - services.mpdris2.enable = true; - - programs.ncmpcpp = { - enable = true; - package = pkgs.ncmpcpp.override { visualizerSupport = true; }; - # TODO: Add more vim-related keybindings. - bindings = [ - { key = "j"; command = "scroll_down"; } - { key = "k"; command = "scroll_up"; } - { key = "J"; command = [ "select_item" "scroll_down" ]; } - { key = "K"; command = [ "select_item" "scroll_up" ]; } - ]; - }; # My custom modules. modules = { + bleachbit.enable = true; i18n.enable = true; - archiving.enable = true; dev = { enable = true; shell.enable = true; @@ -73,5 +61,6 @@ graphics.enable = true; audio.enable = true; }; + research.enable = true; }; }