From 58c7d0403649c5f5362c1ea717fe40758a065f0d Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 24 Apr 2021 09:10:10 -0700 Subject: [PATCH] extract iso/hm config modules to lib.modules --- flake.lock | 2 +- lib/devos/devosSystem.nix | 76 ++------------------------------------- lib/modules.nix | 74 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 75 deletions(-) diff --git a/flake.lock b/flake.lock index a9e5e03..0f3b3eb 100644 --- a/flake.lock +++ b/flake.lock @@ -81,7 +81,7 @@ "utils": "utils_2" }, "locked": { - "narHash": "sha256-9mdO1eRrHz/3EAr3M8Ugdc8T6qWu4UbogafqO4mruKo=", + "narHash": "sha256-IvKVn4U3Ts2aw8JoKvBCte6Z77JynuNob8LClmsopFo=", "path": "./lib", "type": "path" }, diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index cc03a67..00c9e3e 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -6,91 +6,19 @@ lib.nixosSystem (args // { modules = let moduleList = builtins.attrValues modules; - modpath = "nixos/modules"; fullHostConfig = (lib.nixosSystem (args // { modules = moduleList; })).config; isoConfig = (lib.nixosSystem (args // { modules = moduleList ++ [ - - "${nixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" - - ({ config, suites, ... }: { - - # avoid unwanted systemd service startups - # all strings in disabledModules get appended to modulesPath - # so convert each to list which can be coerced to string - disabledModules = map lib.singleton suites.allProfiles; - - nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; - - isoImage.isoBaseName = "nixos-" + config.networking.hostName; - isoImage.contents = [{ - source = self; - target = "/devos/"; - }]; - isoImage.storeContents = [ - self.devShell.${config.nixpkgs.system} - # include also closures that are "switched off" by the - # above profile filter on the local config attribute - fullHostConfig.system.build.toplevel - ]; - # still pull in tools of deactivated profiles - environment.systemPackages = fullHostConfig.environment.systemPackages; - - # confilcts with networking.wireless which might be slightly - # more useful on a stick - networking.networkmanager.enable = lib.mkForce false; - # confilcts with networking.wireless - networking.wireless.iwd.enable = lib.mkForce false; - - # Set up a link-local boostrap network - # See also: https://github.com/NixOS/nixpkgs/issues/75515#issuecomment-571661659 - networking.usePredictableInterfaceNames = lib.mkForce true; # so prefix matching works - networking.useNetworkd = lib.mkForce true; - networking.useDHCP = lib.mkForce false; - networking.dhcpcd.enable = lib.mkForce false; - systemd.network = { - # https://www.freedesktop.org/software/systemd/man/systemd.network.html - networks."boostrap-link-local" = { - matchConfig = { - Name = "en* wl* ww*"; - }; - networkConfig = { - Description = "Link-local host bootstrap network"; - MulticastDNS = true; - LinkLocalAddressing = "ipv6"; - DHCP = "yes"; - }; - address = [ - # fall back well-known link-local for situations where MulticastDNS is not available - "fe80::47" # 47: n=14 i=9 x=24; n+i+x - ]; - extraConfig = '' - # Unique, yet stable. Based off the MAC address. - IPv6LinkLocalAddressGenerationMode = "eui64" - ''; - }; - }; - }) + (lib.modules.iso { inherit self nixos inputs fullHostConfig; }) ]; })).config; hmConfig = (lib.nixosSystem (args // { modules = moduleList ++ [ - ({ config, ... }: { - home-manager.useUserPackages = lib.mkForce false; - home-manager.sharedModules = [ - { - home.sessionVariables = { - inherit (config.environment.sessionVariables) NIX_PATH; - }; - xdg.configFile."nix/registry.json".text = - config.environment.etc."nix/registry.json".text; - } - ]; - }) + (lib.modules.hmConfig) ]; })).config; in diff --git a/lib/modules.nix b/lib/modules.nix index 1e5b8a8..7024f13 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -69,6 +69,80 @@ flakeModules = { self, extern }: { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; + isoConfig = { self, nixos, inputs, fullHostConfig }: + { config, suites, ... }: { + imports = let modpath = "nixos/modules"; in + [ "${nixos}/${modpath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ]; + # avoid unwanted systemd service startups + # all strings in disabledModules get appended to modulesPath + # so convert each to list which can be coerced to string + disabledModules = map lib.singleton suites.allProfiles; + + nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs; + + isoImage.isoBaseName = "nixos-" + config.networking.hostName; + isoImage.contents = [{ + source = self; + target = "/devos/"; + }]; + isoImage.storeContents = [ + self.devShell.${config.nixpkgs.system} + # include also closures that are "switched off" by the + # above profile filter on the local config attribute + fullHostConfig.system.build.toplevel + ]; + # still pull in tools of deactivated profiles + environment.systemPackages = fullHostConfig.environment.systemPackages; + + # confilcts with networking.wireless which might be slightly + # more useful on a stick + networking.networkmanager.enable = lib.mkForce false; + # confilcts with networking.wireless + networking.wireless.iwd.enable = lib.mkForce false; + + # Set up a link-local boostrap network + # See also: https://github.com/NixOS/nixpkgs/issues/75515#issuecomment-571661659 + networking.usePredictableInterfaceNames = lib.mkForce true; # so prefix matching works + networking.useNetworkd = lib.mkForce true; + networking.useDHCP = lib.mkForce false; + networking.dhcpcd.enable = lib.mkForce false; + systemd.network = { + # https://www.freedesktop.org/software/systemd/man/systemd.network.html + networks."boostrap-link-local" = { + matchConfig = { + Name = "en* wl* ww*"; + }; + networkConfig = { + Description = "Link-local host bootstrap network"; + MulticastDNS = true; + LinkLocalAddressing = "ipv6"; + DHCP = "yes"; + }; + address = [ + # fall back well-known link-local for situations where MulticastDNS is not available + "fe80::47" # 47: n=14 i=9 x=24; n+i+x + ]; + extraConfig = '' + # Unique, yet stable. Based off the MAC address. + IPv6LinkLocalAddressGenerationMode = "eui64" + ''; + }; + }; + }; + + hmConfig = + { config, ... }: { + home-manager.useUserPackages = lib.mkForce false; + home-manager.sharedModules = [ + { + home.sessionVariables = { + inherit (config.environment.sessionVariables) NIX_PATH; + }; + xdg.configFile."nix/registry.json".text = + config.environment.etc."nix/registry.json".text; + } + ]; + }; }