flake.nix (3336B)
1 { 2 inputs = { 3 nixpkgs = { 4 url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 5 }; 6 7 home-manager = { 8 url = "github:nix-community/home-manager"; 9 inputs.nixpkgs.follows = "nixpkgs"; 10 }; 11 12 nix-index-database = { 13 url = "github:nix-community/nix-index-database"; 14 inputs.nixpkgs.follows = "nixpkgs"; 15 }; 16 17 disko = { 18 url = "github:nix-community/disko"; 19 inputs.nixpkgs.follows = "nixpkgs"; 20 }; 21 22 ragenix = { 23 url = "github:yaxitech/ragenix"; 24 inputs.nixpkgs.follows = "nixpkgs"; 25 }; 26 27 corpus = { 28 url = "github:mtmn/corpus"; 29 inputs.nixpkgs.follows = "nixpkgs"; 30 }; 31 }; 32 33 outputs = { 34 self, 35 home-manager, 36 nixpkgs, 37 disko, 38 ... 39 } @ inputs: let 40 inherit (nixpkgs) lib; 41 configData = import ./hosts.nix; 42 defaultUsername = configData.defaultUser; 43 44 specialArgs = { 45 inherit inputs self configData; 46 }; 47 48 nixosConfigurations = lib.mapAttrs (hostName: host: let 49 hostDir = ./hosts/${hostName}; 50 username = host.username or defaultUsername; 51 in 52 lib.nixosSystem { 53 specialArgs = specialArgs // {inherit username;}; 54 modules = 55 [ 56 {nixpkgs.hostPlatform = host.system;} 57 inputs.ragenix.nixosModules.default 58 (hostDir + "/configuration.nix") 59 ] 60 ++ (lib.attrValues self.nixosModules) 61 ++ lib.optionals (host.disko or false) ( 62 [disko.nixosModules.disko] 63 ++ lib.optional (builtins.pathExists (hostDir + "/disk-config.nix")) (hostDir + "/disk-config.nix") 64 ); 65 }) 66 (lib.filterAttrs (_: host: host.nixos or false) configData.hosts); 67 68 homeConfigurations = lib.concatMapAttrs (userName: user: 69 lib.mapAttrs' (hostName: _: let 70 host = configData.hosts.${hostName}; 71 username = host.username or userName; 72 homeDirectory = 73 if lib.hasInfix "darwin" host.system 74 then "/Users/${username}" 75 else "/home/${username}"; 76 hostDir = host.hostDir or hostName; 77 in 78 lib.nameValuePair "${username}@${hostName}" ( 79 home-manager.lib.homeManagerConfiguration { 80 pkgs = nixpkgs.legacyPackages.${host.system}; 81 extraSpecialArgs = specialArgs // {inherit username homeDirectory;}; 82 modules = [ 83 ./home.nix 84 ./hosts/${hostDir} 85 ]; 86 } 87 )) 88 user.configs) 89 configData.users; 90 in { 91 inherit nixosConfigurations homeConfigurations configData; 92 93 nixosModules = 94 lib.mapAttrs' ( 95 filename: _: 96 lib.nameValuePair 97 (lib.removeSuffix ".nix" filename) 98 (import ./modules/services/${filename}) 99 ) (lib.filterAttrs ( 100 n: t: 101 (t == "regular" && lib.hasSuffix ".nix" n) 102 || (t == "directory" && builtins.pathExists ./modules/services/${n}/default.nix) 103 ) (builtins.readDir ./modules/services)) 104 // { 105 base = import ./modules/nixos/base.nix; 106 haravara = import ./lib/haravara.nix; 107 }; 108 109 devShells.x86_64-linux.default = let 110 pkgs = nixpkgs.legacyPackages.x86_64-linux; 111 in 112 pkgs.mkShell { 113 packages = [ 114 pkgs.nh 115 pkgs.dix 116 pkgs.nvd 117 pkgs.npins 118 ]; 119 }; 120 }; 121 }