From e038c2dd15be40937f24892583bde168fd6c90b4 Mon Sep 17 00:00:00 2001 From: Erwin Boskma Date: Sat, 14 Oct 2023 16:55:13 +0200 Subject: [PATCH] Initial refactoring --- flake.nix | 81 +++++++++++++++---------------------------------- lib/default.nix | 52 +++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 57 deletions(-) create mode 100644 lib/default.nix diff --git a/flake.nix b/flake.nix index 8696876..092200e 100644 --- a/flake.nix +++ b/flake.nix @@ -130,68 +130,12 @@ outputs = { self , sops - , ha-now-playing - , pamedia , nixinate , flake-parts , ... } @ inputs: with inputs; let machines = import ./machines inputs; - defSystem = system: baseConfig: deployConfig: - nixpkgs.lib.nixosSystem { - system = "${system}"; - modules = [ - { _module.args.inputs = inputs; } - { _module.args.self-overlay = self.overlays.default; } - - ({ ... }: { - imports = - builtins.attrValues self.nixosModules - ++ [ - { - nix.nixPath = [ "nixpkgs=${nixpkgs}" ]; - nixpkgs = - { - overlays = [ - self.overlays.default - ha-now-playing.overlays.${system} - pamedia.overlays.${system} - emacs-overlay.overlay - nil.overlays.default - inputs.eww.overlays.default - inputs.rust-overlay.overlays.default - ] ++ nixpkgs.lib.optional (system == "aarch64-linux") - (_final: super: { - makeModulesClosure = x: - super.makeModulesClosure (x // { allowMissing = true; }); - }); - - config = { - allowUnfree = true; - firefox.speechSynthesisSupport = true; - }; - }; - } - - baseConfig - home-manager.nixosModules.home-manager - { - home-manager = { - useUserPackages = true; - useGlobalPkgs = true; - }; - } - ]; - - system.configurationRevision = nixpkgs.lib.mkIf (self ? rev) self.rev; - nix.registry.nixpkgs.flake = nixpkgs; - }) - sops.nixosModules.sops - sunshine.nixosModules.sunshine - ] ++ (nixpkgs.lib.optional (deployConfig != null) { _module.args.nixinate = deployConfig; }) - ; - }; in flake-parts.lib.mkFlake { inherit inputs; } { @@ -201,6 +145,7 @@ ]; flake = { + lib = import ./lib inputs; overlays.default = import ./overlays; @@ -214,7 +159,7 @@ nixosConfigurations = builtins.listToAttrs (map (machine: { name = machine; - value = defSystem (machines.${machine}.system or "x86_64-linux") + value = self.lib.defSystem (machines.${machine}.system or "x86_64-linux") { imports = [ machines.${machine}.config @@ -226,6 +171,28 @@ apps = nixinate.nixinate.x86_64-linux self; + colmena = { + meta = { + nixpkgs = import nixpkgs { system = "x86_64-linux"; }; + + specialArgs = { + inherit nixpkgs; + }; + }; + drone = { lib, ... }: { + deployment = { + targetHost = "10.0.0.202"; + targetUser = "root"; + }; + imports = + let + system = "x86_64-linux"; + systemConfig = import ./machines/drone/configuration.nix inputs; + in + self.lib.systemModules system systemConfig; + }; + }; + }; perSystem = { self', pkgs, system, lib, ... }: diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..f86cb8d --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,52 @@ +{ self, nixpkgs, ... }@inputs: +rec { + defSystem = system: systemConfig: deployConfig: + nixpkgs.lib.nixosSystem { + system = "${system}"; + modules = (systemModules system systemConfig) ++ (nixpkgs.lib.optional (deployConfig != null) { _module.args.nixinate = deployConfig; }); + }; + + systemModules = system: systemConfig: + builtins.attrValues self.nixosModules ++ [ + { _module.args.inputs = inputs; } + { _module.args.self-overlay = self.overlays.default; } + + { + nix.nixPath = [ "nixpkgs=${nixpkgs}" ]; + nixpkgs = + { + overlays = [ + self.overlays.default + inputs.ha-now-playing.overlays.${system} + inputs.pamedia.overlays.${system} + inputs.emacs-overlay.overlay + inputs.nil.overlays.default + inputs.eww.overlays.default + inputs.rust-overlay.overlays.default + ] ++ nixpkgs.lib.optional (system == "aarch64-linux") + (_final: super: { + makeModulesClosure = x: + super.makeModulesClosure (x // { allowMissing = true; }); + }); + + config = { + allowUnfree = true; + firefox.speechSynthesisSupport = true; + }; + }; + home-manager = { + useUserPackages = true; + useGlobalPkgs = true; + }; + system.configurationRevision = nixpkgs.lib.mkIf (self ? rev) self.rev; + nix.registry.nixpkgs.flake = nixpkgs; + } + + systemConfig + inputs.home-manager.nixosModules.home-manager + + inputs.sops.nixosModules.sops + inputs.sunshine.nixosModules.sunshine + + ]; +}