diff options
| author | nzbr <mail@nzbr.de> | 2022-02-01 04:01:13 +0100 |
|---|---|---|
| committer | nzbr <mail@nzbr.de> | 2022-02-01 04:01:13 +0100 |
| commit | 4262e1f600ca3d8317f095bb8e511e5243fe0238 (patch) | |
| tree | 501bc65aaefa7bd60553ae7eec76b4b0e8950925 /modules | |
| parent | a487bcf303bffb418edda23c9e5ec1d5dbf739c3 (diff) | |
move build-tarball to a flake module
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/build-tarball.nix | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/modules/build-tarball.nix b/modules/build-tarball.nix new file mode 100644 index 0000000..c91e9c5 --- /dev/null +++ b/modules/build-tarball.nix @@ -0,0 +1,74 @@ +{ config, pkgs, lib, ... }: +with builtins; with lib; +let + pkgs2storeContents = l: map (x: { object = x; symlink = "none"; }) l; + + nixpkgs = lib.cleanSource pkgs.path; + + channelSources = pkgs.runCommand "nixos-${config.system.nixos.version}" + { preferLocalBuild = true; } + '' + mkdir -p $out + cp -prd ${nixpkgs.outPath} $out/nixos + chmod -R u+w $out/nixos + if [ ! -e $out/nixos/nixpkgs ]; then + ln -s . $out/nixos/nixpkgs + fi + echo -n ${toString config.system.nixos.revision} > $out/nixos/.git-revision + echo -n ${toString config.system.nixos.versionSuffix} > $out/nixos/.version-suffix + echo ${toString config.system.nixos.versionSuffix} | sed -e s/pre// > $out/nixos/svn-revision + ''; + + preparer = pkgs.writeShellScriptBin "wsl-prepare" '' + set -e + + mkdir -m 0755 ./bin ./etc + mkdir -m 1777 ./tmp + + # WSL requires a /bin/sh - only temporary, NixOS's activate will overwrite + ln -s ${config.users.users.root.shell} ./bin/sh + + # WSL also requires a /bin/mount, otherwise the host fs isn't accessible + ln -s /nix/var/nix/profiles/system/sw/bin/mount ./bin/mount + + # Set system profile + system=${config.system.build.toplevel} + ./$system/sw/bin/nix-store --store `pwd` --load-db < ./nix-path-registration + rm ./nix-path-registration + ./$system/sw/bin/nix-env --store `pwd` -p ./nix/var/nix/profiles/system --set $system + + # Set channel + mkdir -p ./nix/var/nix/profiles/per-user/root + ./$system/sw/bin/nix-env --store `pwd` -p ./nix/var/nix/profiles/per-user/root/channels --set ${channelSources} + mkdir -m 0700 -p ./root/.nix-defexpr + ln -s /nix/var/nix/profiles/per-user/root/channels ./root/.nix-defexpr/channels + + # It's now a NixOS! + touch ./etc/NIXOS + + # Copy the system configuration + mkdir -p ./etc/nixos + cp -R ${../.}/. ./etc/nixos/ + ''; + +in +{ + 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-${config.system.nixos.release}-${pkgs.hostPlatform.system}"; + + storeContents = pkgs2storeContents [ + config.system.build.toplevel + channelSources + preparer + ]; + + extraCommands = "${preparer}/bin/wsl-prepare"; + + # Use gzip + compressCommand = "gzip"; + compressionExtension = ".gz"; + }; +} |
