Skip to content

Commit

Permalink
Bring back customizing the system config to include in the tarball
Browse files Browse the repository at this point in the history
This was previously implemented in nix-community#260, but lost in the migration off
the installer tarball.
  • Loading branch information
terlar committed Oct 2, 2023
1 parent 337edef commit 71a9d01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 19 additions & 4 deletions modules/build-tarball.nix
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -34,13 +34,22 @@ 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";

runtimeInputs = [
pkgs.coreutils
pkgs.findutils
pkgs.gnutar
pkgs.nixos-install-tools
config.nix.package
Expand Down Expand Up @@ -71,7 +80,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" \
Expand Down
2 changes: 0 additions & 2 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@
"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.")
];
}

0 comments on commit 71a9d01

Please sign in to comment.