diff --git a/hive.nix b/hive.nix index aee1fa0..73377fe 100644 --- a/hive.nix +++ b/hive.nix @@ -2,68 +2,57 @@ let mods = import ./modules; users = import ./users; sources = import ./npins; - inherit (import sources.nix-patches { patchFile = ./patches; }) mkNixpkgsSrc; + pkgs = import sources.nixpkgs-unstable { }; + inherit (pkgs) lib; + inherit (lib) + mapAttrs + mapAttrs' + removeSuffix + evalModules + ; - unstable = { - nixpkgs = mkNixpkgsSrc { - src = sources.nixpkgs-unstable; - version = "unstable"; - }; - home-manager = "${sources.home-manager-unstable}/nixos"; - nixvim = import sources.nixvim-unstable; - }; - stable = { - nixpkgs = mkNixpkgsSrc { - src = sources.nixpkgs-stable; - version = "stable"; - }; - home-manager = "${sources.home-manager-stable}/nixos"; - nixvim = import sources.nixvim-stable; - }; - inherit (import unstable.nixpkgs { }) lib; - - nodes = lib.mapAttrs' (name: _: { - name = lib.removeSuffix ".nix" name; + nodes = mapAttrs' (name: _: { + name = removeSuffix ".nix" name; value = import ./machines/${name}; }) (builtins.readDir ./machines); - nodes-meta = lib.mapAttrs (_: n: n.meta) nodes; + meta' = evalModules { + modules = [ + ./kat/meta.nix + { machines = mapAttrs (_: n: n.meta) nodes; } + ]; + specialArgs = { + inherit pkgs sources; + }; + }; + meta = meta'.config // { + machines = mapAttrs (_: node: node.node_meta) meta'.config.machines; + }; in { - meta = rec { - inherit (unstable) nixpkgs; + meta = { + nixpkgs = pkgs.path; specialArgs = { - inherit mods users sources; - meta = nodes-meta; - versions = { - inherit unstable stable; - }; + inherit + mods + users + sources + meta + ; + kat-path = ./kat; }; - nodeNixpkgs = lib.mapAttrs ( - _: node: - lib.foldl ( - pkgs: patch: - mkNixpkgsSrc { - src = pkgs; - version = patch; - } - ) (if node.unstable then unstable else stable).nixpkgs (node.nixPatches or [ ]) - ) nodes-meta; - nodeSpecialArgs = lib.mapAttrs (name: node: { - inherit (node) unstable; - self-version = (if node.unstable then unstable else stable) // { - nixpkgs = nodeNixpkgs.${name}; - }; - }) nodes-meta; + nodeNixpkgs = mapAttrs (_: node: node.nixpkgs-paths.nixpkgs-src) meta.machines; + nodeSpecialArgs = mapAttrs (_: node: { self-meta = node; }) meta.machines; }; defaults = { name, + kat-path, ... }: { - imports = [ ./kat ]; + imports = [ kat-path ]; networking.hostName = name; }; } -// lib.mapAttrs (_: n: n.config) nodes +// mapAttrs (_: n: n.config) nodes diff --git a/kat/default.nix b/kat/default.nix index 916fcbc..1b6360c 100644 --- a/kat/default.nix +++ b/kat/default.nix @@ -3,7 +3,7 @@ config, pkgs, sources, - self-version, + self-meta, ... }: with lib; @@ -12,7 +12,7 @@ with lib; ./users ./proxies ./root.nix - self-version.home-manager + self-meta.home-manager "${sources.disko}/module.nix" ]; options.kat = { @@ -34,7 +34,6 @@ with lib; (mkIf config.kat.addArgs { _module.args = { ssh-keys = import ./ssh-keys { inherit lib; }; - kat-path = ./.; }; }) { @@ -61,10 +60,11 @@ with lib; }; systemd.network.enable = true; + nixpkgs.overlays = map import self-meta.overlay-paths; nix = { nixPath = [ - "nixpkgs=${builtins.storePath pkgs.path}" - "nixos=${builtins.storePath pkgs.path}" + "nixpkgs=${self-meta.nixpkgs-paths.nixpkgs}" + "nixos=${self-meta.nixpkgs-paths.nixpkgs}" ]; channel.enable = false; settings.nix-path = config.nix.nixPath; diff --git a/kat/meta.nix b/kat/meta.nix new file mode 100644 index 0000000..6a8ccd7 --- /dev/null +++ b/kat/meta.nix @@ -0,0 +1,73 @@ +{ + lib, + sources, + pkgs, + ... +}: +let + inherit (lib) + mkOption + concatStringsSep + ; + inherit (lib.types) + attrsOf + listOf + submodule + enum + path + unspecified + ; + + machine_meta = + { config, ... }: + { + options = { + version = mkOption { + type = enum [ + "stable" + "unstable" + ]; + }; + patches = mkOption { + type = listOf path; + default = [ ]; + }; + overlay-paths = mkOption { + type = listOf path; + default = [ ]; + # /!\ Take care of imported files + }; + node_meta = mkOption { + type = unspecified; + readOnly = true; + }; + }; + config.node_meta = rec { + inherit (config) version; + patches = [ ./nginx-fallback.patch ] ++ config.patches; + overlay-paths = [ "${sources.kat-pkgs}/overlay.nix" ] ++ config.overlay-paths; + nixpkgs-paths = { + nixpkgs-src = pkgs.applyPatches { + src = sources."nixpkgs-${version}"; + name = "nixpkgs-${version}-patched"; + inherit patches; + }; + nixpkgs = pkgs.writeText "nixpkgs-entry.nix" '' + { overlays ? [ ], ... }@args: + import ${nixpkgs-paths.nixpkgs-src} (args // { + overlays = [ + ${concatStringsSep "\n " (map (p: "(import ${p})") overlay-paths)} + ] ++ overlays; + }) + ''; + }; + home-manager = "${sources."home-manager-${version}"}/nixos"; + nixvim = import sources."nixvim-${version}"; + }; + }; +in +{ + options.machines = mkOption { + type = attrsOf (submodule machine_meta); + }; +} diff --git a/patches/nginx-fallback.patch b/kat/nginx-fallback.patch similarity index 100% rename from patches/nginx-fallback.patch rename to kat/nginx-fallback.patch diff --git a/kat/users/default.nix b/kat/users/default.nix index 45ecfad..f471378 100644 --- a/kat/users/default.nix +++ b/kat/users/default.nix @@ -1,4 +1,4 @@ -{ config, pkgs, self-version, ... }: +{ config, pkgs, self-meta, ... }: let zsh = import ./zsh.nix; in @@ -9,7 +9,7 @@ in imports = [ zsh.user ./neovim.nix - self-version.nixvim.homeManagerModules.nixvim + self-meta.nixvim.homeManagerModules.nixvim ]; # options.kat = { # ssh = mkEnableOption "ssh configuration"; diff --git a/machines/kat-betamail/default.nix b/machines/kat-betamail/default.nix index 6b048bd..05d0435 100644 --- a/machines/kat-betamail/default.nix +++ b/machines/kat-betamail/default.nix @@ -1,7 +1,7 @@ { meta = { - unstable = false; - pkgsPatches = [ "betamail" ]; + version = "unstable"; + patches = [ ./procmail_322.patch ]; }; config = import ./configuration.nix; } diff --git a/patches/procmail_322.patch b/machines/kat-betamail/procmail_322.patch similarity index 100% rename from patches/procmail_322.patch rename to machines/kat-betamail/procmail_322.patch diff --git a/machines/kat-darknet/default.nix b/machines/kat-darknet/default.nix index 66da70b..b1eb7c1 100644 --- a/machines/kat-darknet/default.nix +++ b/machines/kat-darknet/default.nix @@ -1,4 +1,4 @@ { - meta.unstable = true; + meta.version = "unstable"; config = import ./configuration.nix; } diff --git a/machines/kat-degette/default.nix b/machines/kat-degette/default.nix index e3d020b..23dfccf 100644 --- a/machines/kat-degette/default.nix +++ b/machines/kat-degette/default.nix @@ -1,4 +1,4 @@ { - meta.unstable = false; + meta.version = "stable"; config = import ./configuration.nix; } diff --git a/machines/kat-iso.nix b/machines/kat-iso.nix index 56b9068..891511e 100644 --- a/machines/kat-iso.nix +++ b/machines/kat-iso.nix @@ -1,5 +1,5 @@ { - meta.unstable = true; + meta.version = "unstable"; config = { pkgs, diff --git a/machines/kat-kexec.nix b/machines/kat-kexec.nix index 8fe1ac6..b4c4ef8 100644 --- a/machines/kat-kexec.nix +++ b/machines/kat-kexec.nix @@ -1,5 +1,5 @@ { - meta.unstable = true; + meta.version = "unstable"; config = { pkgs, diff --git a/machines/kat-manah/default.nix b/machines/kat-manah/default.nix index 66da70b..b1eb7c1 100644 --- a/machines/kat-manah/default.nix +++ b/machines/kat-manah/default.nix @@ -1,4 +1,4 @@ { - meta.unstable = true; + meta.version = "unstable"; config = import ./configuration.nix; } diff --git a/machines/kat-orchid/configuration.nix b/machines/kat-orchid/configuration.nix index 3f67f22..554cf81 100644 --- a/machines/kat-orchid/configuration.nix +++ b/machines/kat-orchid/configuration.nix @@ -5,7 +5,7 @@ kat-path, ssh-keys, sources, - self-version, + self-meta, ... }: { @@ -137,7 +137,7 @@ localAddress = "192.168.123.2"; autoStart = true; specialArgs = { - inherit kat-path ssh-keys sources self-version; + inherit kat-path ssh-keys sources self-meta; }; config = { imports = [ kat-path ]; diff --git a/machines/kat-orchid/default.nix b/machines/kat-orchid/default.nix index e3d020b..23dfccf 100644 --- a/machines/kat-orchid/default.nix +++ b/machines/kat-orchid/default.nix @@ -1,4 +1,4 @@ { - meta.unstable = false; + meta.version = "stable"; config = import ./configuration.nix; } diff --git a/machines/kat-probook/default.nix b/machines/kat-probook/default.nix index 66da70b..b1eb7c1 100644 --- a/machines/kat-probook/default.nix +++ b/machines/kat-probook/default.nix @@ -1,4 +1,4 @@ { - meta.unstable = true; + meta.version = "unstable"; config = import ./configuration.nix; } diff --git a/machines/kat-son/default.nix b/machines/kat-son/default.nix index 66da70b..b1eb7c1 100644 --- a/machines/kat-son/default.nix +++ b/machines/kat-son/default.nix @@ -1,4 +1,4 @@ { - meta.unstable = true; + meta.version = "unstable"; config = import ./configuration.nix; } diff --git a/machines/kat-watcher/default.nix b/machines/kat-watcher/default.nix index 66da70b..b1eb7c1 100644 --- a/machines/kat-watcher/default.nix +++ b/machines/kat-watcher/default.nix @@ -1,4 +1,4 @@ { - meta.unstable = true; + meta.version = "unstable"; config = import ./configuration.nix; } diff --git a/machines/kat-www/default.nix b/machines/kat-www/default.nix index e3d020b..23dfccf 100644 --- a/machines/kat-www/default.nix +++ b/machines/kat-www/default.nix @@ -1,4 +1,4 @@ { - meta.unstable = false; + meta.version = "stable"; config = import ./configuration.nix; } diff --git a/npins/sources.json b/npins/sources.json index a74b970..ac44e3f 100644 --- a/npins/sources.json +++ b/npins/sources.json @@ -39,19 +39,16 @@ "url": "https://github.com/nix-community/home-manager/archive/65912bc6841cf420eb8c0a20e03df7cbbff5963f.tar.gz", "hash": "026hmc30kkyd9ihpjd6cm1b22galdi164ardhmj5x5jcszhjx4r9" }, - "nix-patches": { - "type": "GitRelease", + "kat-pkgs": { + "type": "Git", "repository": { "type": "Git", - "url": "https://git.hubrecht.ovh/hubrecht/nix-patches" + "url": "https://git.dgnum.eu/lbailly/kat-pkgs.git" }, - "pre_releases": false, - "version_upper_bound": null, - "release_prefix": null, - "version": "v0.5.0", - "revision": "e11ba20945f4a867f09d84343c37328288f274b4", + "branch": "master", + "revision": "6d804d5e17f7f6363fc300388b6cd6972810fc7c", "url": null, - "hash": "1c6cc44pwlg3ky6cnwhkml8ci77fw3sgjhwvqg0f6igxxf2fqv9v" + "hash": "1scfmdvm81b1ayi78k0kpg573vhxcvbzqvamzrs0g7xq5gv96imk" }, "nixos-images": { "type": "Git", diff --git a/patches/default.nix b/patches/default.nix deleted file mode 100644 index 68dd6fe..0000000 --- a/patches/default.nix +++ /dev/null @@ -1,18 +0,0 @@ -let - general = [ - { - _type = "static"; - path = ./nginx-fallback.patch; - } - ]; -in -{ - unstable = general; - stable = general; - betamail = [ - { - _type = "static"; - path = ./procmail_322.patch; - } - ]; -}