From 3fa010339bbf38f92ff468b8718dc22abead4fdd Mon Sep 17 00:00:00 2001 From: Terje Larsen Date: Mon, 19 Jun 2023 01:27:08 +0000 Subject: [PATCH 1/2] Allow customizing the system config to include in the tarball --- modules/build-tarball.nix | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/modules/build-tarball.nix b/modules/build-tarball.nix index 5eba52d9..9aff7791 100644 --- a/modules/build-tarball.nix +++ b/modules/build-tarball.nix @@ -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; @@ -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 @@ -49,15 +51,17 @@ 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 '' - # 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 - ''} - ''; + '' + 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 + '')); in { @@ -68,6 +72,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"; + }; }; From b1d98a6218c5c4c7fd7dc1966e977c53da841f82 Mon Sep 17 00:00:00 2001 From: Terje Larsen Date: Mon, 26 Jun 2023 02:00:21 +0000 Subject: [PATCH 2/2] Make system config included in the tarball writeable --- modules/build-tarball.nix | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/modules/build-tarball.nix b/modules/build-tarball.nix index 9aff7791..d2e52312 100644 --- a/modules/build-tarball.nix +++ b/modules/build-tarball.nix @@ -51,17 +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 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 - '')); + '' + 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 {