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

View File

@ -3,8 +3,7 @@
let
# Default system for our host configuration.
sys = "x86_64-linux";
in
rec {
in rec {
/* Create an attribute set that represents the structure of the modules
inside of a directory. While it can recurse into directories, it will
stop once it detects `default.nix` inside.
@ -21,23 +20,22 @@ rec {
filesToAttr = dirPath:
let
isModule = file: type:
(type == "regular" && lib.hasSuffix ".nix" file) || (type == "directory");
(type == "regular" && lib.hasSuffix ".nix" file)
|| (type == "directory");
collect = file: type: {
name = lib.removeSuffix ".nix" file;
value =
let
path = dirPath + "/${file}";
in
if (type == "regular") || (type == "directory" && lib.pathExists (path + "/default.nix"))
then path
else filesToAttr path;
};
value = let path = dirPath + "/${file}";
in if (type == "regular")
|| (type == "directory" && lib.pathExists (path + "/default.nix")) then
path
else
filesToAttr path;
};
files = lib.filterAttrs isModule (builtins.readDir dirPath);
in
lib.filterAttrs (name: value: value != { }) (lib.mapAttrs' collect files);
in lib.filterAttrs (name: value: value != { })
(lib.mapAttrs' collect files);
/* Like `filesToAttr` but does it recursively. Those modules with
`default.nix` are ignored and gives the full module directory this time.
@ -54,24 +52,24 @@ rec {
collect = name: file: {
inherit name;
# Since `filesToAttr` has already filtered the files, we can be assured
# it is only either a Nix file or a directory containing a
# `default.nix`.
value = if (lib.pathIsDirectory file) then filesToAttr file else file;
# Since `filesToAttr` has already filtered the files, we can be assured
# it is only either a Nix file or a directory containing a
# `default.nix`.
value = if (lib.pathIsDirectory file) then filesToAttr file else file;
};
in
lib.listToAttrs (lib.mapAttrsToList collect files);
in lib.listToAttrs (lib.mapAttrsToList collect files);
/* 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.
Example:
mkHost ./hosts/june {}
=> { ... } # NixOS configuration attrset
*/
mkHost = file: attrs@{ system ? sys, ... }:
mkHost = file:
attrs@{ system ? sys, ... }:
lib.nixosSystem {
inherit system;
specialArgs = { inherit lib system inputs; };
@ -79,34 +77,33 @@ rec {
# 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; }
# 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)
# Put the given attribute set (except for the system).
(lib.filterAttrs (n: v: !lib.elem n [ "system" ]) attrs)
# The entry point of the module.
# The entry point of the module.
file
]
# 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).
Examples:
zipToAttrs [ "tails" "breed" ] [ 1 "Doggo" ]
=> { tails = 1; breed = "Doggo" }
Examples:
zipToAttrs [ "tails" "breed" ] [ 1 "Doggo" ]
=> { tails = 1; breed = "Doggo" }
zipToAttrs [ "hello" "d" ] [ { r = 5; f = "dogs"; } { r = 532; f = "dogsso"; } ]
=> { d = { ... }; hello = { ... }; }
zipToAttrs [ "hello" "d" ] [ { r = 5; f = "dogs"; } { r = 532; f = "dogsso"; } ]
=> { d = { ... }; hello = { ... }; }
*/
zipToAttrs = keys: values:
lib.listToAttrs (
lib.zipListsWith (name: value: { inherit name value; })
keys
values
);
lib.listToAttrs
(lib.zipListsWith (name: value: { inherit name value; }) keys values);
/* Count the attributes with the given predicate.
@ -115,5 +112,6 @@ rec {
=> 2
*/
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.
{ inputs, lib, options, config, ... }:
let
cfg = config.modules.agenix;
let cfg = config.modules.agenix;
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 ];
config = lib.mkIf cfg.enable {

View File

@ -1,21 +1,20 @@
# All of your embarrassing moments, marked here forever.
{ config, options, lib, pkgs, ... }:
let
cfg = config.modules.archiving;
in
{
options.modules.archiving.enable = lib.mkEnableOption "Install and configure archiving tools.";
let cfg = config.modules.archiving;
in {
options.modules.archiving.enable =
lib.mkEnableOption "Install and configure archiving tools.";
# This is not going to set BorgBackup NixOS services for you.
# Please do it for host-specific configs instead.
config = lib.mkIf cfg.enable {
environment.systemPackages = with pkgs; [
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.
borgmatic # For those insisting on configurations for BorgBackup.
fanficfare # Your fanfics in my hard drive? Pay me rent first.
yt-dlp # More active fork after youtube-dl has been striked.
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.
borgmatic # For those insisting on configurations for BorgBackup.
fanficfare # Your fanfics in my hard drive? Pay me rent first.
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.
{ config, options, lib, pkgs, ... }:
let
cfg = config.modules.desktop;
in
{
let cfg = config.modules.desktop;
in {
options.modules.desktop = {
enable = lib.mkEnableOption "Enables all desktop-related services and default programs.";
audio.enable = lib.mkEnableOption "Enables all desktop audio-related services such as Pipewire.";
enable = lib.mkEnableOption
"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.
services.flatpak.enable = true;
@ -43,9 +44,25 @@ in
# Enable MPD-related services.
services.mpd.enable = true;
environment.systemPackages = with pkgs; [
ncmpcpp # Has the worst name for a music client WTF?
];
environment.systemPackages = with pkgs;
[
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`.
{ config, options, lib, pkgs, ... }:
let
cfg = config.modules.dev;
let cfg = config.modules.dev;
in {
options.modules.dev = {
enable = lib.mkEnableOption "Configures my barebones requirement for a development environment.";
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.)";
enable = lib.mkEnableOption
"Configures my barebones requirement for a development environment.";
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 [
({
# I want to include documentations for my own sanity, OK?
documentation = {
enable = true;
dev.enable = true;
nixos.enable = true;
};
# I want to include documentations for my own sanity, OK?
documentation = {
enable = true;
dev.enable = true;
nixos.enable = true;
};
# Configure all of the development-related configuration in the system.
programs.git.enable = true;
programs.gnupg = {
agent.enable = true;
};
# Configure all of the development-related configuration in the system.
programs.git.enable = true;
programs.gnupg = { agent.enable = true; };
# Convenience!
environment.localBinInPath = true;
# Convenience!
environment.localBinInPath = true;
# This is set as our system packages for the sake of convenience.
services.lorri.enable = true;
environment.systemPackages = with pkgs; [
cachix # Compile no more by using someone's binary cache!
curl # Our favorite network client.
cmake # The poster boy for the hated build system.
direnv # The power of local development environment.
gnumake # Make your life easier with GNU Make.
];
# This is set as our system packages for the sake of convenience.
services.lorri.enable = true;
environment.systemPackages = with pkgs; [
cachix # Compile no more by using someone's binary cache!
curl # Our favorite network client.
cmake # The poster boy for the hated build system.
direnv # The power of local development environment.
gnumake # Make your life easier with GNU Make.
];
})
(lib.mkIf cfg.shell.enable {
environment.systemPackages = with pkgs; [
alacritty # The terminal emu that can run fast.
lazygit # Git interface for the lazy.
fd # Oh nice, a more reliable `find`.
ripgrep # On nice, a more reliable `grep`.
exa # Oh nice, a shinier `ls`.
bat # dog > bat > cat
fzf # A fuzzy finder that enables fuzzy finding not furry finding, a common misconception.
gopass # An improved version of the password manager for hipsters.
zoxide # Gain teleportation abilities!
alacritty # The terminal emu that can run fast.
lazygit # Git interface for the lazy.
fd # Oh nice, a more reliable `find`.
ripgrep # On nice, a more reliable `grep`.
exa # Oh nice, a shinier `ls`.
bat # dog > bat > cat
fzf # A fuzzy finder that enables fuzzy finding not furry finding, a common misconception.
gopass # An improved version of the password manager for hipsters.
zoxide # Gain teleportation abilities!
];
})
@ -59,13 +59,13 @@ in {
# Enable podman just as my main container runtime or something.
virtualisation.podman = {
enable = true;
dockerCompat = true;
dockerCompat = true;
};
# Enable libvirt for muh qemu.
virtualisation.libvirtd = {
enable = true;
qemu.ovmf.enable = true;
qemu.ovmf.enable = true;
};
})
]);

View File

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

View File

@ -4,16 +4,17 @@ let
cfg = config.modules.themes.a-happy-gnome;
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 {
services.xserver.enable = true;
services.xserver.displayManager.gdm.enable = true;
services.xserver.desktopManager.gnome.enable = true;
environment.systemPackages = with pkgs; [
chrome-gnome-shell
# I'm pretty sure this is already done but just to make sure.
services.gnome.chrome-gnome-shell.enable = true;
environment.systemPackages = with pkgs; [
gnomeExtensions.arcmenu
gnomeExtensions.x11-gestures
gnomeExtensions.gsconnect