diff --git a/example/install.sh.md b/example/install.sh.md index 442cb22..7a494db 100644 --- a/example/install.sh.md +++ b/example/install.sh.md @@ -12,5 +12,5 @@ This is a minimal example for a NixOS system installation function using the fun function install-system {( set -eu # 1: blockDev prepare-installer "$@" do-disk-setup "$1" - install-system-to $mnt prompt=true @{config.th.minify.topLevel:-} + install-system-to $mnt prompt=true )} diff --git a/hosts/example.nix.md b/hosts/example.nix.md index 834d901..88b9ebd 100644 --- a/hosts/example.nix.md +++ b/hosts/example.nix.md @@ -49,11 +49,7 @@ in { imports = [ ({ ## Hardware fileSystems."/nix/store" = { options = ["bind,ro"]; device = "/system/nix/store"; neededForBoot = true; }; # Some base config: - users.mutableUsers = false; users.allowNoPasswordLogin = true; - networking.hostId = lib.mkDefault (builtins.substring 0 8 (builtins.hashString "sha256" config.networking.hostName)); - environment.etc."machine-id".text = (builtins.substring 0 32 (builtins.hashString "sha256" "${config.networking.hostName}:machine-id")); - boot.kernelParams = [ "panic=10" "boot.panic_on_fail" ]; # Reboot on kernel panic, panic if boot fails. - systemd.extraConfig = "StatusUnitFormat=name"; # Show unit names instead of descriptions during boot. + wip.base.enable = true; wip.base.includeNixpkgs = inputs.nixpkgs; # Static config for VBox Adapter 1 set to NAT (the default): networking.interfaces.enp0s3.ipv4.addresses = [ { diff --git a/lib/flakes.nix b/lib/flakes.nix index 8ce0d86..2605676 100644 --- a/lib/flakes.nix +++ b/lib/flakes.nix @@ -82,9 +82,11 @@ in rec { networking.hostName = name; - system.extraSystemBuilderCmds = if !config.boot.initrd.enable then "" else '' + system.extraSystemBuilderCmds = (if !config.boot.initrd.enable then "" else '' ln -sT ${builtins.unsafeDiscardStringContext config.system.build.bootStage1} $out/boot-stage-1.sh # (this is super annoying to locate otherwise) - ''; + '') + (if !inputs?self then "" else '' + ln -sT ${inputs.self.outPath} $out/config # (build input for reference) + ''); }) ]; specialArgs = specialArgs; # explicitly passing »pkgs« here breaks »config.nixpkgs.overlays«! @@ -145,7 +147,7 @@ in rec { ... }: let otherArgs = (builtins.removeAttrs args [ "systems" ]) // { inherit systems overlays modules specialArgs scripts inputs configPath nixosSystem localSystem; }; nixosConfigurations = if builtins.isList systems then mergeAttrsUnique (map (systems: mkNixosConfigurations (otherArgs // systems)) systems) else mkNixosConfigurations (otherArgs // systems); - in { + in let outputs = { inherit nixosConfigurations; } // (forEachSystem [ "aarch64-linux" "x86_64-linux" ] (localSystem: let pkgs = (import inputs.nixpkgs { inherit overlays; system = localSystem; }); @@ -212,6 +214,10 @@ in rec { ${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: system: ( "ln -sT ${system.config.system.build.toplevel} $out/systems/${name}" )) nixosConfigurations)} + ${lib.optionalString (scripts != [ ]) '' + mkdir -p $out/scripts + ${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: _: "ln -sT ${outputs.apps.${localSystem}.${name}.program} $out/scripts/${name}") nixosConfigurations)} + ''} ${lib.optionalString (inputs != { }) '' mkdir -p $out/inputs ${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: { outPath, ... }: "ln -sT ${outPath} $out/inputs/${name}") inputs)} @@ -220,6 +226,6 @@ in rec { ''; }; - })); + })); in outputs; } diff --git a/lib/setup-scripts/README.md b/lib/setup-scripts/README.md index aee55f4..63f430f 100644 --- a/lib/setup-scripts/README.md +++ b/lib/setup-scripts/README.md @@ -11,7 +11,7 @@ With the functions from here, adding a simple three-liner can be enough to do a function install-system {( set -eu # 1: blockDev prepare-installer "$@" do-disk-setup "$1" - install-system-to $mnt prompt=true @{config.th.minify.topLevel:-} + install-system-to $mnt prompt=true )} ``` diff --git a/modules/base.nix.md b/modules/base.nix.md index 4af536f..d72e4c6 100644 --- a/modules/base.nix.md +++ b/modules/base.nix.md @@ -16,6 +16,7 @@ in { options.${prefix} = { base = { enable = lib.mkEnableOption "saner defaults"; + includeNixpkgs = lib.mkOption { description = "»nixpkgs« to include in the system build."; type = lib.types.nullOr lib.types.package; default = null; }; }; }; config = let @@ -36,6 +37,16 @@ in { # might additionally want to do this: https://stackoverflow.com/questions/62083796/automatic-reboot-on-systemd-emergency-mode systemd.extraConfig = "StatusUnitFormat=name"; # Show unit names instead of descriptions during boot. + + }) (lib.mkIf (cfg.includeNixpkgs != null) { + + nix.registry.nixpkgs.flake = cfg.includeNixpkgs; + environment.etc."nix/channels/nixpkgs".source = cfg.includeNixpkgs.outPath; + nix.nixPath = [ "nixpkgs=/etc/nix/channels/nixpkgs" "nixos-config=/etc/nixos" ]; + nix.extraOptions = "experimental-features = nix-command flakes"; # apparently, even nix 2.8 (in nixos-22.05) needs this + environment.shellAliases = { "with" = ''nix-shell --run "bash --login" -p''; }; + + }) ({ # Free convenience: