From 9cb8ca802f3bb81bc6d59ef1ec3c2d6cabfa3b25 Mon Sep 17 00:00:00 2001 From: Terje Larsen Date: Mon, 2 Oct 2023 10:23:53 +0000 Subject: [PATCH] Bring back customizing the system config to include in the tarball This was previously implemented in #260, but lost in the migration off the installer tarball. --- modules/build-tarball.nix | 22 ++++++++++++++++++---- modules/default.nix | 4 ++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/modules/build-tarball.nix b/modules/build-tarball.nix index 577f0448..8341f7fa 100644 --- a/modules/build-tarball.nix +++ b/modules/build-tarball.nix @@ -1,7 +1,7 @@ { config, pkgs, lib, ... }: with builtins; with lib; let - cfg = config.wsl; + cfg = config.wsl.tarball; defaultConfig = pkgs.writeText "default-configuration.nix" '' # Edit this configuration file to define what should be installed on @@ -21,7 +21,7 @@ let wsl.enable = true; wsl.defaultUser = "nixos"; - ${lib.optionalString (!cfg.nativeSystemd) "wsl.nativeSystemd = false;"} + ${lib.optionalString (!config.wsl.nativeSystemd) "wsl.nativeSystemd = false;"} # This value determines the NixOS release from which the default # settings for stateful data, like file locations and database versions @@ -34,8 +34,16 @@ let ''; in { + options.wsl.tarball = { + configPath = mkOption { + type = types.nullOr types.path; + default = null; + description = "Path to system configuration which is copied into the tarball"; + }; + }; + # These options make no sense without the wsl-distro module anyway - config = mkIf cfg.enable { + config = mkIf config.wsl.enable { system.build.tarballBuilder = pkgs.writeShellApplication { name = "nixos-wsl-tarball-builder"; @@ -71,7 +79,13 @@ in nixos-enter --root "$root" --command 'nix-channel --add https://github.com/nix-community/NixOS-WSL/archive/refs/heads/main.tar.gz nixos-wsl' echo "[NixOS-WSL] Adding default config..." - install -Dm644 ${defaultConfig} "$root/etc/nixos/configuration.nix" + ${if cfg.configPath == null then '' + install -Dm644 ${defaultConfig} "$root/etc/nixos/configuration.nix" + '' else '' + mkdir -p "$root/etc/nixos" + cp -R ${lib.cleanSource cfg.configPath}/. "$root/etc/nixos" + chmod -R u+w "$root/etc/nixos" + ''} echo "[NixOS-WSL] Compressing..." tar -C "$root" \ diff --git a/modules/default.nix b/modules/default.nix index c2f9a387..b5134b8b 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -14,7 +14,7 @@ "Additional workarounds are no longer required for Docker to work. Please use the standard `virtualisation.docker` NixOS options.") (lib.mkRemovedOptionModule [ "wsl" "interop" "preserveArgvZero" ] "wsl.interop.preserveArgvZero is now always enabled, as used by modern WSL versions.") - (lib.mkRemovedOptionModule [ "wsl" "tarball" ] - "The tarball is now always generated with a default configuration.nix.") + (lib.mkRemovedOptionModule [ "wsl" "tarball" "includeConfig" ] + "The tarball is now always generated including configuration.") ]; }