From 156c00fd4eaf63c7a9ff927b6edbd87afa1076b1 Mon Sep 17 00:00:00 2001 From: nzbr Date: Sun, 17 Apr 2022 01:33:13 +0200 Subject: [PATCH 1/2] Make including the system config in the tarball optional --- modules/build-tarball.nix | 58 ++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/modules/build-tarball.nix b/modules/build-tarball.nix index 03d6a609..d275c022 100644 --- a/modules/build-tarball.nix +++ b/modules/build-tarball.nix @@ -49,35 +49,49 @@ let # Write wsl.conf so that it is present when NixOS is started for the first time cp ${config.environment.etc."wsl.conf".source} ./etc/wsl.conf - # Copy the system configuration - mkdir -p ./etc/nixos/nixos-wsl - cp -R ${lib.cleanSource ../.}/. ./etc/nixos/nixos-wsl - mv ./etc/nixos/nixos-wsl/configuration.nix ./etc/nixos/configuration.nix - # Patch the import path to avoid havin a flake.nix in /etc/nixos - sed -i 's|import \./default\.nix|import \./nixos-wsl|' ./etc/nixos/configuration.nix + ${lib.optionalString config.wsl.tarball.includeConfig '' + # Copy the system configuration + mkdir -p ./etc/nixos/nixos-wsl + cp -R ${lib.cleanSource ../.}/. ./etc/nixos/nixos-wsl + mv ./etc/nixos/nixos-wsl/configuration.nix ./etc/nixos/configuration.nix + # Patch the import path to avoid havin a flake.nix in /etc/nixos + sed -i 's|import \./default\.nix|import \./nixos-wsl|' ./etc/nixos/configuration.nix + ''} ''; in -mkIf config.wsl.enable { - # These options make no sense without the wsl-distro module anyway +{ + + options.wsl.tarball = { + includeConfig = mkOption { + type = types.bool; + default = true; + description = "Whether or not to copy the system configuration into the tarball"; + }; + }; - system.build.tarball = pkgs.callPackage "${nixpkgs}/nixos/lib/make-system-tarball.nix" { - # No contents, structure will be added by prepare script - contents = [ ]; - fileName = "nixos-wsl-${pkgs.hostPlatform.system}"; + config = mkIf config.wsl.enable { + # These options make no sense without the wsl-distro module anyway - storeContents = pkgs2storeContents [ - config.system.build.toplevel - channelSources - preparer - ]; + system.build.tarball = pkgs.callPackage "${nixpkgs}/nixos/lib/make-system-tarball.nix" { + # No contents, structure will be added by prepare script + contents = [ ]; - extraCommands = "${preparer}/bin/wsl-prepare"; + fileName = "nixos-wsl-${pkgs.hostPlatform.system}"; - # Use gzip - compressCommand = "gzip"; - compressionExtension = ".gz"; - }; + storeContents = pkgs2storeContents [ + config.system.build.toplevel + channelSources + preparer + ]; + + extraCommands = "${preparer}/bin/wsl-prepare"; + # Use gzip + compressCommand = "gzip"; + compressionExtension = ".gz"; + }; + + }; } From b0eaa5db6e44de68b5c2d11f913d1b978c6a77a1 Mon Sep 17 00:00:00 2001 From: nzbr Date: Sun, 17 Apr 2022 12:38:20 +0200 Subject: [PATCH 2/2] fix typo --- modules/build-tarball.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/build-tarball.nix b/modules/build-tarball.nix index d275c022..feba78d4 100644 --- a/modules/build-tarball.nix +++ b/modules/build-tarball.nix @@ -54,7 +54,7 @@ let mkdir -p ./etc/nixos/nixos-wsl cp -R ${lib.cleanSource ../.}/. ./etc/nixos/nixos-wsl mv ./etc/nixos/nixos-wsl/configuration.nix ./etc/nixos/configuration.nix - # Patch the import path to avoid havin a flake.nix in /etc/nixos + # Patch the import path to avoid having a flake.nix in /etc/nixos sed -i 's|import \./default\.nix|import \./nixos-wsl|' ./etc/nixos/configuration.nix ''} '';