summaryrefslogtreecommitdiff
path: root/machines
diff options
context:
space:
mode:
authorMike Vink <mike1994vink@gmail.com>2023-10-11 16:40:00 +0000
committerMike Vink <mike1994vink@gmail.com>2023-10-11 16:40:00 +0000
commita4d82f2fc56a7b0c3dc84dc61cd074f94dfce62f (patch)
tree67a9f4bbcc8e6edafc06197f38e04b95653144df /machines
parent63aae9abf1f83a41ba92a4672277ba04c3bd48bf (diff)
move impure stuff
Diffstat (limited to 'machines')
-rw-r--r--machines/wsl.nix116
1 files changed, 108 insertions, 8 deletions
diff --git a/machines/wsl.nix b/machines/wsl.nix
index 6616489..8cc81c3 100644
--- a/machines/wsl.nix
+++ b/machines/wsl.nix
@@ -1,19 +1,119 @@
{ inputs, config, lib, pkgs, ... }:
+with builtins; with lib;
+let
+ defaultConfig = pkgs.writeText "default-configuration.nix" ''
+ { config, lib, pkgs, ... }:
+
+ {
+ imports = [
+ # include NixOS-WSL modules
+ <nixos-wsl/modules>
+ ];
+
+ wsl.enable = true;
+ wsl.defaultUser = "nixos";
+ ${lib.optionalString (!cfg.nativeSystemd) "wsl.nativeSystemd = false;"}
+
+ # This value determines the NixOS release from which the default
+ # settings for stateful data, like file locations and database versions
+ # on your system were taken. It's perfectly fine and recommended to leave
+ # this value at the release version of the first install of this system.
+ # Before changing this value read the documentation for this option
+ # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
+ system.stateVersion = "${config.system.nixos.release}"; # Did you read the comment?
+ }
+ '';
+in
{
- imports = [
- inputs.nixos-wsl.nixosModules.default
- ];
+ imports = [
+ inputs.nixos-wsl.nixosModules.default
+ ];
+
+ # These options make no sense without the wsl-distro module anyway
+ config = {
+ wsl = {
+ enable = true;
+ defaultUser = "mike";
+ wslConf.network = {
+ generateResolvConf = true;
+ };
+ };
+
+ system.build.tarballBuilder = pkgs.writeShellApplication {
+ name = "nixos-wsl-tarball-builder";
+
+ runtimeInputs = [
+ pkgs.coreutils
+ pkgs.gnutar
+ pkgs.nixos-install-tools
+ config.nix.package
+ ];
+
+ text = ''
+ if ! [ $EUID -eq 0 ]; then
+ echo "This script must be run as root!"
+ exit 1
+ fi
+
+ out=''${1:-nixos-wsl.tar.gz}
+
+ root=$(mktemp -p "''${TMPDIR:-/tmp}" -d nixos-wsl-tarball.XXXXXXXXXX)
+ # FIXME: fails in CI for some reason, but we don't really care because it's CI
+ trap 'rm -rf "$root" || true' INT TERM EXIT
+
+ chmod o+rx "$root"
+
+ echo "[NixOS-WSL] Installing..."
+ nixos-install \
+ --root "$root" \
+ --no-root-passwd \
+ --system ${config.system.build.toplevel} \
+ --substituters ""
+
+ echo "[NixOS-WSL] Adding channel..."
+ nixos-enter --root "$root" --command 'nix-channel --add https://github.com/nix-community/NixOS-WSL/archive/refs/heads/main.tar.gz nixos-wsl'
+
+ echo "[NixOS-WSL] Adding default config..."
+ install -Dm644 ${defaultConfig} "$root/etc/nixos/configuration.nix"
+
+ echo "[NixOS-WSL] Compressing..."
+ tar -C "$root" \
+ -cz \
+ --sort=name \
+ --mtime='@1' \
+ --owner=0 \
+ --group=0 \
+ --numeric-owner \
+ . \
+ > "$out"
+ '';
+ };
environment.systemPackages = with pkgs; [
git
];
- wsl = {
+ system.stateVersion = "23.05";
+ virtualisation.docker = {
enable = true;
- defaultUser = "mike";
- wslConf.network.generateResolvConf = false;
+ autoPrune = {
+ enable = true;
+ flags = ["-af"];
+ };
};
- system.stateVersion = "23.05";
- virtualisation.docker.enable = true;
+ systemd.services.docker.serviceConfig = {
+ ExecStart = ["" ''
+ ${pkgs.docker}/bin/dockerd --config-file=/wsl/dockerd/daemon.json
+ ''];
+ EnvironmentFile = "/wsl/dockerd/environmentfile";
+ };
+ networking.resolvconf.enable = false;
+ # TODO: why does this not work with etc."resolv.conf"??
+ environment.etc."/resolv.conf".source = "/wsl/etc/resolv.conf";
+ environment.etc."profile.local".source = "/wsl/etc/profile";
+ security.pki.certificateFiles = [
+ (/. + "/home/mike/pr-root.cer")
+ ];
+ };
}