nix-config: 45b6d7b8b325c838773068c41fc9a0e26abb9893

     1: # Warbo's preferred setup, used across a bunch of systems. This part is specific
     2: # to NixOS; there is an equivalent module for Home Manager (which this module
     3: # can load for us too!)
     4: {
     5:   config,
     6:   lib,
     7:   pkgs,
     8:   ...
     9: }:
    10: with {
    11:   inherit (lib)
    12:     mkIf
    13:     mkMerge
    14:     mkOption
    15:     types
    16:     ;
    17:   cfg = config.warbo;
    18: };
    19: {
    20:   imports = [ (import "${import ../../home-manager/nixos-import.nix}/nixos") ];
    21: 
    22:   options.warbo =
    23:     with { common = import ../../warbo-options.nix { inherit lib pkgs; }; };
    24:     common
    25:     // {
    26:       home-manager = (common.home-manager or { }) // {
    27:         extras = mkOption {
    28:           default = { };
    29:           description = ''
    30:             Extra configuration for the user's home-manager setup.
    31:           '';
    32:         };
    33: 
    34:         username = mkOption {
    35:           type = types.nullOr types.str;
    36:           default = null;
    37:           description = ''
    38:             The username to enable Home Manager for (leave null to disable HM).
    39:           '';
    40:         };
    41:       };
    42:     };
    43: 
    44:   config = mkIf cfg.enable (mkMerge [
    45:     {
    46:       # Unconditional settings; override if desired
    47:       nix.settings.show-trace = true;
    48:       nixpkgs.config.allowUnfree = true;
    49: 
    50:       # Install packages system-wide. If Home Manager is being used then we'll
    51:       # also put these in the user's home.packages, but it's annoying to not
    52:       # have things available as root, to require a login shell for them, etc.
    53:       environment.systemPackages = cfg.packages;
    54: 
    55:       programs.fuse.userAllowOther = true;
    56:       programs.iotop.enable = true;
    57:       programs.screen.enable = true;
    58:     }
    59:     (mkIf (!cfg.wsl) {
    60:       # Trying this on NixOS in WSL will unload the Windows executable support
    61:       # from the kernel, affecting every other running container!
    62:       boot.binfmt = {
    63:         # See https://discourse.nixos.org/t/chroot-into-arm-container-with-systemd-nspawn/34735/9
    64:         emulatedSystems =
    65:           with builtins;
    66:           filter (s: s != currentSystem) [
    67:             "aarch64-linux" # Pinephone
    68:             "armv6l-linux" # RaspberryPi
    69:             "i686-linux" # Thinkpad
    70:             "riscv64-linux" # VisionFive
    71:             "x86_64-linux" # Laptops
    72:           ];
    73:         # https://github.com/felixonmars/archriscv-packages/blob/7c270ecef6a84edd6031b357b7bd1f6be2d6d838/devtools-riscv64/z-archriscv-qemu-riscv64.conf#L1
    74:         registrations."riscv64-linux" = {
    75:           preserveArgvZero = true;
    76:           matchCredentials = true;
    77:           fixBinary = true;
    78:         };
    79:       };
    80:     })
    81:     (mkIf (cfg.nixpkgs.path != null) {
    82:       nix.nixPath = [ "nixpkgs=${cfg.nixpkgs.path}" ];
    83:       nixpkgs.flake.source = cfg.nixpkgs.path;
    84:     })
    85:     (mkIf (cfg.nixpkgs.overlays != null) {
    86:       nixpkgs.overlays = cfg.nixpkgs.overlays (import ../../overlays.nix);
    87:     })
    88:     (mkIf (!cfg.professional) {
    89:       # Disable by setting 'warbo.professional'
    90:       programs.gnupg.agent.enable = true;
    91:       services.avahi = {
    92:         enable = true;
    93:         nssmdns4 = true;
    94:         publish.enable = true;
    95:         publish.addresses = true;
    96:         publish.workstation = true;
    97:       };
    98:     })
    99:     (mkIf cfg.direnv {
   100:       programs.direnv = {
   101:         enable = true;
   102:         loadInNixShell = true; # This option doesn't exist in Home Manager
   103:         nix-direnv.enable = true;
   104:       };
   105:     })
   106:     (mkIf (cfg.home-manager.username != null) {
   107:       home-manager.users."${cfg.home-manager.username}" =
   108:         { ... }:
   109:         cfg.home-manager.extras
   110:         // {
   111:           # Load our Home Manager equivalent
   112:           imports = [ (../../home-manager/modules/warbo.nix) ];
   113: 
   114:           # Pass along relevant config to our Home Manager module
   115:           warbo = {
   116:             inherit (cfg)
   117:               direnv
   118:               enable
   119:               nixpkgs
   120:               packages
   121:               professional
   122:               ;
   123:             is-nixos = true;
   124:             # Passing along username will cause an error, since our Home Manager
   125:             # module doesn't define that option
   126:             home-manager = builtins.removeAttrs cfg.home-manager [
   127:               "extras"
   128:               "username"
   129:             ];
   130:           };
   131:         };
   132:     })
   133:   ]);
   134: }

Generated by git2html.