dotfiles
My PC Dotfiles & Websitegit clone https://github.com/maydayv7/dotfiles
commit 660f873205dbbb18a2e84a8fcb1ff962ee275126 parent 17a9088b02481146f4258e9935241dbed9327a2b Author: maydayv7 <maydayv7@gmail.com> Date: Fri, 1 Dec 2023 17:07:28 +0530 refactor: Drop `.templates` + Refactor `lib.build` + Fix Script Shebangs
Diffstat:
| D | .templates/README.md | | | 3 | --- |
| D | .templates/flake.nix | | | 29 | ----------------------------- |
| D | .templates/minimal/.gitignore | | | 1 | - |
| D | .templates/minimal/flake.nix | | | 48 | ------------------------------------------------ |
| M | README.md | | | 15 | +++++++-------- |
| M | devices/flake.nix | | | 36 | +++++++++++++++++++++++++++++------- |
| M | flake.nix | | | 24 | ++++++++++++++++++------ |
| M | lib/README.md | | | 5 | ----- |
| M | lib/build.nix | | | 32 | ++------------------------------ |
| D | lib/default.nix | | | 2 | -- |
| M | lib/map.nix | | | 16 | ++++++++-------- |
| M | lib/pack.nix | | | 13 | ++++--------- |
| D | packages/dotfiles.nix | | | 21 | --------------------- |
| M | packages/flake.nix | | | 1 | - |
| M | scripts/README.md | | | 2 | +- |
| M | scripts/commands.sh | | | 2 | +- |
| M | scripts/mail.sh | | | 2 | +- |
| M | scripts/nixos.nix | | | 8 | ++++---- |
| M | scripts/packages.sh | | | 2 | +- |
| M | scripts/partitions.sh | | | 2 | +- |
| M | scripts/pci.sh | | | 2 | +- |
| M | users/README.md | | | 2 | +- |
22 files changed, 79 insertions(+), 189 deletions(-)
diff --git a/.templates/README.md b/.templates/README.md @@ -1,3 +0,0 @@ -### Configuration Templates - -You can use `nix flake init -t github:maydayv7/dotfiles` for a basic Flakes-compatible system configuration diff --git a/.templates/flake.nix b/.templates/flake.nix @@ -1,29 +0,0 @@ -{inputs, ...}: { - flake.templates = let - inherit (inputs.filters.lib) filter matchExt; - in { - ## Configuration Templates ## - default = { - description = "Simple, Minimal NixOS Configuration"; - path = filter { - root = ./minimal; - include = [(matchExt "nix")]; - }; - }; - - extensive = { - description = "My Complete, Extensive NixOS Configuration"; - path = filter { - root = ../.; - exclude = [ - ./.github - ./.gitlab - ./site - ./packages/website.nix - (matchExt "md") - (matchExt "secret") - ]; - }; - }; - }; -} diff --git a/.templates/minimal/.gitignore b/.templates/minimal/.gitignore @@ -1 +0,0 @@ -flake.lock diff --git a/.templates/minimal/flake.nix b/.templates/minimal/flake.nix @@ -1,48 +0,0 @@ -{ - description = "Simple, Minimal NixOS Configuration"; - - ## System Repositories ## - inputs = { - ## Package Repositories ## - # NixOS Package Repository - nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable"; - - ## Configuration Modules ## - # My PC Dotfiles - dotfiles.url = "github:maydayv7/dotfiles"; - }; - - ## System Configuration ## - outputs = inputs: let - lib = with inputs; nixpkgs.lib // dotfiles.lib; - in { - nixosConfigurations.host = lib.build.device { - name = "HOST_NAME"; - system = "x86_64-linux"; - - # Generate these files using 'nixos-generate-config' - imports = [./configuration.nix ./hardware-configuration.nix]; - - timezone = "Asia/Kolkata"; - locale = "IN"; - - kernel = "zen"; - kernelModules = ["xhci_pci" "ahci" "usb_storage" "sd_mod"]; - - gui = {}; - hardware = { - boot = "efi"; - cores = 4; - filesystem = "simple"; - }; - - # Default User - user = { - name = "nixos"; - description = "Default User"; - minimal = true; - password = "HASHED_PASSWORD"; # Generate using 'mkpasswd -m sha-512' - }; - }; - }; -} diff --git a/README.md b/README.md @@ -115,8 +115,7 @@ github:maydayv7/dotfiles │ ├───nixos: package 'nixos' │ └───website: package 'website-stable' ├───templates -│ ├───default: template: Simple, Minimal NixOS Configuration -│ └───extensive: template: My Complete, Extensive NixOS Configuration +│ └───default: template: My NixOS Configuration └───vmConfigurations └───Windows: Virtual Machine ``` @@ -129,7 +128,6 @@ github:maydayv7/dotfiles ``` ┌── flake.nix ├── flake.lock -├── .templates ├── files ├── secrets ├── shells @@ -162,7 +160,6 @@ github:maydayv7/dotfiles - `flake.nix`: toplevel configuration file and repository version control [`flake-parts`](https://github.com/hercules-ci/flake-parts) is used for modularization -- `.templates`: custom Flakes configuration templates - [`files`](./files/README.md): `dotfiles` and program configuration - [`secrets`](./secrets/README.md): authentication credentials management using [`sops-nix`](https://github.com/Mic92/sops-nix) - `shells`: sand-boxed shells for development purposes @@ -177,7 +174,7 @@ github:maydayv7/dotfiles - `overlays`: overrides for pre-built packages - [`lib`](./lib/README.md): custom functions designed for conveniently defining configuration - [`modules`](./modules/README.md): custom configuration modules for additional functionality -- `configuration.nix`: builds system configuration as part of `lib.build` +- `configuration.nix`: builds system configuration ## Installation @@ -193,7 +190,7 @@ In case you want to use my configuration as-is for a fresh NixOS install, you ca cd /etc/nixos </code></pre> -2. Clone this repository (and preferably initialize it using `git`): <pre><code>nix flake init -t github:maydayv7/dotfiles#extensive +2. Clone this repository (and preferably initialize it using `git`): <pre><code>nix flake init -t github:maydayv7/dotfiles git init </code></pre> @@ -278,7 +275,7 @@ _In case you are using the `advanced` filesystem scheme, you may need to set the <details> <summary><b>Build It Yourself</b></summary> -If you really want to get dirty with Nix and decide to invest oodles of your time into building your own configuration, this repository can be used as inspiration. For starters, you can run `nix flake init -t github:maydayv7/dotfiles` in `/etc/nixos` for a basic Flakes-compatible system configuration. You can check out the list of links below to resourceful Nix documentation/tutorials/projects that may be helpful in your endeavour +If you really want to get dirty with Nix and decide to invest oodles of your time into building your own configuration, this repository can be used as inspiration. You can check out the list of links below to resourceful Nix documentation/tutorials/projects that may be helpful in your endeavour **Welcome** to the Nix Community! ;) @@ -416,13 +413,15 @@ You can navigate to the `README`s present in the various directories to know mor - Use the [`flake-parts`](https://flake.parts/) Flakes framework - Improve Syntax Formatting with `treefmt-nix` and drop `pre-commit-hooks` - Support declarative [Flatpak](https://flatpak.org/) application install +- Update Nix to version 2.19 - Allow patching Default Package Channel - Separate `games` and `laptop` module - Show package delta using [`nvd`](https://gitlab.com/khumba/nvd) - Upgrade to GNOME 45 - Fix Emoji Support - Update Extension -- Miscellaneous Updates +- Drop `.templates` +- Multiple Refactors ### v13 diff --git a/devices/flake.nix b/devices/flake.nix @@ -1,15 +1,17 @@ { + lib, util, inputs, ... }: let inherit (inputs) self; - inherit (util) build map pack; - inherit (builtins) head; + inherit (util) map pack; + inherit (builtins) head readFile; + inherit (import ../modules/configuration.nix {inherit lib inputs;}) build; in { flake = { ## Device Configuration ## - nixosConfigurations = map.modules ./. (name: build.device (import name)); + nixosConfigurations = map.modules ./. (name: build (import name)); ## Virtual Machines ## vmConfigurations = with self; @@ -18,15 +20,35 @@ in { ## Install Media Configuration ## installMedia = let - config = { + iso = config: + build (config + // { + format = "iso"; + description = "Install Media"; + + kernelModules = ["nvme"]; + kernel = "zfs"; + gui.desktop = config.gui.desktop + "-minimal"; + + # Default User + imports = [{user.home = lib.mkForce {};}]; + user = { + name = "nixos"; + description = "Default User"; + minimal = true; + shells = null; + password = readFile ../modules/user/passwords/default; + }; + }); + + region = { timezone = "Asia/Kolkata"; locale = "IN"; - kernel = "zfs"; }; in rec { default = xfce; - gnome = build.iso (config // {gui.desktop = "gnome";}); - xfce = build.iso (config // {gui.desktop = "xfce";}); + gnome = iso (region // {gui.desktop = "gnome";}); + xfce = iso (region // {gui.desktop = "xfce";}); }; }; diff --git a/flake.nix b/flake.nix @@ -144,23 +144,35 @@ ## Configuration ## outputs = {self, ...} @ inputs: let inherit (inputs.nixpkgs) lib; + map = import ./lib/map.nix lib; in inputs.framework.lib.mkFlake {inherit inputs;} { inherit (self) systems; debug = false; _module.args = {util = self.lib;}; - imports = - (import ./lib/map.nix {inherit lib;}).flake ./. - ++ [modules/nix/format.nix]; + imports = map.flake ./. ++ [modules/nix/format.nix]; flake = { # Supported Architectures systems = import inputs.systems; - ## Custom Library Functions - lib = import ./lib { - inherit lib inputs; + ## Custom Library Functions ## + lib = map.modules ./lib (file: import file lib); + + ## Configuration Template ## + templates.default = with inputs.filters.lib; { + description = "My NixOS Configuration"; + path = filter { + root = ./.; + exclude = [ + ./.github + ./.gitlab + ./site + (matchExt "md") + (matchExt "secret") + ]; + }; }; }; }; diff --git a/lib/README.md b/lib/README.md @@ -6,17 +6,12 @@ The `lib` directory contains custom-made utility functions (exposed as `util`), - [`build`](./build.nix): Configuration building functions for efficient system management and declaration - - - `device`: Main system configuration building function, used to build the entire configuration for devices (`nixosConfigurations`) as per provided parameters - - `iso`: configuration building function used to build the entire configuration for install media (`installMedia`) as per provided parameters - - `each`: Maps function for each `attr` as passed - `mime`: Builds and sets `mimetype` values according to specified application and types - `script`: Builds script from specified file by removing `shebangs` and exporting as a _string_ - [`map`](./map.nix): Mapping functions primarily aimed at shortening code complexity - - `array`: Maps required parameter to all elements present in `list` - - `checkAttr`: Checks if file contains an attrset - - `checkName`: Checks if file to be mapped has a valid name - `filter`: Filters out unneeded `attrs` and maps required ones to specified function - `list`: Lists all toplevel `attrs` of `attrset` and returns a space-separated string - `file`: Maps all files with a particular extension adhering to a particular condition stored in a directory as an `attrset` acted upon by specified function. Use `file'` in order to recursively search inside directories diff --git a/lib/build.nix b/lib/build.nix @@ -1,36 +1,8 @@ -{ - lib, - inputs, - ... -}: let - inherit (lib) flatten hasPrefix mapAttrsToList mkForce nameValuePair splitString; +lib: let + inherit (lib) flatten hasPrefix mapAttrsToList nameValuePair splitString; inherit (builtins) concatStringsSep filter hasAttr listToAttrs map readFile; in rec { ## Builder Functions ## - each = attr: func: - listToAttrs (map (name: nameValuePair name (func name)) attr); - - # Configuration Builders - device = (import ../modules/configuration.nix {inherit lib inputs;}).build; - iso = config: - device (config - // { - format = "iso"; - description = "Install Media"; - kernelModules = ["nvme"]; - gui.desktop = config.gui.desktop + "-minimal"; - - # Default User - imports = [{user.home = mkForce {};}]; - user = { - name = "nixos"; - description = "Default User"; - minimal = true; - shells = null; - password = readFile ../modules/user/passwords/default; - }; - }); - # Mime Types Handler mime = values: option: listToAttrs (flatten (mapAttrsToList (name: types: diff --git a/lib/default.nix b/lib/default.nix @@ -1,2 +0,0 @@ -args: -(import ./map.nix args).modules ./. (file: import file args) diff --git a/lib/map.nix b/lib/map.nix @@ -1,4 +1,4 @@ -{lib, ...}: let +lib: let inherit (builtins) attrNames @@ -26,6 +26,13 @@ nameValuePair removeSuffix ; + + # Import Checks + checkName = name: type: type != null && !(hasPrefix "_" name); + checkAttr = name: let + file = import name; + in + typeOf file == "set" || typeOf file == "lambda"; in rec { ## Mapping Functions ## array = list: func: forEach list (name: getAttrFromPath [name] func); @@ -81,13 +88,6 @@ in rec { then nameValuePair (removeSuffix ext name) (func path) else nameValuePair "" null) (readDir dir); - # Import Checks - checkName = name: type: type != null && !(hasPrefix "_" name); - checkAttr = name: let - file = import name; - in - typeOf file == "set" || typeOf file == "lambda"; - # Package Patches patches = patch: if isPath patch diff --git a/lib/pack.nix b/lib/pack.nix @@ -1,9 +1,4 @@ -{ - lib, - inputs, - ... -}: let - inherit (inputs) self; +lib: let inherit (builtins) attrNames; inherit (lib) genAttrs id mapAttrs'; in rec { @@ -16,9 +11,9 @@ in rec { }) (genAttrs (attrNames attrs) id); # User Home Configurations - user = user: + user = attrs: user: mapAttrs' (_: name: { name = "User-${name}"; - value = self.homeConfigurations."${user}".activationPackage; - }) (genAttrs (attrNames self.homeConfigurations) id); + value = attrs."${user}".activationPackage; + }) (genAttrs (attrNames attrs) id); } diff --git a/packages/dotfiles.nix b/packages/dotfiles.nix @@ -1,21 +0,0 @@ -{ - lib, - pkgs, - files, - ... -}: -pkgs.stdenv.mkDerivation rec { - pname = "Dotfiles"; - version = "v15"; - - src = files.path.toplevel; - dontBuild = true; - installPhase = "mkdir -p $out/ && cp -r . $out/"; - - meta = with lib; { - description = "My PC Dotfiles"; - homepage = files.path.repo; - license = licenses.mit; - maintainers = ["maydayv7"]; - }; -} diff --git a/packages/flake.nix b/packages/flake.nix @@ -60,7 +60,6 @@ in { packages = map.modules ./. call // map.modules ../scripts call - // {default = self'.packages.dotfiles;} // inputs'.proprietary.packages; }); diff --git a/scripts/README.md b/scripts/README.md @@ -1,6 +1,6 @@ ### Scripts -The `scripts` directory contains a combination of custom Bash Scripts (with `nix-shell` shebangs, and can be run using <code><i>./path/to/script</i></code>) as well as ones written in conjunction with the Nix Syntax (which can be accessed by `github:maydayv7/dotfiles#apps.${system}`) +The `scripts` directory contains a combination of custom Bash Scripts (with `nix` shebangs, and can be run using <code><i>./path/to/script</i></code>) as well as ones written in conjunction with the Nix Syntax (which can be accessed by `github:maydayv7/dotfiles#apps.${system}`) A system management script, invoked with the command [`nixos`](./nixos.nix), has been included, which can be used to apply user and device configuration changes, painlessly install the OS and setup the device using a single command, and perform various other useful functions (If you have a working NixOS install, you can check it out using `nix run github:maydayv7/dotfiles`) ```shellsession diff --git a/scripts/commands.sh b/scripts/commands.sh @@ -1,5 +1,5 @@ #! /usr/bin/env nix -#! nix shell nixpkgs#{bash,bzip2,coreutils,git,gnupg,gnutar,gzip,p7zip,unzip} -c bash +#! nix shell nixpkgs#bash nixpkgs#bzip2 nixpkgs#coreutils nixpkgs#git nixpkgs#gnupg nixpkgs#gnutar nixpkgs#gzip nixpkgs#p7zip nixpkgs#unzip -c bash # Useful Commands # diff --git a/scripts/mail.sh b/scripts/mail.sh @@ -1,5 +1,5 @@ #! /usr/bin/env nix -#! nix shell nixpkgs#{bash,coreutils,gnused,libpst} -c bash +#! nix shell nixpkgs#bash nixpkgs#coreutils nixpkgs#gnused nixpkgs#libpst -c bash # Script to convert '.pst' Files to '.mbox' # diff --git a/scripts/nixos.nix b/scripts/nixos.nix @@ -138,8 +138,8 @@ in nixos-rebuild dry-activate --flake ${path.system}# ;; "--delta") - rm -rf /tmp/build && mkdir /tmp/build - pushd /tmp/build &> /dev/null + DIR=/tmp/nixos/build + mkdir "$DIR" && pushd "$DIR" &> /dev/null echo "Building Configuration..." info "This may take a while..." if nixos-rebuild build --flake ${path.system}# &> /dev/null @@ -147,10 +147,10 @@ in echo "Processing Delta..." nvd diff /run/current-system result else - error "Couldn't build generation successfully" + rm -rf "$DIR" && error "Couldn't build generation successfully" fi popd &> /dev/null - rm -rf /tmp/build + rm -rf "$DIR" ;; "--test") echo "Testing Configuration..." diff --git a/scripts/packages.sh b/scripts/packages.sh @@ -1,5 +1,5 @@ #! /usr/bin/env nix -#! nix shell nixpkgs#{bash,coreutils,jq} -c bash +#! nix shell nixpkgs#bash nixpkgs#coreutils nixpkgs#jq -c bash # shellcheck shell=bash unset NIX_PATH set -euo pipefail diff --git a/scripts/partitions.sh b/scripts/partitions.sh @@ -1,5 +1,5 @@ #! /usr/bin/env nix -#! nix shell nixpkgs#{bash,dosfstools,ntfs3g,parted,util-linux,zfs} -c bash +#! nix shell nixpkgs#bash nixpkgs#dosfstools nixpkgs#ntfs3g nixpkgs#parted nixpkgs#util-linux nixpkgs#zfs -c bash # Script to automatically Create, Label, Format and Mount Partitions # diff --git a/scripts/pci.sh b/scripts/pci.sh @@ -1,5 +1,5 @@ #! /usr/bin/env nix -#! nix shell nixpkgs#{bash,coreutils} -c bash +#! nix shell nixpkgs#bash nixpkgs#coreutils -c bash # Shows PCI Devices mapped to IOMMU Groups # diff --git a/users/README.md b/users/README.md @@ -1,5 +1,5 @@ ### Users -The `users` directory contains the individual user-specific configurations for multiple users (of a single PC or multiple ones). To add a new user, simply create a configuration file for it (name of the file/directory must be the same as the `username` of the user) and write down the configuration using the `home-manager` module [options](https://mipmip.github.io/home-manager-option-search/). The configuration is automatically imported by `lib.build`, if present. Do not forget to create a `USERNAME.secret` file (using `nixos secret create`) in [`modules/user/passwords`](../modules/user/passwords/) containing the user password +The `users` directory contains the individual user-specific configurations for multiple users (of a single PC or multiple ones). To add a new user, simply create a configuration file for it (name of the file/directory must be the same as the `username` of the user) and write down the configuration using the `home-manager` module [options](https://mipmip.github.io/home-manager-option-search/). The configuration is automatically imported, if present. Do not forget to create a `USERNAME.secret` file (using `nixos secret create`) in [`modules/user/passwords`](../modules/user/passwords/) containing the user password There is also a `recovery` user defined in the system configuration as a [specialisation](https://nixos.wiki/wiki/Specialisation)