Skip to content

Commit f0dd180

Browse files
authored
Merge pull request #80 from nzbr/optional-config
Allow building tarballs that do not contain the system config
2 parents a374c54 + b0eaa5d commit f0dd180

File tree

1 file changed

+36
-22
lines changed

1 file changed

+36
-22
lines changed

modules/build-tarball.nix

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,49 @@ let
4949
# Write wsl.conf so that it is present when NixOS is started for the first time
5050
cp ${config.environment.etc."wsl.conf".source} ./etc/wsl.conf
5151
52-
# Copy the system configuration
53-
mkdir -p ./etc/nixos/nixos-wsl
54-
cp -R ${lib.cleanSource ../.}/. ./etc/nixos/nixos-wsl
55-
mv ./etc/nixos/nixos-wsl/configuration.nix ./etc/nixos/configuration.nix
56-
# Patch the import path to avoid havin a flake.nix in /etc/nixos
57-
sed -i 's|import \./default\.nix|import \./nixos-wsl|' ./etc/nixos/configuration.nix
52+
${lib.optionalString config.wsl.tarball.includeConfig ''
53+
# Copy the system configuration
54+
mkdir -p ./etc/nixos/nixos-wsl
55+
cp -R ${lib.cleanSource ../.}/. ./etc/nixos/nixos-wsl
56+
mv ./etc/nixos/nixos-wsl/configuration.nix ./etc/nixos/configuration.nix
57+
# Patch the import path to avoid having a flake.nix in /etc/nixos
58+
sed -i 's|import \./default\.nix|import \./nixos-wsl|' ./etc/nixos/configuration.nix
59+
''}
5860
'';
5961

6062
in
61-
mkIf config.wsl.enable {
62-
# These options make no sense without the wsl-distro module anyway
63+
{
64+
65+
options.wsl.tarball = {
66+
includeConfig = mkOption {
67+
type = types.bool;
68+
default = true;
69+
description = "Whether or not to copy the system configuration into the tarball";
70+
};
71+
};
6372

64-
system.build.tarball = pkgs.callPackage "${nixpkgs}/nixos/lib/make-system-tarball.nix" {
65-
# No contents, structure will be added by prepare script
66-
contents = [ ];
6773

68-
fileName = "nixos-wsl-${pkgs.hostPlatform.system}";
74+
config = mkIf config.wsl.enable {
75+
# These options make no sense without the wsl-distro module anyway
6976

70-
storeContents = pkgs2storeContents [
71-
config.system.build.toplevel
72-
channelSources
73-
preparer
74-
];
77+
system.build.tarball = pkgs.callPackage "${nixpkgs}/nixos/lib/make-system-tarball.nix" {
78+
# No contents, structure will be added by prepare script
79+
contents = [ ];
7580

76-
extraCommands = "${preparer}/bin/wsl-prepare";
81+
fileName = "nixos-wsl-${pkgs.hostPlatform.system}";
7782

78-
# Use gzip
79-
compressCommand = "gzip";
80-
compressionExtension = ".gz";
81-
};
83+
storeContents = pkgs2storeContents [
84+
config.system.build.toplevel
85+
channelSources
86+
preparer
87+
];
88+
89+
extraCommands = "${preparer}/bin/wsl-prepare";
8290

91+
# Use gzip
92+
compressCommand = "gzip";
93+
compressionExtension = ".gz";
94+
};
95+
96+
};
8397
}

0 commit comments

Comments
 (0)