Format the Nix files properly

This commit is contained in:
Gabriel Arazas 2021-11-25 21:45:48 +08:00
parent 539a798009
commit f038f48464
8 changed files with 181 additions and 173 deletions

View File

@ -5,10 +5,9 @@
{ config, pkgs, ... }: { config, pkgs, ... }:
{ {
imports = imports = [ # Include the results of the hardware scan.
[ # Include the results of the hardware scan. ./hardware-configuration.nix
./hardware-configuration.nix ];
];
# My custom configuration with my custom modules starts here. # My custom configuration with my custom modules starts here.
modules = { modules = {
@ -63,22 +62,20 @@
# List packages installed in system profile. To search, run: # List packages installed in system profile. To search, run:
# $ nix search wget # $ nix search wget
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [ git wget brave lf fd ripgrep ];
git
wget
brave
lf
fd
ripgrep
];
# Some programs need SUID wrappers, can be configured further or are # Some programs need SUID wrappers, can be configured further or are
# started in user sessions. # started in user sessions.
programs.mtr.enable = true; programs.mtr.enable = true;
security.doas.enable = true;
# List services that you want to enable: # The usual doas config.
#services.borgmatic.enable = true; security.doas = {
enable = true;
extraRules = [{
groups = [ "wheel" ];
persist = true;
}];
};
# This value determines the NixOS release from which the default # This value determines the NixOS release from which the default
# settings for stateful data, like file locations and database versions # settings for stateful data, like file locations and database versions
@ -89,44 +86,46 @@
system.stateVersion = "21.11"; # Did you read the comment? system.stateVersion = "21.11"; # Did you read the comment?
# This is my external hard disk so it has to be non-blocking. # This is my external hard disk so it has to be non-blocking.
fileSystems."/archive" = fileSystems."/mnt/archive" = {
{ device = "/dev/disk/by-uuid/665A391C5A38EB07"; device = "/dev/disk/by-uuid/665A391C5A38EB07";
fsType = "ntfs"; fsType = "ntfs";
noCheck = true; noCheck = true;
options = [ "nofail" "noauto" "user" "x.systemd.automount" "x.systemd.device.timeout=1ms" ]; options = [
}; "nofail"
"noauto"
"user"
"x.systemd.automount"
"x.systemd.device.timeout=1ms"
];
};
# Automated backup for my external storage. # Automated backup for my external storage.
services.borgbackup.jobs = { services.borgbackup.jobs = {
personal_archive = { personal_archive = {
exclude = [ exclude = [
"/home/*/.cache" "/home/*/.cache"
# The usual NodeJS shenanigans. # The usual NodeJS shenanigans.
"*/node_modules" "*/node_modules"
"*/.next" "*/.next"
# Rust-related files. # Rust-related files.
"projects/software/*/result" "projects/software/*/result"
"projects/software/*/build" "projects/software/*/build"
"projects/software/*/target" "projects/software/*/target"
]; ];
doInit = false; doInit = false;
removableDevice = true; removableDevice = true;
repo = "/archive/backups"; repo = "/archive/backups";
paths = [ paths = [ "~/dotfiles" "~/library" "~/writings" ];
"~/dotfiles"
"~/library"
"~/writings"
];
encryption = { encryption = {
mode = "repokey"; mode = "repokey";
passCommand = "${pkgs.gopass}/bin/gopass show misc/BorgBackup_pass" passCommand = "${pkgs.gopass}/bin/gopass show misc/BorgBackup_pass";
}; };
compression = "auto,lzma"; compression = "auto,lzma";
startAt = "daily"; startAt = "daily";
prune = { prune = {
prefix = "{hostname}-"; prefix = "{hostname}-";
keep = { keep = {
within = "1d"; within = "1d";
daily = 30; daily = 30;

View File

@ -3,8 +3,7 @@
let let
# Default system for our host configuration. # Default system for our host configuration.
sys = "x86_64-linux"; sys = "x86_64-linux";
in in rec {
rec {
/* Create an attribute set that represents the structure of the modules /* Create an attribute set that represents the structure of the modules
inside of a directory. While it can recurse into directories, it will inside of a directory. While it can recurse into directories, it will
stop once it detects `default.nix` inside. stop once it detects `default.nix` inside.
@ -21,23 +20,22 @@ rec {
filesToAttr = dirPath: filesToAttr = dirPath:
let let
isModule = file: type: isModule = file: type:
(type == "regular" && lib.hasSuffix ".nix" file) || (type == "directory"); (type == "regular" && lib.hasSuffix ".nix" file)
|| (type == "directory");
collect = file: type: { collect = file: type: {
name = lib.removeSuffix ".nix" file; name = lib.removeSuffix ".nix" file;
value = value = let path = dirPath + "/${file}";
let in if (type == "regular")
path = dirPath + "/${file}"; || (type == "directory" && lib.pathExists (path + "/default.nix")) then
in path
if (type == "regular") || (type == "directory" && lib.pathExists (path + "/default.nix")) else
then path filesToAttr path;
else filesToAttr path; };
};
files = lib.filterAttrs isModule (builtins.readDir dirPath); files = lib.filterAttrs isModule (builtins.readDir dirPath);
in in lib.filterAttrs (name: value: value != { })
lib.filterAttrs (name: value: value != { }) (lib.mapAttrs' collect files); (lib.mapAttrs' collect files);
/* Like `filesToAttr` but does it recursively. Those modules with /* Like `filesToAttr` but does it recursively. Those modules with
`default.nix` are ignored and gives the full module directory this time. `default.nix` are ignored and gives the full module directory this time.
@ -54,24 +52,24 @@ rec {
collect = name: file: { collect = name: file: {
inherit name; inherit name;
# Since `filesToAttr` has already filtered the files, we can be assured # Since `filesToAttr` has already filtered the files, we can be assured
# it is only either a Nix file or a directory containing a # it is only either a Nix file or a directory containing a
# `default.nix`. # `default.nix`.
value = if (lib.pathIsDirectory file) then filesToAttr file else file; value = if (lib.pathIsDirectory file) then filesToAttr file else file;
}; };
in in lib.listToAttrs (lib.mapAttrsToList collect files);
lib.listToAttrs (lib.mapAttrsToList collect files);
/* Create a NixOS system through a given host folder. /* Create a NixOS system through a given host folder.
It will automate some of the things such as making the last component It will automate some of the things such as making the last component
of the path as the hostname. of the path as the hostname.
Example: Example:
mkHost ./hosts/june {} mkHost ./hosts/june {}
=> { ... } # NixOS configuration attrset => { ... } # NixOS configuration attrset
*/ */
mkHost = file: attrs@{ system ? sys, ... }: mkHost = file:
attrs@{ system ? sys, ... }:
lib.nixosSystem { lib.nixosSystem {
inherit system; inherit system;
specialArgs = { inherit lib system inputs; }; specialArgs = { inherit lib system inputs; };
@ -79,34 +77,33 @@ rec {
# We also set the following in order for priority. # We also set the following in order for priority.
# Later modules will override previously imported modules. # Later modules will override previously imported modules.
modules = [ modules = [
# Set the hostname. # Set the hostname.
{ networking.hostName = builtins.baseNameOf file; } {
networking.hostName = builtins.baseNameOf file;
}
# Put the given attribute set (except for the system). # Put the given attribute set (except for the system).
(lib.filterAttrs (n: v: !lib.elem n [ "system" ]) attrs) (lib.filterAttrs (n: v: !lib.elem n [ "system" ]) attrs)
# The entry point of the module. # The entry point of the module.
file file
] ]
# Append with our custom modules from the modules folder. # Append with our custom modules from the modules folder.
++ (lib.mapAttrsToList (n: v: import v) (filesToAttr ../modules)); ++ (lib.mapAttrsToList (n: v: import v) (filesToAttr ../modules));
}; };
/* Create an attribute set from two lists (or a zip). /* Create an attribute set from two lists (or a zip).
Examples: Examples:
zipToAttrs [ "tails" "breed" ] [ 1 "Doggo" ] zipToAttrs [ "tails" "breed" ] [ 1 "Doggo" ]
=> { tails = 1; breed = "Doggo" } => { tails = 1; breed = "Doggo" }
zipToAttrs [ "hello" "d" ] [ { r = 5; f = "dogs"; } { r = 532; f = "dogsso"; } ] zipToAttrs [ "hello" "d" ] [ { r = 5; f = "dogs"; } { r = 532; f = "dogsso"; } ]
=> { d = { ... }; hello = { ... }; } => { d = { ... }; hello = { ... }; }
*/ */
zipToAttrs = keys: values: zipToAttrs = keys: values:
lib.listToAttrs ( lib.listToAttrs
lib.zipListsWith (name: value: { inherit name value; }) (lib.zipListsWith (name: value: { inherit name value; }) keys values);
keys
values
);
/* Count the attributes with the given predicate. /* Count the attributes with the given predicate.
@ -115,5 +112,6 @@ rec {
=> 2 => 2
*/ */
countAttrs = pred: attrs: countAttrs = pred: attrs:
lib.count (attr: pred attr.name attr.value) (lib.mapAttrsToList lib.nameValuePair attrs); lib.count (attr: pred attr.name attr.value)
(lib.mapAttrsToList lib.nameValuePair attrs);
} }

View File

@ -1,10 +1,10 @@
# A module that automates setting up agenix for your system. # A module that automates setting up agenix for your system.
{ inputs, lib, options, config, ... }: { inputs, lib, options, config, ... }:
let let cfg = config.modules.agenix;
cfg = config.modules.agenix;
in { in {
options.modules.agenix.enable = lib.mkEnableOption "Enable agenix on your system"; options.modules.agenix.enable =
lib.mkEnableOption "Enable agenix on your system";
imports = [ inputs.agenix.nixosModules.age ]; imports = [ inputs.agenix.nixosModules.age ];
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {

View File

@ -1,21 +1,20 @@
# All of your embarrassing moments, marked here forever. # All of your embarrassing moments, marked here forever.
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let let cfg = config.modules.archiving;
cfg = config.modules.archiving; in {
in options.modules.archiving.enable =
{ lib.mkEnableOption "Install and configure archiving tools.";
options.modules.archiving.enable = lib.mkEnableOption "Install and configure archiving tools.";
# This is not going to set BorgBackup NixOS services for you. # This is not going to set BorgBackup NixOS services for you.
# Please do it for host-specific configs instead. # Please do it for host-specific configs instead.
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
archivebox # Create by ye' old pirate. archivebox # Create by ye' old pirate.
borgbackup # I'm pretty sure this is named after some thing from a franchise somewhere but I'm not omnipresent. borgbackup # I'm pretty sure this is named after some thing from a franchise somewhere but I'm not omnipresent.
borgmatic # For those insisting on configurations for BorgBackup. borgmatic # For those insisting on configurations for BorgBackup.
fanficfare # Your fanfics in my hard drive? Pay me rent first. fanficfare # Your fanfics in my hard drive? Pay me rent first.
yt-dlp # More active fork after youtube-dl has been striked. yt-dlp # More active fork after youtube-dl has been striked.
]; ];
}; };
} }

View File

@ -3,16 +3,17 @@
# That can be found in the `themes` module. # That can be found in the `themes` module.
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let let cfg = config.modules.desktop;
cfg = config.modules.desktop; in {
in
{
options.modules.desktop = { options.modules.desktop = {
enable = lib.mkEnableOption "Enables all desktop-related services and default programs."; enable = lib.mkEnableOption
audio.enable = lib.mkEnableOption "Enables all desktop audio-related services such as Pipewire."; "Enables all desktop-related services and default programs.";
audio.enable = lib.mkEnableOption
"Enables all desktop audio-related services such as Pipewire.";
fonts.enable = lib.mkEnableOption "Enables font-related config.";
}; };
config = lib.mkIf cfg.enable (lib.mkMerge [ config = lib.mkIf cfg.enable (lib.mkMerge [
({ ({
# Enable Flatpak for additional options for installing desktop applications. # Enable Flatpak for additional options for installing desktop applications.
services.flatpak.enable = true; services.flatpak.enable = true;
@ -43,9 +44,25 @@ in
# Enable MPD-related services. # Enable MPD-related services.
services.mpd.enable = true; services.mpd.enable = true;
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs;
ncmpcpp # Has the worst name for a music client WTF? [
]; ncmpcpp # Has the worst name for a music client WTF?
];
})
(lib.mkIf cfg.fonts.enable {
fonts = {
enableDefaultFonts = true;
fontconfig = {
enable = true;
includeUserConf = true;
};
fonts = with pkgs;
[
];
};
}) })
]); ]);
} }

View File

@ -2,55 +2,55 @@
# If you want to see editor-specific modules, see `modules/editors.nix`. # If you want to see editor-specific modules, see `modules/editors.nix`.
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let let cfg = config.modules.dev;
cfg = config.modules.dev;
in { in {
options.modules.dev = { options.modules.dev = {
enable = lib.mkEnableOption "Configures my barebones requirement for a development environment."; enable = lib.mkEnableOption
shell.enable = lib.mkEnableOption "Installs of the shell utilities I rely on."; "Configures my barebones requirement for a development environment.";
virtualization.enable = lib.mkEnableOption "Configures my virtualization-related stuff for my development. (I sometimes have to use these.)"; shell.enable =
lib.mkEnableOption "Installs of the shell utilities I rely on.";
virtualization.enable = lib.mkEnableOption
"Configures my virtualization-related stuff for my development. (I sometimes have to use these.)";
}; };
config = lib.mkIf cfg.enable (lib.mkMerge [ config = lib.mkIf cfg.enable (lib.mkMerge [
({ ({
# I want to include documentations for my own sanity, OK? # I want to include documentations for my own sanity, OK?
documentation = { documentation = {
enable = true; enable = true;
dev.enable = true; dev.enable = true;
nixos.enable = true; nixos.enable = true;
}; };
# Configure all of the development-related configuration in the system. # Configure all of the development-related configuration in the system.
programs.git.enable = true; programs.git.enable = true;
programs.gnupg = { programs.gnupg = { agent.enable = true; };
agent.enable = true;
};
# Convenience! # Convenience!
environment.localBinInPath = true; environment.localBinInPath = true;
# This is set as our system packages for the sake of convenience. # This is set as our system packages for the sake of convenience.
services.lorri.enable = true; services.lorri.enable = true;
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
cachix # Compile no more by using someone's binary cache! cachix # Compile no more by using someone's binary cache!
curl # Our favorite network client. curl # Our favorite network client.
cmake # The poster boy for the hated build system. cmake # The poster boy for the hated build system.
direnv # The power of local development environment. direnv # The power of local development environment.
gnumake # Make your life easier with GNU Make. gnumake # Make your life easier with GNU Make.
]; ];
}) })
(lib.mkIf cfg.shell.enable { (lib.mkIf cfg.shell.enable {
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
alacritty # The terminal emu that can run fast. alacritty # The terminal emu that can run fast.
lazygit # Git interface for the lazy. lazygit # Git interface for the lazy.
fd # Oh nice, a more reliable `find`. fd # Oh nice, a more reliable `find`.
ripgrep # On nice, a more reliable `grep`. ripgrep # On nice, a more reliable `grep`.
exa # Oh nice, a shinier `ls`. exa # Oh nice, a shinier `ls`.
bat # dog > bat > cat bat # dog > bat > cat
fzf # A fuzzy finder that enables fuzzy finding not furry finding, a common misconception. fzf # A fuzzy finder that enables fuzzy finding not furry finding, a common misconception.
gopass # An improved version of the password manager for hipsters. gopass # An improved version of the password manager for hipsters.
zoxide # Gain teleportation abilities! zoxide # Gain teleportation abilities!
]; ];
}) })
@ -59,13 +59,13 @@ in {
# Enable podman just as my main container runtime or something. # Enable podman just as my main container runtime or something.
virtualisation.podman = { virtualisation.podman = {
enable = true; enable = true;
dockerCompat = true; dockerCompat = true;
}; };
# Enable libvirt for muh qemu. # Enable libvirt for muh qemu.
virtualisation.libvirtd = { virtualisation.libvirtd = {
enable = true; enable = true;
qemu.ovmf.enable = true; qemu.ovmf.enable = true;
}; };
}) })
]); ]);

View File

@ -1,45 +1,44 @@
{ config, options, lib, pkgs, ... }: { config, options, lib, pkgs, ... }:
let let cfg = config.modules.editors;
cfg = config.modules.editors; in {
in
{
options.modules.editors = { options.modules.editors = {
neovim.enable = lib.mkEnableOption "Enable Neovim and its components"; neovim.enable = lib.mkEnableOption "Enable Neovim and its components";
emacs = { emacs = {
enable = lib.mkEnableOption "Enable Emacs and all of its components"; enable = lib.mkEnableOption "Enable Emacs and all of its components";
doom.enable = lib.mkEnableOption "Enable Doom Emacs-related dependencies."; doom.enable =
lib.mkEnableOption "Enable Doom Emacs-related dependencies.";
}; };
vscode.enable = lib.mkEnableOption "Enable Visual Studio Code"; vscode.enable = lib.mkEnableOption "Enable Visual Studio Code";
}; };
config = lib.mkMerge [ config = lib.mkMerge [
(lib.mkIf cfg.emacs.enable { (lib.mkIf cfg.emacs.enable {
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs;
emacs [ emacs ] ++ (if cfg.emacs.doom.enable then [
] ++ (if cfg.emacs.doom.enable then [ # The required depdencies.
# The required depdencies. git
git ripgrep
ripgrep gnutls
gnutls
# Optional dependencies. # Optional dependencies.
fd fd
imagemagick imagemagick
zstd zstd
# Module dependencies # Module dependencies
# :checkers spell # :checkers spell
aspell aspell
aspellDicts.en aspellDicts.en
aspellDicts.en-computer aspellDicts.en-computer
# :tools lookup # :tools lookup
wordnet wordnet
# :lang org +roam2 # :lang org +roam2
sqlite sqlite
] else []); ] else
[ ]);
}) })
(lib.mkIf cfg.neovim.enable { (lib.mkIf cfg.neovim.enable {
@ -50,16 +49,11 @@ in
withRuby = true; withRuby = true;
}; };
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [ editorconfig-core-c ];
editorconfig-core-c
];
}) })
(lib.mkIf cfg.vscode.enable { (lib.mkIf cfg.vscode.enable {
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [ vscode editorconfig-core-c ];
vscode
editorconfig-core-c
];
}) })
]; ];
} }

View File

@ -4,16 +4,17 @@ let
cfg = config.modules.themes.a-happy-gnome; cfg = config.modules.themes.a-happy-gnome;
in in
{ {
options.modules.theme.a-happy-gnome.enable = lib.mkEnableOption "Enables my configuration of GNOME Shell."; options.modules.themes.a-happy-gnome.enable = lib.mkEnableOption "Enables my configuration of GNOME Shell.";
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
services.xserver.enable = true; services.xserver.enable = true;
services.xserver.displayManager.gdm.enable = true; services.xserver.displayManager.gdm.enable = true;
services.xserver.desktopManager.gnome.enable = true; services.xserver.desktopManager.gnome.enable = true;
environment.systemPackages = with pkgs; [ # I'm pretty sure this is already done but just to make sure.
chrome-gnome-shell services.gnome.chrome-gnome-shell.enable = true;
environment.systemPackages = with pkgs; [
gnomeExtensions.arcmenu gnomeExtensions.arcmenu
gnomeExtensions.x11-gestures gnomeExtensions.x11-gestures
gnomeExtensions.gsconnect gnomeExtensions.gsconnect