mirror of
https://github.com/davegallant/nix-config
synced 2025-08-07 17:32:26 +00:00
Add updated wsl configuration
This commit is contained in:
77
machines/aether/nixos-wsl/modules/installer.nix
Normal file
77
machines/aether/nixos-wsl/modules/installer.nix
Normal file
@@ -0,0 +1,77 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with builtins;
|
||||
with lib; {
|
||||
config = mkIf config.wsl.enable (
|
||||
let
|
||||
mkTarball = pkgs.callPackage "${lib.cleanSource pkgs.path}/nixos/lib/make-system-tarball.nix";
|
||||
|
||||
pkgs2storeContents = map (x: {
|
||||
object = x;
|
||||
symlink = "none";
|
||||
});
|
||||
|
||||
rootfs = let tarball = config.system.build.tarball; in "${tarball}/tarball/${tarball.fileName}.tar${tarball.extension}";
|
||||
|
||||
installer = pkgs.writeScript "installer.sh" ''
|
||||
#!${pkgs.busybox}/bin/sh
|
||||
BASEPATH=$PATH
|
||||
export PATH=$BASEPATH:${pkgs.busybox}/bin # Add busybox to path
|
||||
|
||||
set -e
|
||||
cd /
|
||||
|
||||
echo "Unpacking root file system..."
|
||||
${pkgs.pv}/bin/pv ${rootfs} | tar xz
|
||||
|
||||
echo "Activating nix configuration..."
|
||||
/nix/var/nix/profiles/system/activate
|
||||
PATH=$BASEPATH:/run/current-system/sw/bin # Use packages from target system
|
||||
|
||||
echo "Cleaning up installer files..."
|
||||
nix-collect-garbage
|
||||
rm /nix-path-registration
|
||||
|
||||
echo "Optimizing store..."
|
||||
nix-store --optimize
|
||||
|
||||
|
||||
echo "Starting systemd..."
|
||||
# Don't package the shell here, it's contained in the rootfs
|
||||
exec ${builtins.unsafeDiscardStringContext config.users.users.root.shell} "$@"
|
||||
'';
|
||||
|
||||
# Set installer.sh as the root shell
|
||||
passwd = pkgs.writeText "passwd" ''
|
||||
root:x:0:0:System administrator:/root:${installer}
|
||||
'';
|
||||
in {
|
||||
system.build.installer = mkTarball {
|
||||
fileName = "nixos-wsl-installer";
|
||||
compressCommand = "gzip";
|
||||
compressionExtension = ".gz";
|
||||
extraArgs = "--hard-dereference";
|
||||
|
||||
storeContents = with pkgs;
|
||||
pkgs2storeContents [
|
||||
installer
|
||||
];
|
||||
|
||||
contents = [
|
||||
{
|
||||
source = config.environment.etc."wsl.conf".source;
|
||||
target = "/etc/wsl.conf";
|
||||
}
|
||||
{
|
||||
source = passwd;
|
||||
target = "/etc/passwd";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user