From 3d7738689420f8ba811466bcafeb7478373ed103 Mon Sep 17 00:00:00 2001 From: Swarsel Date: Wed, 11 Dec 2024 01:19:10 +0100 Subject: [PATCH] docs: increase verbosity --- SwarselSystems.org | 22 +++++-- index.html | 157 ++++++++++++++++++++++++++++----------------- 2 files changed, 116 insertions(+), 63 deletions(-) diff --git a/SwarselSystems.org b/SwarselSystems.org index cb99f27..796abf4 100644 --- a/SwarselSystems.org +++ b/SwarselSystems.org @@ -322,7 +322,9 @@ These settings are to be used only on full NixOS setups. Handling the flake.nix file used to be a bit of a chore, since it felt like writing so much boilerplate code just to define new systems. The noweb-approach here makes this a little bit less painful. -These blocks are later inserted here: [[#h:aee5ec75-7ca6-40d8-b6ac-a3e7e33a474b][flake.nix template]]. Adding new flake inputs is very easy, you just add them to [[#h:8a411ee2-a58e-4b5b-99bd-4ba772f8f0a2][Inputs & Inputs@Outputs]] first by name in the first source-block, and then the path in the second source-block. Any variables to be set for the host configuration are done in [[#h:df0072bc-853f-438f-bd85-bfc869501015][let]], and the specific setup is done in either [[#h:9c9b9e3b-8771-44fa-ba9e-5056ae809655][nixosConfigurations]] (for NixOS systems), [[#h:f881aa05-a670-48dd-a57b-2916abdcb692][homeConfigurations]] (for home-manager systems), or [[#h:5f6ef553-59f9-4239-b6f3-63d33b57f335][nixOnDroidConfigurations]] (for Nix on Android). There is also the [[#h:6a08495a-8566-4bb5-9fac-b03df01f6c81][nixos-generators]] section that currently just defines a Proxmox LXC image. +These blocks are later inserted here: [[#h:aee5ec75-7ca6-40d8-b6ac-a3e7e33a474b][flake.nix template]]. Adding new flake inputs is very easy, you just add them to [[#h:8a411ee2-a58e-4b5b-99bd-4ba772f8f0a2][Inputs & Inputs@Outputs]] first by name in the first source-block, and then the path in the second source-block. Any variables to be set for the host configuration are done in [[#h:df0072bc-853f-438f-bd85-bfc869501015][let]], and the specific setup is done in either [[#h:9c9b9e3b-8771-44fa-ba9e-5056ae809655][nixosConfigurations]] (for NixOS systems), [[#h:f881aa05-a670-48dd-a57b-2916abdcb692][homeConfigurations]] (for home-manager systems), or [[#h:5f6ef553-59f9-4239-b6f3-63d33b57f335][nixOnDroidConfigurations]] (for Nix on Android) and [[#h:f881aa05-a670-48dd-a57b-2916abdcb692][darwinConfigurations]] (for Darwin systems, also known as Macs). There also used to be a [[#h:6a08495a-8566-4bb5-9fac-b03df01f6c81][nixos-generators]] section that used to define a Proxmox LXC image when I was still using Proxmox as my main server. An example of the repository at that time would be =acc0ad6 main Add several NixOS hosts on Proxmox and Oracle Cloud=. + + ** flake.nix template :PROPERTIES: @@ -391,7 +393,7 @@ This sections puts together the =flake.nix= file from the [[#h:d39b8dfb-536d-414 :CUSTOM_ID: h:cbd5002c-e0fa-434a-951b-e05b179e4e3f :END: -This file defines a number of checks that can either be run by calling =nix flake check= or +This file defines a number of checks that can either be run by calling =nix flake check= or while in a =nix-shell= or =nix develop=. This helps me make sure that my flake confirms to my self-imposed standards. The GitHub actions perform less checks than are being done here (they are only checking the formatting, as well as =statix= and =deadnix=) #+begin_src nix :tangle checks/default.nix { self, inputs, pkgs, system, ... }: @@ -591,7 +593,14 @@ A short overview over each input and what it does: Here I define a few variables that I need for my system specifications. First and foremost, =pkgs=, which gets passed the emacs-overlay, nur, and nixgl modules to it. With this, I can grab all these packages by referencing =pkgs.= instead of having to put e.g. =nixgl.auto.nixGLDefault=. -Lastly I define some common module lists that I can simply load depending on the fundamental system (NixOS vs. non-NixOS). +I also define some common module lists that I can simply load depending on the fundamental system (NixOS vs. non-NixOS) - =nixModules=, =homeModules=, and =mixedModules=. + +The interesting part is in the start: +- first, I define =pkgsFor=. This function reads all available systems from nixpkgs and generates pkgs for them. +- next, =forEachSystem= is a function that can be called to declare an output for each such defined system. +- =forAllSystems= is a crude function that I use for expressions that depend on =system=, as the prior two attributes already consumed it at that stage. This is only really used to generate the checks in their own file. +- =mkFullHost= is a function that takes a hostname as well as a boolean whether it is NixOS or not, and returns a matching =nixosSystem= or =darwinSystem=. This function is only used for systems that can use both NixOS and home-manager options (darwin still counts here as it can use some NixOS options). +- =mkFullHostConfigs= is the function that dynamically creates all definded hosts. The hosts are defined by placing a directory in =hosts/= under either the =nixos/= or =darwin/= directory. These directories are being read by =readHosts= and delivered to this funtion in the later call in [[#h:9c9b9e3b-8771-44fa-ba9e-5056ae809655][nixosConfigurations]] or [[#h:f881aa05-a670-48dd-a57b-2916abdcb692][darwinConfigurations]]. #+begin_src nix :tangle no :noweb-ref flakelet @@ -667,12 +676,15 @@ In this section I am creating some attributes that define general concepts of my - =nixosModules= imports self-defined options that I only want to use on NixOS systems. All modules are held as separately as possible, to allow for easier sharing with other people mostly. - =homeManagerModules= imports modules that are to be used on NixOS and non-NixOS systems. These are mostly used to define outputs (monitors), keyboards and special commands for machines. - =packages= holds packages that I am building myself. These are mostly shell scripts, but also a few others such as AppImages and firefox addons. -- =devShells= provides a development shell that can be used as a bootstrap for new installs using =nix develop= while inside the flake directory. -- =formatter= provides the formatter that is to be used on =.nix= files. At the moment this is not used anywhere. +- =devShells= provides a development shell that can be used as a bootstrap for new installs using =nix develop= while inside the flake directory. It received an overhaul in =0a6cf0e feat: add checks to devShell=, since when it is handled using =forAllSystems= and now including pre-commit-hook checks. +- =formatter= provides the formatter that is to be used on =.nix= files. It can be called by using =nix fmt=. +- =check= provides the pre-commit-hook checks that I have explained in [[#h:cbd5002c-e0fa-434a-951b-e05b179e4e3f][Pre-commit-hooks (Checks)]]. - =overlays= imports a few community overlays (such as the emacs-overlay) and also three overlays of my own: 1) =additions= holds derivations that I am adding myself to nixpkgs - i.e. this is where the packages defined in =/pkgs= get added to nixpkgs. 2) =modifications= holds derivations that I have performed overrides on. The list of interesting attribute overrides can be found by looking at the source code of a derivation and looking at the start of the file for lines of the form = ? =. But this can also be used to, for example, fetch a different version of a package instead. 3) =nixpkgs-stable= holds the newest version of stable nixpkgs. I only use this on packages that seem broken on unstable, which are not many. + 4) =zjstatus= holds some options for =zellij=, but I have stopped using it since I prefer =tmux=. + They are defined in [[#h:5e3e21e0-57af-4dad-b32f-6400af9b7aab][Overlays (additions, overrides, nixpkgs-stable)]]. The way this is handled was simplified in =647a2ae feat: simplify overlay structure=; however, the old structure might be easier to understand as a reference. #+begin_src nix :tangle no :noweb-ref flakeoutputgeneral diff --git a/index.html b/index.html index b6aa47a..836a827 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + SwarselSystems: NixOS + Emacs Configuration @@ -353,7 +353,7 @@

-This file has 50438 words spanning 13199 lines and was last revised on 2024-12-11 00:05:08 +0100. +This file has 50861 words spanning 13228 lines and was last revised on 2024-12-11 01:25:11 +0100.

@@ -403,7 +403,7 @@ This section defines my Emacs configuration. For a while, I considered to use ry

-My emacs is built using the emacs-overlay nix flake, which builds a bleeding edge emacs on wayland (pgtk) with utilities like treesitter support. By executing the below source block, the current build setting can be updated at any time, and you can see my most up-to-date build options (last updated: 2024-12-11 00:05:08 +0100) +My emacs is built using the emacs-overlay nix flake, which builds a bleeding edge emacs on wayland (pgtk) with utilities like treesitter support. By executing the below source block, the current build setting can be updated at any time, and you can see my most up-to-date build options (last updated: 2024-12-11 01:25:11 +0100)

@@ -718,7 +718,7 @@ Handling the flake.nix file used to be a bit of a chore, since it felt like writ

-These blocks are later inserted here: flake.nix template. Adding new flake inputs is very easy, you just add them to Inputs & Inputs@Outputs first by name in the first source-block, and then the path in the second source-block. Any variables to be set for the host configuration are done in let, and the specific setup is done in either nixosConfigurations (for NixOS systems), homeConfigurations (for home-manager systems), or nixOnDroidConfigurations (for Nix on Android). There is also the [BROKEN LINK: h:6a08495a-8566-4bb5-9fac-b03df01f6c81] section that currently just defines a Proxmox LXC image. +These blocks are later inserted here: flake.nix template. Adding new flake inputs is very easy, you just add them to Inputs & Inputs@Outputs first by name in the first source-block, and then the path in the second source-block. Any variables to be set for the host configuration are done in let, and the specific setup is done in either nixosConfigurations (for NixOS systems), homeConfigurations (for home-manager systems), or nixOnDroidConfigurations (for Nix on Android) and darwinConfigurations (for Darwin systems, also known as Macs). There also used to be a [BROKEN LINK: h:6a08495a-8566-4bb5-9fac-b03df01f6c81] section that used to define a Proxmox LXC image when I was still using Proxmox as my main server. An example of the repository at that time would be acc0ad6 main Add several NixOS hosts on Proxmox and Oracle Cloud.

@@ -852,7 +852,6 @@ This sections puts together the flake.nix file from the flake.nix file from the flake.nix file from the flake.nix file from the 3.2. Pre-commit-hooks (Checks)

-This file defines a number of checks that can either be run by calling nix flake check or +This file defines a number of checks that can either be run by calling nix flake check or while in a nix-shell or nix develop. This helps me make sure that my flake confirms to my self-imposed standards. The GitHub actions perform less checks than are being done here (they are only checking the formatting, as well as statix and deadnix)

@@ -1218,21 +1222,25 @@ Here I define a few variables that I need for my system specifications. First an

-Lastly I define some common module lists that I can simply load depending on the fundamental system (NixOS vs. non-NixOS). +I also define some common module lists that I can simply load depending on the fundamental system (NixOS vs. non-NixOS) - nixModules, homeModules, and mixedModules.

+

+The interesting part is in the start: +

+
+
 inherit (self) outputs;
 lib = nixpkgs.lib // home-manager.lib;
 
-forEachSystem = f: lib.genAttrs (import systems) (system: f pkgsFor.${system});
-forAllSystems = lib.genAttrs [
-  "x86_64-linux"
-  "aarch64-linux"
-  "x86_64-darwin"
-  "aarch64-darwin"
-];
 pkgsFor = lib.genAttrs (import systems) (
   system:
   import nixpkgs {
@@ -1240,6 +1248,13 @@ pkgsFor = lib.genAttrs (import systems) (
     config.allowUnfree = true;
   }
 );
+forEachSystem = f: lib.genAttrs (import systems) (system: f pkgsFor.${system});
+forAllSystems = lib.genAttrs [
+  "x86_64-linux"
+  "aarch64-linux"
+  "x86_64-darwin"
+  "aarch64-darwin"
+];
 mkFullHost = host: isNixos: {
   ${host} =
     let
@@ -1299,14 +1314,21 @@ In this section I am creating some attributes that define general concepts of my
 
  • nixosModules imports self-defined options that I only want to use on NixOS systems. All modules are held as separately as possible, to allow for easier sharing with other people mostly.
  • homeManagerModules imports modules that are to be used on NixOS and non-NixOS systems. These are mostly used to define outputs (monitors), keyboards and special commands for machines.
  • packages holds packages that I am building myself. These are mostly shell scripts, but also a few others such as AppImages and firefox addons.
  • -
  • devShells provides a development shell that can be used as a bootstrap for new installs using nix develop while inside the flake directory.
  • -
  • formatter provides the formatter that is to be used on .nix files. At the moment this is not used anywhere.
  • -
  • overlays imports a few community overlays (such as the emacs-overlay) and also three overlays of my own: +
  • devShells provides a development shell that can be used as a bootstrap for new installs using nix develop while inside the flake directory. It received an overhaul in 0a6cf0e feat: add checks to devShell, since when it is handled using forAllSystems and now including pre-commit-hook checks.
  • +
  • formatter provides the formatter that is to be used on .nix files. It can be called by using nix fmt.
  • +
  • check provides the pre-commit-hook checks that I have explained in Pre-commit-hooks (Checks).
  • +
  • +overlays imports a few community overlays (such as the emacs-overlay) and also three overlays of my own: +

    1. additions holds derivations that I am adding myself to nixpkgs - i.e. this is where the packages defined in /pkgs get added to nixpkgs.
    2. modifications holds derivations that I have performed overrides on. The list of interesting attribute overrides can be found by looking at the source code of a derivation and looking at the start of the file for lines of the form <name> ? <val>. But this can also be used to, for example, fetch a different version of a package instead.
    3. nixpkgs-stable holds the newest version of stable nixpkgs. I only use this on packages that seem broken on unstable, which are not many.
    4. -
  • +
  • zjstatus holds some options for zellij, but I have stopped using it since I prefer tmux.
  • + +

    +They are defined in Overlays (additions, overrides, nixpkgs-stable). The way this is handled was simplified in 647a2ae feat: simplify overlay structure; however, the old structure might be easier to understand as a reference. +

    @@ -1319,16 +1341,29 @@ nixosModules = import ./modules/nixos; homeManagerModules = import ./modules/home; packages = forEachSystem (pkgs: import ./pkgs { inherit pkgs; }); -devShells = forEachSystem - (pkgs: +devShells = forAllSystems ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + checks = self.checks.${system}; + in { default = pkgs.mkShell { NIX_CONFIG = "experimental-features = nix-command flakes"; - nativeBuildInputs = [ pkgs.nix pkgs.home-manager pkgs.git ]; + inherit (checks.pre-commit-check) shellHook; + buildInputs = checks.pre-commit-check.enabledPackages; + nativeBuildInputs = [ + pkgs.nix + pkgs.home-manager + pkgs.git + pkgs.just + pkgs.age + pkgs.ssh-to-age + pkgs.sops + ]; }; }); -# this sets the formatter that is going to be used by nix fmt formatter = forEachSystem (pkgs: pkgs.nixpkgs-fmt); checks = forAllSystems ( system: @@ -1337,15 +1372,7 @@ checks = forAllSystems ( in import ./checks { inherit self inputs system pkgs; } ); -overlaysList = [ - (import ./overlays { inherit inputs; }).additions - (import ./overlays { inherit inputs; }).modifications - (import ./overlays { inherit inputs; }).nixpkgs-stable - (import ./overlays { inherit inputs; }).zjstatus - inputs.nur.overlays.default - inputs.emacs-overlay.overlay - inputs.nixgl.overlay -]; +overlays = import ./overlays { inherit inputs; };
    @@ -1538,7 +1565,7 @@ This is the "reference implementation" of a setup that runs without NixOS, only imports = builtins.attrValues outputs.homeManagerModules; nixpkgs = { - overlays = outputs.overlaysList; + overlays = [ outputs.overlays.default ]; config = { allowUnfree = true; }; @@ -1632,7 +1659,7 @@ in nixpkgs = { - overlays = outputs.overlaysList; + overlays = [ outputs.overlays.default ]; config = { allowUnfree = true; }; @@ -1851,13 +1878,12 @@ in nixpkgs = { - overlays = outputs.overlaysList; + overlays = [ outputs.overlays.default ]; config = { allowUnfree = true; }; }; - boot = { loader.systemd-boot.enable = true; loader.efi.canTouchEfiVariables = true; @@ -3020,7 +3046,9 @@ This file now holds all of the "nixpkgs-changes" that I am using across the conf
    -
    { inputs, ... }: {
    +
    { inputs, ... }:
    +
    +let
       additions = final: _prev: import ../pkgs { pkgs = final; };
       modifications = _: _prev: {
         vesktop = _prev.vesktop.override {
    @@ -3063,6 +3091,19 @@ This file now holds all of the "nixpkgs-changes" that I am using across the conf
         zjstatus = inputs.zjstatus.packages.${_prev.system}.default;
       };
     
    +in
    +{
    +  default =
    +    final: prev:
    +
    +    (additions final prev)
    +    // (modifications final prev)
    +    // (nixpkgs-stable final prev)
    +    // (zjstatus final prev)
    +    // (inputs.nur.overlays.default final prev)
    +    // (inputs.emacs-overlay.overlay final prev)
    +    // (inputs.nixgl.overlay final prev);
    +
     }
     
     
    @@ -7037,7 +7078,7 @@ in nix.settings.experimental-features = "nix-command flakes"; nixpkgs = { hostPlatform = "x86_64-darwin"; - overlays = outputs.overlaysList; + overlays = [ outputs.overlays.default ]; config = { allowUnfree = true; }; @@ -14542,7 +14583,7 @@ Prints a reasuring message to proove good faith."

    Author: Leon Schwarzäugl

    -

    Created: 2024-12-11 Mi 00:05

    +

    Created: 2024-12-11 Mi 01:25

    Validate