Skip to content

Commit

Permalink
Merge pull request #304 from terlar/customize-tarball-system-config
Browse files Browse the repository at this point in the history
Bring back customizing the system config to include in the tarball
  • Loading branch information
nzbr authored Nov 28, 2023
2 parents a9287f7 + 9cb8ca8 commit b4354a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 18 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,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";

Expand Down Expand Up @@ -71,7 +79,13 @@ in
nixos-enter --root "$root" --command 'HOME=/root 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
4 changes: 2 additions & 2 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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.")
];
}

0 comments on commit b4354a9

Please sign in to comment.