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,8 +5,7 @@
{ 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
]; ];
@ -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,11 +86,17 @@
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.
@ -114,14 +117,10 @@
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";

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.
@ -60,8 +58,7 @@ rec {
# `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
@ -71,7 +68,8 @@ rec {
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; };
@ -80,7 +78,9 @@ rec {
# 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)
@ -102,11 +102,8 @@ rec {
=> { 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,11 +1,10 @@
# 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.

View File

@ -3,13 +3,14 @@
# 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 [
@ -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,13 +2,15 @@
# 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 [
@ -22,9 +24,7 @@ in {
# 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;

View File

@ -1,23 +1,21 @@
{ 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
@ -39,7 +37,8 @@ in
# :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