-
Notifications
You must be signed in to change notification settings - Fork 0
/
lima-init.nix
59 lines (48 loc) · 1.91 KB
/
lima-init.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{ config, modulesPath, pkgs, lib, ... }:
let
LIMA_CIDATA_MNT = "/mnt/lima-cidata"; # FIXME: hardcoded
LIMA_CIDATA_DEV = "/dev/disk/by-label/cidata"; # FIXME: hardcoded
script = ''
echo "attempting to fetch configuration from LIMA user data..."
export HOME=/root
export PATH=${pkgs.lib.makeBinPath [ pkgs.gnused config.nix.package config.system.build.nixos-rebuild]}:$PATH
export NIX_PATH=nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels
if [ -f ${LIMA_CIDATA_MNT}/lima.env ]; then
echo "storage exists";
else
echo "storage not exists";
exit 2
fi
cp -f ${./configuration.nix} /etc/nixos/configuration.nix
cp -f ${./lima-init.nix} /etc/nixos/lima-init.nix
cp -f ${./lima-runtime.nix} /etc/nixos/lima-runtime.nix
chmod 664 /etc/nixos/configuration.nix
chmod 664 /etc/nixos/lima-init.nix
chmod 664 /etc/nixos/lima-runtime.nix
sed -i 's@imports = \[];@imports = \[ "/etc/nixos/lima-runtime.nix" ];@g' /etc/nixos/lima-init.nix
nixos-rebuild switch
cp "${LIMA_CIDATA_MNT}"/meta-data /run/lima-ssh-ready
cp "${LIMA_CIDATA_MNT}"/meta-data /run/lima-boot-done
exit 0
'';
in {
imports = []; # PLACE HOLDER #
systemd.services.lima-init = {
inherit script;
description = "Reconfigure the system from lima-init userdata on startup";
wantedBy = [ "multi-user.target" ];
after = [ "multi-user.target" ];
requires = [ "network.target" ];
restartIfChanged = false;
unitConfig.X-StopOnRemoval = false;
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
};
fileSystems."${LIMA_CIDATA_MNT}" = {
device = "${LIMA_CIDATA_DEV}";
fsType = "auto";
options = [ "ro" "mode=0700" "dmode=0700" "overriderockperm" "exec" "uid=0" ];
};
}