Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customizing the system config to include in the tarball #260

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions modules/build-tarball.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{ config, pkgs, lib, ... }:
with builtins; with lib;
let
cfg = config.wsl.tarball;

pkgs2storeContents = l: map (x: { object = x; symlink = "none"; }) l;

nixpkgs = lib.cleanSource pkgs.path;
Expand All @@ -19,7 +21,7 @@ let
echo ${toString config.system.nixos.versionSuffix} | sed -e s/pre// > $out/nixos/svn-revision
'';

preparer = pkgs.writeShellScriptBin "wsl-prepare" ''
preparer = pkgs.writeShellScriptBin "wsl-prepare" (''
set -e

mkdir -m 0755 ./bin ./etc
Expand Down Expand Up @@ -49,15 +51,20 @@ 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

${lib.optionalString config.wsl.tarball.includeConfig ''
'' + lib.optionalString cfg.includeConfig ''
${if cfg.configPath == null then ''
# 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
'' else ''
mkdir -p ./etc/nixos
cp -R ${lib.cleanSource cfg.configPath}/. ./etc/nixos
''}
'';
chmod -R u+w etc/nixos
'');

in
{
Expand All @@ -68,6 +75,12 @@ in
default = true;
description = "Whether or not to copy the system configuration into the tarball";
};

configPath = mkOption {
type = types.nullOr types.path;
default = null;
description = "Path to system configuration which is copied into the tarball";
};
};


Expand Down
Loading