dotfiles
My PC Dotfiles & Websitegit clone https://github.com/maydayv7/dotfiles
commit 17a9088b02481146f4258e9935241dbed9327a2b parent 9a9c8fe03a8d7301a091a945e89edbc6f9312911 Author: maydayv7 <maydayv7@gmail.com> Date: Thu, 30 Nov 2023 22:55:04 +0530 feat!: Update to Nix 2.19 + View package delta using `nvd` + Update Scripts
Diffstat:
| M | .github/workflows/build.yml | | | 2 | +- |
| M | .github/workflows/check.yml | | | 2 | +- |
| M | .github/workflows/release.yml | | | 2 | +- |
| M | .github/workflows/shell.yml | | | 2 | +- |
| M | .github/workflows/update.yml | | | 2 | +- |
| M | .github/workflows/website.yml | | | 2 | +- |
| M | .gitignore | | | 1 | - |
| M | README.md | | | 14 | ++++++++------ |
| M | files/flake.nix | | | 2 | +- |
| M | modules/base/default.nix | | | 14 | ++++---------- |
| M | modules/nix/default.nix | | | 2 | +- |
| M | modules/user/home.nix | | | 18 | +++++++++++++++--- |
| M | netlify.toml | | | 2 | +- |
| A | packages/overlays/nixFlakes.nix | | | 13 | +++++++++++++ |
| M | scripts/README.md | | | 2 | +- |
| M | scripts/colors.sh | | | 4 | ++-- |
| M | scripts/commands.sh | | | 4 | ++-- |
| M | scripts/mail.sh | | | 4 | ++-- |
| M | scripts/nixos.nix | | | 88 | +++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- |
| M | scripts/packages.sh | | | 4 | ++-- |
| M | scripts/partitions.sh | | | 4 | ++-- |
| M | scripts/pci.sh | | | 4 | ++-- |
| M | secrets/README.md | | | 2 | +- |
| R | secrets/.sops.yaml -> secrets/secrets.yaml | | | 0 | |
| M | users/default.nix | | | 2 | ++ |
25 files changed, 122 insertions(+), 74 deletions(-)
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml @@ -51,6 +51,6 @@ jobs: name: maydayv7-dotfiles authToken: "${{ secrets.CACHIX_TOKEN }}" - name: Fix Relative Flake Inputs - run: nix flake lock --update-input systems + run: nix flake update systems - name: Build Configuration run: nix build .#nixosConfigurations.${{ matrix.device }}.config.system.build.toplevel -L --show-trace diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml @@ -33,6 +33,6 @@ jobs: accept-flake-config = true access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} - name: Fix Relative Flake Inputs - run: nix flake lock --update-input systems + run: nix flake update systems - name: Check Syntax run: nix flake check . --keep-going diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml @@ -22,7 +22,7 @@ jobs: accept-flake-config = true access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} - name: Fix Relative Flake Inputs - run: nix flake lock --update-input systems + run: nix flake update systems - name: Build Default Install Media run: nix build .#installMedia.default.config.system.build.isoImage -L --show-trace - name: Draft Release diff --git a/.github/workflows/shell.yml b/.github/workflows/shell.yml @@ -30,6 +30,6 @@ jobs: name: maydayv7-dotfiles authToken: "${{ secrets.CACHIX_TOKEN }}" - name: Fix Relative Flake Inputs - run: nix flake lock --update-input systems + run: nix flake update systems - name: Check Shells run: nix develop .#${{ matrix.shell }} diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml @@ -23,7 +23,7 @@ jobs: accept-flake-config = true access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} - name: Fix Relative Flake Inputs - run: nix flake lock --update-input systems + run: nix flake update systems - name: Update Flake Lock File uses: DeterminateSystems/update-flake-lock@v20 with: diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml @@ -23,7 +23,7 @@ jobs: accept-flake-config = true access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} - name: Fix Relative Flake Inputs - run: nix flake lock --update-input systems + run: nix flake update systems - name: Build Zola Site run: nix build .#website - name: Deploy to GitHub Pages diff --git a/.gitignore b/.gitignore @@ -4,4 +4,3 @@ builds .direnv result *.wiki -.pre-commit-config.yaml diff --git a/README.md b/README.md @@ -197,7 +197,7 @@ In case you want to use my configuration as-is for a fresh NixOS install, you ca git init </code></pre> -3. Install `gnupg` and generate a GPG Key for yourself (if you don't already have one), and include it in the [`.sops.yaml`](./secrets/.sops.yaml) file (using `gpg --list-keys`). You can use the following commands to generate the GPG key (Ultimate trust and w/o passphrase is preferred): +3. Install `gnupg` and generate a GPG Key for yourself (if you don't already have one), and include it in the [`secrets.yaml`](./secrets/secrets.yaml) file (using `gpg --list-keys`). You can use the following commands to generate the GPG key (Ultimate trust and w/o passphrase is preferred): _Replace_ **_USER_** _,_ **_EMAIL_** _and_ **_COMMENT_** <pre><code>gpg --full-generate-key 1 4096 @@ -214,8 +214,8 @@ In case you want to use my configuration as-is for a fresh NixOS install, you ca 4. Import all required GPG Keys into a convenient location (like `/etc/gpg`) using <code>gpg --homedir <i>DIR</i> import</code> and specify it at `config.sops.gnupg.home` (Required for decryption of `secrets` on boot, can also be on an external drive) -5. Make new `secrets` and `passwords` in the desired directories by appending the paths to `.sops.yaml` and then using the following command (The [`nixos`](./scripts/README.md) script can be used to simplify the process): - _Replace_ **_PATH_** _with the path to the `secret`_ <pre><code>sops --config <i>/path/to/<b>.sops.yaml</b></i> -i <b><i>PATH</i></b></code></pre> +5. Make new `secrets` and `passwords` in the desired directories by appending the paths to `secrets.yaml` and then using the following command (The [`nixos`](./scripts/README.md) script can be used to simplify the process): + _Replace_ **_PATH_** _with the path to the `secret`_ <pre><code>sops --config <i>/path/to/<b>secrets.yaml</b></i> -i <b><i>PATH</i></b></code></pre> 6. Add device-specific configuration by creating a new file in [`devices`](./devices) (bear in mind that the name of the file must be same as the `HOSTNAME` of your device), and if required, hardware configuration using the `hardware.modules` option @@ -288,7 +288,7 @@ If you really want to get dirty with Nix and decide to invest oodles of your tim ### Caution -I am pretty new to Nix, and my configuration is still _WIP_ and uses Nix [Flakes](https://nixos.wiki/wiki/Flakes), an experimental feature (**Important:** Nix >= 2.7) +I am pretty new to Nix, and my configuration is still _WIP_ and uses Nix [Flakes](https://nixos.wiki/wiki/Flakes), an experimental feature (**Important:** Nix >= 2.19) It is not recommended to use NixOS if you are a beginner just starting out, without acquaintance with either the command-line or functional programming languages, since the learning curve is steep, debugging issues is difficult, documentation is shallow, and the effort required/time spent isn't worth the hassle for a novice/casual user @@ -415,11 +415,13 @@ 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` -- Fix Emoji Support - Support declarative [Flatpak](https://flatpak.org/) application install - Allow patching Default Package Channel -- Upgrade to GNOME 45 - 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 ### v13 diff --git a/files/flake.nix b/files/flake.nix @@ -75,7 +75,7 @@ scripts = map.files ../scripts build.script ".sh"; # 'sops' Encrypted Secrets - sops = ../secrets/.sops.yaml; + sops = ../secrets/secrets.yaml; # Document Templates templates = ./templates; diff --git a/modules/base/default.nix b/modules/base/default.nix @@ -8,16 +8,10 @@ ## Base Configuration ## config = { # Documentation - documentation.nixos.enable = false; - - # Rebuild Delta - system.activationScripts.diff = { - supportsDryActivation = true; - text = '' - if [[ -e /run/current-system ]]; then - ${pkgs.nix}/bin/nix store diff-closures /run/current-system "$systemConfig" - fi - ''; + environment. systemPackages = [pkgs.man-pages]; + documentation = { + dev.enable = true; + man.enable = true; }; }; } diff --git a/modules/nix/default.nix b/modules/nix/default.nix @@ -29,7 +29,7 @@ in { # Settings nix = { # Version - package = pkgs.nix; + package = pkgs.nixFlakes; # Garbage Collection settings.auto-optimise-store = true; diff --git a/modules/user/home.nix b/modules/user/home.nix @@ -1,4 +1,8 @@ -{config, ...}: { +{ + config, + pkgs, + ... +}: { ## User Home Configuration ## config = { # Environment Settings @@ -10,8 +14,16 @@ }; user.home = { - imports = [../../users]; - systemd.user.startServices = true; + imports = [ + ../../users + + # Package Delta + ({lib, ...}: { + home.activation.delta = lib.hm.dag.entryAnywhere '' + ${pkgs.nvd}/bin/nvd diff $oldGenPath $newGenPath + ''; + }) + ]; # Package Configuration home = { diff --git a/netlify.toml b/netlify.toml @@ -4,7 +4,7 @@ command = """ export NP_GIT=$(which git) wget -nv https://github.com/DavHau/nix-portable/releases/latest/download/nix-portable chmod +x nix-portable -./nix-portable nix flake lock --update-input systems +./nix-portable nix flake update systems ./nix-portable nix build --impure --expr "with import ./.; callPackage ./site { site = ${DEPLOY_PRIME_URL}; }" ./nix-portable nix shell nixpkgs#bash -c "bash" -c "cp -rL result build" """ diff --git a/packages/overlays/nixFlakes.nix b/packages/overlays/nixFlakes.nix @@ -0,0 +1,13 @@ +final: prev: { + # Update Nix to latest version + nixFlakes = prev.nixFlakes.overrideAttrs (old: rec { + version = "2.19.1"; + src = prev.fetchFromGitHub { + owner = "NixOS"; + repo = "nix"; + rev = version; + hash = "sha256-OzAeQwlAF4l0h2uBWGIPvGBYNL6MpBfrdRKwHTRQXl4="; + }; + patches = old.patches or []; + }); +} diff --git a/scripts/README.md b/scripts/README.md @@ -26,5 +26,5 @@ $ nixos -h search 'term' [ 'source' ] - Searches for Packages [ Providing 'term' ] or Configuration Options secret 'choice' [ 'path' ] - Manages 'sops' Encrypted Secrets shell [ 'name' ] - Opens desired Nix Developer Shell - update [ 'repository' ['rev'] ] - Updates System Repositories + update [ 'repo' / --'option' ] - Manages System Package Updates ``` diff --git a/scripts/colors.sh b/scripts/colors.sh @@ -1,5 +1,5 @@ -#! /usr/bin/env nix-shell -#! nix-shell -i bash +#! /usr/bin/env nix +#! nix shell nixpkgs#bash -c bash # Print Color Map # diff --git a/scripts/commands.sh b/scripts/commands.sh @@ -1,5 +1,5 @@ -#! /usr/bin/env nix-shell -#! nix-shell -i bash -p bzip2 coreutils git gnupg gnutar gzip p7zip unzip +#! /usr/bin/env nix +#! nix shell nixpkgs#{bash,bzip2,coreutils,git,gnupg,gnutar,gzip,p7zip,unzip} -c bash # Useful Commands # diff --git a/scripts/mail.sh b/scripts/mail.sh @@ -1,5 +1,5 @@ -#! /usr/bin/env nix-shell -#! nix-shell -i bash -p coreutils gnused libpst +#! /usr/bin/env nix +#! nix shell nixpkgs#{bash,coreutils,gnused,libpst} -c bash # Script to convert '.pst' Files to '.mbox' # diff --git a/scripts/nixos.nix b/scripts/nixos.nix @@ -39,32 +39,40 @@ with files; let search 'term' [ 'source' ] - Searches for Packages [ Providing 'term' ] or Configuration Options secret 'choice' [ 'path' ] - Manages 'sops' Encrypted Secrets shell [ 'name' ] - Opens desired Nix Developer Shell - update [ 'repository' ['rev'] ] - Updates System Repositories + update [ 'repo' / --'option' ] - Manages System Package Updates ''; apply = '' # Usage # - --activate - Activates Current Configuration - --boot - Applies Configuration on boot - --check - Checks Configuration Build - --rollback [ 'generation' ] - Reverts to Last [ or Specified ] Build Generation - --test - Tests Configuration Build + --activate - Activates Current Configuration + --boot - Applies Configuration on boot + --check - Checks Configuration Build + --delta - Shows Package Delta for Build + --rollback [ 'generation' ] - Reverts to Last [ or Specified ] Build Generation + --test - Tests Configuration Build ''; search = '' # Usage # - cmd.'command' - Searches for Package providing 'command' - pkgs.'package' [ 'repo' ] - Searches for Package 'package' [ In Repository ] - 'term' - Searches for Packages and Configuration Options and matching 'term' + cmd.'command' - Searches for Package providing 'command' + pkgs.'package' [ 'repo' ] - Searches for Package 'package' [ In Repository ] + 'term' - Searches for Packages and Configuration Options and matching 'term' ''; secret = '' # Usage # - create 'path' - Creates desired Secret - edit 'name' - Edits desired Secret - list - Lists all 'sops' Encrypted Secrets - show 'name' - Shows desired Secret - update - Updates Secrets to defined Keys + create 'path' - Creates desired Secret + edit 'name' - Edits desired Secret + list - Lists all 'sops' Encrypted Secrets + show 'name' - Shows desired Secret + update - Updates Secrets to defined Keys + ''; + + update = '' + # Usage # + --pkgs - Automatically updates manually packaged apps + --commit - Updates 'inputs' and commits changes + 'repo' ['source'] - Updates 'repo' input [ To specified 'source' ] ''; }; in @@ -88,6 +96,7 @@ in jq manix nixFlakes + nvd parted sops tree @@ -110,6 +119,7 @@ in help|--help|-h) echo -e "## Tool for NixOS System Management ##\n${usage.script}";; apply) case $2 in + help|--help|-h) echo "${usage.apply}";; "") echo "Applying Configuration..." sudo nixos-rebuild switch --flake ${path.system}# @@ -127,12 +137,26 @@ in echo "Checking Configuration..." nixos-rebuild dry-activate --flake ${path.system}# ;; + "--delta") + rm -rf /tmp/build && mkdir /tmp/build + pushd /tmp/build &> /dev/null + echo "Building Configuration..." + info "This may take a while..." + if nixos-rebuild build --flake ${path.system}# &> /dev/null + then + echo "Processing Delta..." + nvd diff /run/current-system result + else + error "Couldn't build generation successfully" + fi + popd &> /dev/null + rm -rf /tmp/build + ;; "--test") echo "Testing Configuration..." sudo nixos-rebuild test --no-build-nix --show-trace --flake ${path.system}# ;; "--rollback") - profile="/nix/var/nix/profiles/system" case $3 in "") echo "Applying Rollback..." @@ -144,7 +168,7 @@ in ;; *) echo "Rolling Back to Generation '$3'..." - sudo nix-env --switch-generation "$3" -p "$profile" && nixos apply --activate + sudo nix-env --switch-generation "$3" -p "/nix/var/nix/profiles/system" && nixos apply --activate ;; esac ;; @@ -163,7 +187,7 @@ in ;; check) echo "Formatting Code..." - pushd ${path.system} > /dev/null; nix fmt; popd > /dev/null + pushd ${path.system} &> /dev/null; nix fmt; popd &> /dev/null case $2 in "") nix flake check ${path.system} --keep-going;; "--trace") nix flake check ${path.system} --keep-going --show-trace;; @@ -215,7 +239,7 @@ in read -rp "Do you want to Automatically Create the Partitions? (Y/N): " choice case $choice in [Yy]*) warn "Assuming Disk is Completely Empty"; partition_disk;; - *) warn "You must Create, Format and Label the Partitions on your own"; gparted > /dev/null;; + *) warn "You must Create, Format and Label the Partitions on your own"; gparted &> /dev/null;; esac newline read -rp "Select Filesystem to use for Disk (simple/advanced): " choice @@ -366,7 +390,7 @@ in ;; save) echo "Saving Changes..." - pushd ${path.system} > /dev/null + pushd ${path.system} &> /dev/null git stash git pull --rebase git branch save @@ -375,7 +399,7 @@ in git add . git commit git push --set-upstream origin save --force - popd > /dev/null + popd &> /dev/null ;; search) case $2 in @@ -460,27 +484,29 @@ in ;; update) case $2 in - "") - echo "Updating Flake Inputs..." - nix flake update ${path.system} + help|--help|-h) echo "${usage.update}";; + "--pkgs") + echo "Updating Packages..." + pushd ${path.system}/packages &> /dev/null + bash ${./packages.sh} + popd &> /dev/null ;; "--commit") echo "Updating Flake Inputs..." - nix flake update ${path.system} --commit-lock-file + nix flake update --flake ${path.system} --commit-lock-file ;; - "--pkgs") - echo "Updating Packages..." - pushd ${path.system}/packages > /dev/null - bash ${./packages.sh} - popd > /dev/null + "") + echo "Updating Flake Inputs..." + nix flake update --flake ${path.system} ;; *) echo "Updating Flake Input '$2'..." if [ -z "$3" ] then - nix flake lock ${path.system} --update-input "$2" + nix flake update --flake ${path.system} "$2" else - nix flake lock ${path.system} --override-input "$2" "$3" + + nix flake update --flake ${path.system} "$2" --override-input "$2" "$3" fi ;; esac diff --git a/scripts/packages.sh b/scripts/packages.sh @@ -1,5 +1,5 @@ -#! /usr/bin/env nix-shell -#! nix-shell -i bash -p coreutils jq +#! /usr/bin/env nix +#! nix shell nixpkgs#{bash,coreutils,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-shell -#! nix-shell -i bash -p dosfstools ntfs3g parted util-linux zfs +#! /usr/bin/env nix +#! nix shell nixpkgs#{bash,dosfstools,ntfs3g,parted,util-linux,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-shell -#! nix-shell -i bash -p coreutils +#! /usr/bin/env nix +#! nix shell nixpkgs#{bash,coreutils} -c bash # Shows PCI Devices mapped to IOMMU Groups # diff --git a/secrets/README.md b/secrets/README.md @@ -2,4 +2,4 @@ The authentication credentials are managed using [`sops-nix`](https://github.com/Mic92/sops-nix) at `secrets`. The [`sops`](https://github.com/mozilla/sops) encrypted secrets (using GPG authentication) are stored at multiple places, like in this directory, as well as [`modules/user/passwords`](../modules/user/passwords). User passwords are made using the command `mkpasswd -m sha-512` and specified using the `hashedPasswordFile` option. The `sops` encrypted secrets are of `binary` format (and have the extension `.secret`) and can be conveniently managed using the [`nixos`](../scripts/README.md) `secret` command. The `keys` directory contains the _public_ User GPG Keys which are automatically imported -To create a secret, use the `nixos secret create` command, and append the directory along with requisite access permissions to the `.sops.yaml` file +To create a secret, use the `nixos secret create` command, and append the directory along with requisite access permissions to the `secrets.yaml` file diff --git a/secrets/.sops.yaml b/secrets/secrets.yaml diff --git a/users/default.nix b/users/default.nix @@ -38,6 +38,8 @@ in { ## Home Configuration ## config = { + systemd.user.startServices = true; + # GPG Settings programs.gpg = { settings = mkIf (cfg.key != "") {