1# tops and bottoms 2this document outlines things that i learned from various sources and some pure guesswork 3 4> To learn Nix is to learn to suffer, and to learn the way of numbing the pain 5— Cassie circa. 2023 6 7## overriding packages 8the pill confused me and i thought i had to make overlays to do overrides but no 9 10in packages (i.e. `environment.systemPackages`), just do 11```nix 12#-------8<-Snip------- 13environment = { 14 systemPackages = with pkgs; [ 15 (discord.override {withOpenASAR = true;}) 16 () 17 ]; 18}; 19#-------Snip->8------- 20``` 21 22This works as well 23```nix 24security.sudo.package = (pkgs.sudo.override {withInsults = true;}); 25``` 26 27## overlays 28overlays are useful when you want to refer to a package globally. 29 30the gist of overlays is as thus: 31 32> overlay is just `final: pref: {}` functions where dumbed down idea is 33> that you do pkg = prev.pkg.override and refer to everything else from 34> final 35> 36> idea is like final = prev // overlay(prev, final) 37> (it's a recursive definition) 38 39(poorly made) example overlays can be found [here](https://github.com/soopyc/nixos-config/blob/master/overlays/discord-canary.nix) 40 41currently in-use and slightly better overlays can be found in this repo! head over to /overlays to see them. 42 43*note: replace `self: super:` with `final: prev:` for consistency* 44 45*concept and content by \@natsukagami* 46 47## extra opts 48a way of passing additional options globally to modules is by using extraOpts. 49 50in nix flakes, this is accomplished by using `specialArgs` in `nixosSystem`. 51 52for example, check out this line in our flake.nix: 53 54https://github.com/soopyc/nix-on-koumakan/blob/492dfaa01808c2aa5dbb2d8223163e92bcef673b/flake.nix#L22-L28 55 56this avoids the horror of `import ../../../utils/bar.nix;` 57 58refer to [nixpkgs:nixos/lib/eval-config.nix] and [nixpkgs:lib/modules.nix#122] for more info 59 60*pointers by \@natsukagami* 61 62## @ (at) syntax 63very simple. 64 65```nix 66args@{a, b, c, ...}: { 67 # args.a and a are the same 68 some = "value"; 69} 70``` 71 72## nginx regex location 73```nix 74{ 75 locations."~ \.php$".extraConfig = '' 76 # balls 77 ''; 78} 79``` 80from [nixos wiki](https://nixos.wiki/wiki/Nginx#LEMP_stack) 81 82## adding a package with an overlay to a package set 83 84for package sets with a scope, you will have to do something like 85```nix 86final: prev: { 87 nimPackages = prev.nimPackages.overrideScope (final': prev': { 88 sha1 = final'.callPackage ./sha1.nix {}; 89 oauth = final'.callPackage ./oauth.nix {}; 90 }); 91} 92``` 93There's an alternative method that i used to use here: 94 95https://github.com/soopyc/nix-on-koumakan/blob/30e65402d22b000a3b5af6c9e5ea48a2b58a54e0/overlays/nim/oauth/default.nix 96 97however i do not think that's the best way lol 98 99# Common pitfalls 100## importing nixpkgs with an empty attrset 101 102ever had this in your flake.nix 103 104```nix 105{ 106 outputs = { nixpkgs, ... }@inputs: let 107 pkgs = import nixpkgs {}; 108 lib = nixpkgs.lib; 109 in { 110 # ... 111 }; 112} 113``` 114 115... and got fucked with this? 116```shell 117error: 118while checking flake output 'nixosConfigurations' 119 120 at /nix/store/lz2ra1180qfffmpwg41jpyg1z602qdgx-source/flake.nix:50:5: 121 122 49| in { 123 50| nixosConfigurations = { 124 | ^ 125 51| koumakan = (import ./systems/koumakan { inherit pkgs lib inputs; }); 126 127while checking the NixOS configuration 'nixosConfigurations.koumakan' 128 129 at /nix/store/lz2ra1180qfffmpwg41jpyg1z602qdgx-source/flake.nix:51:7: 130 131 50| nixosConfigurations = { 132 51| koumakan = (import ./systems/koumakan { inherit pkgs lib inputs; }); 133 | ^ 134 52| }; 135 136 (stack trace truncated; use '--show-trace' to show the full trace) 137 138 error: attribute 'currentSystem' missing 139 140 at /nix/store/5c0k827yjq7j24qaq8l2fcnsxp7nv8v1-source/pkgs/top-level/impure.nix:17:43: 141 142 16| # (build, in GNU Autotools parlance) platform. 143 17| localSystem ? { system = args.system or builtins.currentSystem; } 144 | ^ 145 18| 146``` 147 148just don't!!!11 remove the pkgs definition. (note that this only applies to `pkgs = import nixpkgs {};`) 149 150### explanation 151> you shouldn't ever really import nixpkgs with an empty attrset either 152> 153> that causes it to fall back on guessing your system using `builtins.currentSystem`, 154> which is impure and so not allowed in pure evaluation mode 155— \@getchoo 156## Useful links 157 158Builtin stdlib functions search engine: https://noogle.dev/ 159 160 161<!--links--> 162[nixpkgs:lib/modules.nix#122]: https://github.com/NixOS/nixpkgs/blob/6e68daefde56a7a8e6fe7c3ca9ceeb436294bb9f/lib/modules.nix#L122 163[nixpkgs:nixos/lib/eval-config.nix]: https://github.com/NixOS/nixpkgs/blob/5054472759a3b0df8e18cfe4031a5eff92d4cdc3/nixos/lib/eval-config.nix