My NixOS configuration.
at master 116 lines 3.4 kB view raw
1{inputs}: let 2 myLib = (import ./default.nix) {inherit inputs;}; 3 outputs = inputs.self.outputs; 4in rec { 5 # ================================================================ # 6 # = My Lib = # 7 # ================================================================ # 8 9 # ======================= Package Helpers ======================== # 10 11 pkgsFor = sys: inputs.nixpkgs.legacyPackages.${sys}; 12 13 # ========================== Buildables ========================== # 14 15 mkSystem = config: extraModules: 16 inputs.nixpkgs.lib.nixosSystem { 17 specialArgs = { 18 inherit inputs outputs myLib; 19 pkgs = import inputs.nixpkgs { 20 system = "x86_64-linux"; 21 config = { 22 allowUnfree = true; 23 allowUnfreePredicate = (_: true); 24 allowUnsupportedSystem = true; 25 }; 26 }; 27 }; 28 modules = [ 29 config 30 outputs.nixosModules.default 31 ] ++ extraModules; 32 }; 33 34 mkHome = sys: config: 35 inputs.home-manager.lib.homeManagerConfiguration { 36 pkgs = pkgsFor sys; 37 extraSpecialArgs = { 38 inherit inputs myLib outputs; 39 }; 40 modules = [ 41 inputs.stylix.homeManagerModules.stylix 42 { 43 nixpkgs.config.allowUnfree = true; 44 } 45 46 config 47 outputs.homeManagerModules.default 48 ]; 49 }; 50 51 # =========================== Helpers ============================ # 52 53 filesIn = dir: (map (fname: dir + "/${fname}") 54 (builtins.attrNames (builtins.readDir dir))); 55 56 dirsIn = dir: 57 inputs.nixpkgs.lib.filterAttrs (name: value: value == "directory") 58 (builtins.readDir dir); 59 60 fileNameOf = path: (builtins.head (builtins.split "\\." (baseNameOf path))); 61 62 # ========================== Extenders =========================== # 63 64 # Evaluates nixos/home-manager module and extends it's options / config 65 extendModule = {path, ...} @ args: {pkgs, ...} @ margs: let 66 eval = 67 if (builtins.isString path) || (builtins.isPath path) 68 then import path margs 69 else path margs; 70 evalNoImports = builtins.removeAttrs eval ["imports" "options"]; 71 72 extra = 73 if (builtins.hasAttr "extraOptions" args) || (builtins.hasAttr "extraConfig" args) 74 then [ 75 ({...}: { 76 options = args.extraOptions or {}; 77 config = args.extraConfig or {}; 78 }) 79 ] 80 else []; 81 in { 82 imports = 83 (eval.imports or []) 84 ++ extra; 85 86 options = 87 if builtins.hasAttr "optionsExtension" args 88 then (args.optionsExtension (eval.options or {})) 89 else (eval.options or {}); 90 91 config = 92 if builtins.hasAttr "configExtension" args 93 then (args.configExtension (eval.config or evalNoImports)) 94 else (eval.config or evalNoImports); 95 }; 96 97 # Applies extendModules to all modules 98 # modules can be defined in the same way 99 # as regular imports, or taken from "filesIn" 100 extendModules = extension: modules: 101 map 102 (f: let 103 name = fileNameOf f; 104 in (extendModule ((extension name) // {path = f;}))) 105 modules; 106 107 # ============================ Shell ============================= # 108 forAllSystems = pkgs: 109 inputs.nixpkgs.lib.genAttrs [ 110 "x86_64-linux" 111 "aarch64-linux" 112 "x86_64-darwin" 113 "aarch64-darwin" 114 ] 115 (system: pkgs inputs.nixpkgs.legacyPackages.${system}); 116}