From 28ccf4f3f9f18d488c9ee67bc3878ddc0e7fcd05 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Mon, 25 Jan 2021 16:48:51 -0500 Subject: [PATCH 1/4] host: add deault implementation for system.build.isoImage target (per host) --- README.md | 5 ++--- hosts/default.nix | 34 +++++++++++++++++++++++++++++++++- hosts/niximg.nix | 13 ------------- shell/default.nix | 4 ++-- 4 files changed, 37 insertions(+), 19 deletions(-) delete mode 100644 hosts/niximg.nix diff --git a/README.md b/README.md index 46e74a6..7a06a82 100644 --- a/README.md +++ b/README.md @@ -170,10 +170,9 @@ nix build ./#homeConfigurations.NixOS.nixos.home.activationPackage ## Build an ISO -You can make an ISO and customize it by modifying the [niximg](./hosts/niximg.nix) -file: +You can make an ISO out of any config: ```sh -flk iso +flk iso yourConfig # build an iso for hosts/yourConfig.nix ``` ## Hardware Specific Profile for a Single Host diff --git a/hosts/default.nix b/hosts/default.nix index 52d2a59..55a197d 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -15,8 +15,40 @@ let unstableModules = [ ]; addToDisabledModules = [ ]; + libExt = lib.extend ( + final: prev: { + nixosSystemExtended = { modules, ... } @ args: + lib.nixosSystem (args // { + modules = + let + isoConfig = ( + import (nixos + "/nixos/lib/eval-config.nix") + ( + args // { + modules = modules ++ [ + (nixos + "/nixos/modules/installer/cd-dvd/installation-cd-minimal-new-kernel.nix") + ({ config, ... }: { + isoImage.isoBaseName = "nixos-" + config.networking.hostName; + }) + ]; + } + ) + ).config; + in + modules ++ [ + { + system.build = { + iso = isoConfig.system.build.isoImage; + }; + } + ]; + } + ); + } + ); + config = hostName: - lib.nixosSystem { + libExt.nixosSystemExtended { inherit system; specialArgs = diff --git a/hosts/niximg.nix b/hosts/niximg.nix deleted file mode 100644 index 823eeb6..0000000 --- a/hosts/niximg.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ unstableModulesPath, ... }: { - imports = [ - # passwd is nixos by default - ../users/nixos - # passwd is empty by default - ../users/root - "${unstableModulesPath}/installer/cd-dvd/iso-image.nix" - ]; - - isoImage.makeEfiBootable = true; - isoImage.makeUsbBootable = true; - networking.networkmanager.enable = true; -} diff --git a/shell/default.nix b/shell/default.nix index 038ca2d..f651115 100644 --- a/shell/default.nix +++ b/shell/default.nix @@ -12,7 +12,7 @@ let flk = pkgs.writeShellScriptBin "flk" '' if [[ -z "$1" ]]; then - echo "Usage: $(basename "$0") [ iso | up | install {host} | {host} [switch|boot|test] | home {host} {user} [switch] ]" + echo "Usage: $(basename "$0") [ up | iso {host} | install {host} | {host} [switch|boot|test] | home {host} {user} [switch] ]" elif [[ "$1" == "up" ]]; then mkdir -p $DEVSHELL_ROOT/up hostname=$(hostname) @@ -24,7 +24,7 @@ let git add -f $DEVSHELL_ROOT/up/$hostname git add -f $DEVSHELL_ROOT/hosts/up-$hostname.nix elif [[ "$1" == "iso" ]]; then - nix build $DEVSHELL_ROOT#nixosConfigurations.niximg.${build}.isoImage "${"\${@:2}"}" + nix build $DEVSHELL_ROOT#nixosConfigurations.$2.${build}.iso "${"\${@:3}"}" elif [[ "$1" == "install" ]]; then sudo nixos-install --flake "$DEVSHELL_ROOT#$2" "${"\${@:3}"}" elif [[ "$1" == "home" ]]; then From 33bcf093b7e5f0e913c444d9da10507978a5a1c7 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Mon, 25 Jan 2021 18:40:39 -0500 Subject: [PATCH 2/4] iso-cd: fix by overruling conflicting custom configuration --- hosts/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hosts/default.nix b/hosts/default.nix index 55a197d..8d6f060 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -29,6 +29,8 @@ let (nixos + "/nixos/modules/installer/cd-dvd/installation-cd-minimal-new-kernel.nix") ({ config, ... }: { isoImage.isoBaseName = "nixos-" + config.networking.hostName; + networking.networkmanager.enable = lib.mkForce false; # confilcts with networking.wireless which might be slightly more useful on a stick + networking.wireless.iwd.enable = lib.mkForce false; # confilcts with networking.wireless }) ]; } From 8cb82a307ff248b276da03687c6a9f29855839c2 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Wed, 27 Jan 2021 21:11:38 -0500 Subject: [PATCH 3/4] iso: move iso target to ./lib --- flake.nix | 1 + hosts/default.nix | 38 ++------------------------------------ lib/default.nix | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/flake.nix b/flake.nix index a5bdcb5..dc63d7e 100644 --- a/flake.nix +++ b/flake.nix @@ -62,6 +62,7 @@ lib = import ./lib { inherit (nixos) lib; + inherit nixos; }; templates.flk.path = ./.; diff --git a/hosts/default.nix b/hosts/default.nix index 8d6f060..addb3b2 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -9,48 +9,14 @@ , ... }: let - inherit (lib.flk) recImport; + inherit (lib.flk) recImport nixosSystemExtended; inherit (builtins) attrValues removeAttrs; unstableModules = [ ]; addToDisabledModules = [ ]; - libExt = lib.extend ( - final: prev: { - nixosSystemExtended = { modules, ... } @ args: - lib.nixosSystem (args // { - modules = - let - isoConfig = ( - import (nixos + "/nixos/lib/eval-config.nix") - ( - args // { - modules = modules ++ [ - (nixos + "/nixos/modules/installer/cd-dvd/installation-cd-minimal-new-kernel.nix") - ({ config, ... }: { - isoImage.isoBaseName = "nixos-" + config.networking.hostName; - networking.networkmanager.enable = lib.mkForce false; # confilcts with networking.wireless which might be slightly more useful on a stick - networking.wireless.iwd.enable = lib.mkForce false; # confilcts with networking.wireless - }) - ]; - } - ) - ).config; - in - modules ++ [ - { - system.build = { - iso = isoConfig.system.build.isoImage; - }; - } - ]; - } - ); - } - ); - config = hostName: - libExt.nixosSystemExtended { + nixosSystemExtended { inherit system; specialArgs = diff --git a/lib/default.nix b/lib/default.nix index f2f6a2b..86d0242 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,9 +1,9 @@ -{ lib, ... }: +{ lib, nixos, ... }: let inherit (builtins) attrNames attrValues isAttrs readDir listToAttrs mapAttrs; inherit (lib) fold filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix - recursiveUpdate genAttrs; + recursiveUpdate genAttrs nixosSystem; # mapFilterAttrs :: # (name -> value -> bool ) @@ -55,6 +55,39 @@ in nameValuePair ("") (null)) (readDir dir); + nixosSystemExtended = { modules, ... } @ args: + nixosSystem ( + args // { + modules = + let + isoConfig = ( + import (nixos + "/nixos/lib/eval-config.nix") + ( + args // { + modules = modules ++ [ + (nixos + "/nixos/modules/installer/cd-dvd/installation-cd-minimal-new-kernel.nix") + ( + { config, ... }: { + isoImage.isoBaseName = "nixos-" + config.networking.hostName; + networking.networkmanager.enable = lib.mkForce false; # confilcts with networking.wireless which might be slightly more useful on a stick + networking.wireless.iwd.enable = lib.mkForce false; # confilcts with networking.wireless + } + ) + ]; + } + ) + ).config; + in + modules ++ [ + { + system.build = { + iso = isoConfig.system.build.isoImage; + }; + } + ]; + } + ); + nixosModules = let # binary cache From 17621d6b14db1bf5d0e914f89f338be630cf92f9 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Mon, 1 Feb 2021 18:57:19 -0700 Subject: [PATCH 4/4] iso-cd: style cleanup (#2) --- flake.nix | 5 +--- lib/default.nix | 63 +++++++++++++++++++++++-------------------------- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/flake.nix b/flake.nix index dc63d7e..4eb5673 100644 --- a/flake.nix +++ b/flake.nix @@ -60,10 +60,7 @@ overlay = import ./pkgs; - lib = import ./lib { - inherit (nixos) lib; - inherit nixos; - }; + lib = import ./lib { inherit nixos; }; templates.flk.path = ./.; diff --git a/lib/default.nix b/lib/default.nix index 86d0242..b8890fb 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,9 +1,9 @@ -{ lib, nixos, ... }: +{ nixos, ... }: let inherit (builtins) attrNames attrValues isAttrs readDir listToAttrs mapAttrs; - inherit (lib) fold filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix - recursiveUpdate genAttrs nixosSystem; + inherit (nixos.lib) fold filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix + recursiveUpdate genAttrs nixosSystem mkForce; # mapFilterAttrs :: # (name -> value -> bool ) @@ -56,37 +56,32 @@ in (readDir dir); nixosSystemExtended = { modules, ... } @ args: - nixosSystem ( - args // { - modules = - let - isoConfig = ( - import (nixos + "/nixos/lib/eval-config.nix") - ( - args // { - modules = modules ++ [ - (nixos + "/nixos/modules/installer/cd-dvd/installation-cd-minimal-new-kernel.nix") - ( - { config, ... }: { - isoImage.isoBaseName = "nixos-" + config.networking.hostName; - networking.networkmanager.enable = lib.mkForce false; # confilcts with networking.wireless which might be slightly more useful on a stick - networking.wireless.iwd.enable = lib.mkForce false; # confilcts with networking.wireless - } - ) - ]; - } - ) - ).config; - in - modules ++ [ - { - system.build = { - iso = isoConfig.system.build.isoImage; - }; - } - ]; - } - ); + nixosSystem (args // { + modules = + let + modpath = "nixos/modules"; + cd = "installer/cd-dvd/installation-cd-minimal-new-kernel.nix"; + isoConfig = (nixosSystem + (args // { + modules = modules ++ [ + "${nixos}/${modpath}/${cd}" + ({ config, ... }: { + isoImage.isoBaseName = "nixos-" + config.networking.hostName; + # confilcts with networking.wireless which might be slightly + # more useful on a stick + networking.networkmanager.enable = mkForce false; + # confilcts with networking.wireless + networking.wireless.iwd.enable = mkForce false; + }) + ]; + })).config; + in + modules ++ [{ + system.build = { + iso = isoConfig.system.build.isoImage; + }; + }]; + }); nixosModules = let