Skip to content

Commit

Permalink
Merge pull request #80 from nzbr/optional-config
Browse files Browse the repository at this point in the history
Allow building tarballs that do not contain the system config
  • Loading branch information
nzbr authored Apr 17, 2022
2 parents a374c54 + b0eaa5d commit f0dd180
Showing 1 changed file with 36 additions and 22 deletions.
58 changes: 36 additions & 22 deletions modules/build-tarball.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 having 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";
};

};
}

0 comments on commit f0dd180

Please sign in to comment.