diff options
| author | seth <[email protected]> | 2024-02-02 16:13:17 -0500 |
|---|---|---|
| committer | seth <[email protected]> | 2024-02-02 19:22:07 -0500 |
| commit | 1e32ab22f3fc2a4959f90ded95d7318bd4e23623 (patch) | |
| tree | a38ddb5f3fe720bc140f6a10cd41fd820adb4a5f | |
| parent | 9758b8236dcaafb958e6ef4f634d201af0bea80b (diff) | |
systems: use new configurations flakeModule
| -rw-r--r-- | configs.nix | 62 | ||||
| -rw-r--r-- | dev/ci.nix | 19 | ||||
| -rw-r--r-- | flake.nix | 37 | ||||
| -rw-r--r-- | modules/flake/configurations.nix | 211 | ||||
| -rw-r--r-- | modules/flake/default.nix | 5 | ||||
| -rw-r--r-- | systems/default.nix | 64 | ||||
| -rw-r--r-- | users/default.nix | 39 |
7 files changed, 304 insertions, 133 deletions
diff --git a/configs.nix b/configs.nix new file mode 100644 index 0000000..cdb9216 --- /dev/null +++ b/configs.nix @@ -0,0 +1,62 @@ +{ + withSystem, + inputs, + self, + ... +}: let + common = import ./systems/common.nix {inherit inputs self;}; +in { + imports = [ + ./systems/deploy.nix + ./modules/flake/configurations.nix + ]; + + configurations = { + home = { + builder = inputs.hm.lib.homeManagerConfiguration; + pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux; + + users = { + seth = {}; + }; + }; + + nixos = { + builder = inputs.nixpkgs.lib.nixosSystem; + + systems = { + glados = { + modules = common.personal; + }; + + glados-wsl = { + modules = common.personal; + }; + + atlas = { + builder = inputs.nixpkgs-stable.lib.nixosSystem; + system = "aarch64-linux"; + modules = common.server; + }; + }; + }; + + darwin = { + builder = inputs.darwin.lib.darwinSystem; + + systems = { + caroline = { + modules = common.darwin; + }; + }; + }; + }; + + flake.legacyPackages.x86_64-linux = withSystem "x86_64-linux" ({pkgs, ...}: { + openWrtImages = { + turret = pkgs.callPackage ./systems/turret { + inherit (inputs) openwrt-imagebuilder; + }; + }; + }); +} @@ -7,17 +7,14 @@ ciSystems = ["x86_64-linux"]; getOutputs = lib.getAttrs ciSystems; + mapCfgsToDerivs = lib.mapAttrs (_: cfg: cfg.activationPackage or cfg.config.system.build.toplevel); getCompatibleCfgs = lib.filterAttrs (_: cfg: lib.elem cfg.pkgs.system ciSystems); - in { - checks = getOutputs self.checks; - devShells = getOutputs self.devShells; - - homeConfigurations = let - legacyPackages = getOutputs self.legacyPackages; - in - lib.mapAttrs (_: v: mapCfgsToDerivs v.homeConfigurations) legacyPackages; - - nixosConfigurations = mapCfgsToDerivs (getCompatibleCfgs self.nixosConfigurations); - }; + getConfigurations = type: mapCfgsToDerivs (getCompatibleCfgs self."${type}Configurations"); + in + { + checks = getOutputs self.checks; + devShells = getOutputs self.devShells; + } + // lib.genAttrs ["nixos" "home"] getConfigurations; } @@ -6,6 +6,24 @@ extra-trusted-public-keys = ["getchoo.cachix.org-1:ftdbAUJVNaFonM0obRGgR5+nUmdLMM+AOvDOSx0z5tE="]; }; + outputs = {parts, ...} @ inputs: + parts.lib.mkFlake {inherit inputs;} { + imports = [ + ./configs.nix + ./dev + ./modules + ./overlay + ./terranix + ]; + + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + }; + inputs = { nixpkgs.url = "nixpkgs/nixos-unstable"; nixpkgs-stable.url = "nixpkgs/nixos-23.11"; @@ -132,23 +150,4 @@ }; }; }; - - outputs = {parts, ...} @ inputs: - parts.lib.mkFlake {inherit inputs;} { - imports = [ - ./dev - ./modules - ./overlay - ./systems - ./terranix - ./users - ]; - - systems = [ - "x86_64-linux" - "aarch64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; - }; } diff --git a/modules/flake/configurations.nix b/modules/flake/configurations.nix new file mode 100644 index 0000000..3d2d512 --- /dev/null +++ b/modules/flake/configurations.nix @@ -0,0 +1,211 @@ +{ + config, + lib, + withSystem, + inputs, + self, + ... +}: let + namespace = "configurations"; + cfg = config.${namespace}; + + inherit + (lib) + genAttrs + literalExpression + mapAttrs + mdDoc + mkOption + recursiveUpdate + types + ; + + builderType = types.functionTo pkgsType; + modulesType = types.listOf types.unspecified; + pkgsType = types.lazyAttrsOf types.raw; + + kernelFor = type: + { + nixos = "linux"; + darwin = "darwin"; + } + .${type}; + + builderStringFor = type: + { + nixos = "inputs.nixpkgs.lib.nixosSystem"; + darwin = "inputs.nix-darwin.lib.darwinSystem"; + } + .${type}; + + mkSystem = type: name: let + args = cfg.${type}.systems.${name}; + in + args.builder ( + (removeAttrs args ["builder"]) + // { + modules = args.modules ++ [../../systems/${name} {networking.hostName = name;}]; + specialArgs = { + inherit inputs self; + inputs' = withSystem args.system ({inputs', ...}: inputs'); + secretsDir = ../../secrets/${name}; + }; + } + ); + + mkUser = name: let + args = cfg.home.users.${name}; + in + args.builder (recursiveUpdate (removeAttrs args ["builder"]) { + inherit (args) pkgs; + + modules = + [ + ../../users/${name}/home.nix + + { + _module.args.osConfig = {}; + programs.home-manager.enable = true; + } + ] + ++ args.modules; + + extraSpecialArgs = { + inherit inputs self; + inputs' = withSystem args.pkgs.system ({inputs', ...}: inputs'); + }; + }); + + mapSystems = type: mapAttrs (name: _: mkSystem type name) cfg.${type}.systems; + mapUsers = mapAttrs (name: _: mkUser name) cfg.home.users; + + systemsSubmodule = type: { + options = { + builder = mkOption { + type = builderType; + default = cfg.${type}.builder; + example = literalExpression (builderStringFor type); + description = mdDoc '' + Function to build this ${type}Configuration with + ''; + }; + + modules = mkOption { + type = modulesType; + default = []; + example = literalExpression "[ self.${type}Modules.default ]"; + description = mdDoc '' + Extra modules to add to this ${type}Configuration + ''; + }; + + system = mkOption { + type = types.str; + default = "x86_64-${kernelFor type}"; + example = literalExpression "aarch64-${kernelFor type}"; + description = mdDoc '' + System to build this ${type}Configuration for + ''; + }; + }; + }; + + usersSubmodule = { + options = { + builder = mkOption { + type = builderType; + default = cfg.home.builder; + example = literalExpression "inputs.home-manager.lib.homeManagerConfiguration"; + description = mdDoc '' + Function to build this homeConfiguration with + ''; + }; + + modules = mkOption { + type = modulesType; + default = []; + example = literalExpression "[ self.hmModules.default ]"; + description = mdDoc '' + Extra modules to add to this homeConfiguration + ''; + }; + + pkgs = mkOption { + type = pkgsType; + default = cfg.home.pkgs; + example = literalExpression "inputs.nixpkgs.legacyPackages.aarch64-linux"; + description = mdDoc '' + Instance of nixpkgs to use in this homeConfiguration + ''; + }; + }; + }; + + mkSystemOptions = type: { + builder = mkOption { + type = builderType; + example = literalExpression (builderStringFor type); + description = mdDoc '' + Default function to build ${type}Configurations with + ''; + }; + + systems = mkOption { + type = types.attrsOf (types.submodule (systemsSubmodule type)); + default = {}; + example = literalExpression '' + { + foo = { + system = "aarch64-${kernelFor type}"; + }; + } + ''; + description = mdDoc '' + Attribute set of ${type}Configuration definitions + ''; + }; + }; +in { + options.${namespace} = + genAttrs ["nixos" "darwin"] mkSystemOptions + // { + home = { + builder = mkOption { + type = builderType; + example = literalExpression "inputs.home-manager.lib.homeManagerConfiguration"; + description = mdDoc '' + Default function to build homeConfigurations with + ''; + }; + + pkgs = mkOption { + type = pkgsType; + example = literalExpression "inputs.nixpkgs.legacyPackages.aarch64-linux"; + description = mdDoc '' + Default instance of nixpkgs to use in homeConfigurations + ''; + }; + + users = mkOption { + type = types.attrsOf (types.submodule usersSubmodule); + default = {}; + example = literalExpression '' + { + john = { + pkgs = inputs.nixpkgs.legacyPackages.aarch64-linux; + }; + } + ''; + description = mdDoc '' + Attribute set of homeConfiguration definitions + ''; + }; + }; + }; + + config.flake = { + nixosConfigurations = mapSystems "nixos"; + darwinConfigurations = mapSystems "darwin"; + homeConfigurations = mapUsers; + }; +} diff --git a/modules/flake/default.nix b/modules/flake/default.nix new file mode 100644 index 0000000..e86bee4 --- /dev/null +++ b/modules/flake/default.nix @@ -0,0 +1,5 @@ +{ + flake.flakeModules = { + configurations = import ./configurations.nix; + }; +} diff --git a/systems/default.nix b/systems/default.nix deleted file mode 100644 index ae37e1c..0000000 --- a/systems/default.nix +++ /dev/null @@ -1,64 +0,0 @@ -{ - lib, - withSystem, - inputs, - self, - ... -}: let - /* - basic nixosSystem/darwinSystem wrapper; can override - the exact builder by supplying an argument - */ - toSystem = builder: name: args: - (args.builder or builder) ( - (builtins.removeAttrs args ["builder"]) - // { - modules = args.modules ++ [./${name}]; - specialArgs = { - inherit inputs self; - inputs' = withSystem (args.system or "x86_64-linux") ({inputs', ...}: inputs'); - secretsDir = ../secrets/${name}; - }; - } - ); - - mapSystems = builder: lib.mapAttrs (toSystem builder); - - mapDarwin = mapSystems inputs.darwin.lib.darwinSystem; - mapNixOS = mapSystems inputs.nixpkgs.lib.nixosSystem; - common = import ./common.nix {inherit inputs self;}; -in { - imports = [./deploy.nix]; - - flake = { - darwinConfigurations = mapDarwin { - caroline = { - system = "x86_64-darwin"; - modules = common.darwin; - }; - }; - - nixosConfigurations = mapNixOS { - glados = { - system = "x86_64-linux"; - modules = common.personal; - }; - - glados-wsl = { - system = "x86_64-linux"; - modules = common.personal; - }; - - atlas = { - builder = inputs.nixpkgs-stable.lib.nixosSystem; - system = "aarch64-linux"; - modules = common.server; - }; - }; - - legacyPackages.x86_64-linux.turret = withSystem "x86_64-linux" ({pkgs, ...}: - pkgs.callPackage ./turret { - inherit (inputs) openwrt-imagebuilder; - }); - }; -} diff --git a/users/default.nix b/users/default.nix deleted file mode 100644 index 4f81fbb..0000000 --- a/users/default.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ - inputs, - self, - ... -}: { - perSystem = { - lib, - pkgs, - inputs', - ... - }: let - # basic homeManagerConfiguration wrapper with nice defaults - mkUser = name: args: - inputs.hm.lib.homeManagerConfiguration (lib.recursiveUpdate args { - pkgs = args.pkgs or pkgs; - - modules = - [ - ./${name}/home.nix - - { - _module.args.osConfig = {}; - programs.home-manager.enable = true; - } - ] - ++ (args.modules or []); - - extraSpecialArgs = { - inherit inputs inputs' self; - }; - }); - - mapUsers = lib.mapAttrs mkUser; - in { - legacyPackages.homeConfigurations = mapUsers { - seth = {}; - }; - }; -} |
