1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-11 07:10:39 +02:00

chore: enforce disko use for microvm hosts

This commit is contained in:
oddlama 2023-05-16 17:54:43 +02:00
parent c03d1a1c8f
commit 02f27c85f4
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
4 changed files with 56 additions and 58 deletions

82
flake.lock generated
View file

@ -3,16 +3,17 @@
"agenix": {
"inputs": {
"darwin": "darwin",
"home-manager": "home-manager",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1682101079,
"narHash": "sha256-MdAhtjrLKnk2uiqun1FWABbKpLH090oeqCSiWemtuck=",
"lastModified": 1684153753,
"narHash": "sha256-PVbWt3qrjYAK+T5KplFcO+h7aZWfEj1UtyoKlvcDxh0=",
"owner": "ryantm",
"repo": "agenix",
"rev": "2994d002dcff5353ca1ac48ec584c7f6589fe447",
"rev": "db5637d10f797bb251b94ef9040b237f4702cde3",
"type": "github"
},
"original": {
@ -53,11 +54,11 @@
"stable": "stable"
},
"locked": {
"lastModified": 1682737380,
"narHash": "sha256-n3rZkHZls9BNr35o3veK00UsM1KSh/oNTJjLkFbEOY8=",
"lastModified": 1684127527,
"narHash": "sha256-tAzgb2jgmRaX9HETry38h2OvBf9YkHEH1fFvIJQV9A0=",
"owner": "zhaofengli",
"repo": "colmena",
"rev": "be837ee341b6508c355035973d5f7c7e88d7c64f",
"rev": "caf33af7d854c8d9b88a8f3dae7adb1c24c1407b",
"type": "github"
},
"original": {
@ -116,11 +117,11 @@
]
},
"locked": {
"lastModified": 1683508929,
"narHash": "sha256-AqkIrwewCL8+zlkqhNxheF+kOfyakzZDk43SqRTIqRE=",
"lastModified": 1684170997,
"narHash": "sha256-WgwqHeYv2sDA0eWghnYCUNx7dm5S8lqDVZjp7ufzm30=",
"owner": "nix-community",
"repo": "disko",
"rev": "2a59f5cf641607dbecb0cfec3ae32247e4aeb311",
"rev": "10402e31443941b50bf62e67900743dcb26b3b27",
"type": "github"
},
"original": {
@ -203,15 +204,36 @@
"home-manager": {
"inputs": {
"nixpkgs": [
"agenix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1683651229,
"narHash": "sha256-HN0Mw8g1XQIrcdyzqT00YW0Uqi/V/BUUUAgvcK1pcSM=",
"lastModified": 1682203081,
"narHash": "sha256-kRL4ejWDhi0zph/FpebFYhzqlOBrk0Pl3dzGEKSAlEw=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "983f8a1bb965b261492123cd8e2d07da46d4d50a",
"rev": "32d3e39c491e2f91152c84f8ad8b003420eab0a1",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "home-manager",
"type": "github"
}
},
"home-manager_2": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1684157850,
"narHash": "sha256-xGHTCgvAxO5CgAL6IAgE/VGRX2wob2Y+DPyqpXJ32oQ=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "c0deab0effd576e70343cb5df0c64428e0e0d010",
"type": "github"
},
"original": {
@ -222,11 +244,11 @@
},
"impermanence": {
"locked": {
"lastModified": 1682268411,
"narHash": "sha256-ICDKQ7tournRVtfM8C2II0qHiOZOH1b3dXVOCsgr11o=",
"lastModified": 1684144492,
"narHash": "sha256-5TBG9kZGdKrZGHdyjLA04ODSzhx1Bx/vwMxfRgWF+JU=",
"owner": "nix-community",
"repo": "impermanence",
"rev": "df1692e2d9f1efc4300b1ea9201831730e0b817d",
"rev": "ec1a8e70d61261f9ada30f4e450ea7230d9efb62",
"type": "github"
},
"original": {
@ -257,10 +279,10 @@
]
},
"locked": {
"lastModified": 1683574932,
"narHash": "sha256-k7cKhbuMJew1Cy6dPKb19MmXIHmLCJtuIfsekzhgW8o=",
"lastModified": 1684191523,
"narHash": "sha256-xIK3uQgSRqNLkEeD1vmRrpXjtYjpM7PK3liGMqAAPfc=",
"ref": "refs/heads/main",
"rev": "01f07441eb8b244065f2bd6d5ca090acc9766ab6",
"rev": "fc98a8ca01ce1461d51728fd5df0c2ff609b5d09",
"revCount": 486,
"type": "git",
"url": "file:///root/projects/microvm.nix"
@ -309,11 +331,11 @@
},
"nixos-hardware": {
"locked": {
"lastModified": 1683269598,
"narHash": "sha256-KNsb+nBbB1Fmxd07dt4E0KXMT4YeKJB7gQaA6Xfk+mo=",
"lastModified": 1684169666,
"narHash": "sha256-N5jrykeSxLVgvm3Dd3hZ38/XwM/jU+dltqlXgrGlYxk=",
"owner": "NixOS",
"repo": "nixos-hardware",
"rev": "51559e691f1493a26f94f1df1aaf516bb507e78b",
"rev": "71ce85372a614d418d5e303dd5702a79d1545c04",
"type": "github"
},
"original": {
@ -345,12 +367,10 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1683408522,
"narHash": "sha256-9kcPh6Uxo17a3kK3XCHhcWiV1Yu1kYj22RHiymUhMkU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "897876e4c484f1e8f92009fd11b7d988a121a4e7",
"type": "github"
"lastModified": 1684049129,
"narHash": "sha256-dyq0Cc+C/WaVHWSIICqIlteLzzQyRAfw3rQQGrBAzWM=",
"type": "git",
"url": "file:///root/projects/nixpkgs-test"
},
"original": {
"owner": "NixOS",
@ -388,11 +408,11 @@
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1682596858,
"narHash": "sha256-Hf9XVpqaGqe/4oDGr30W8HlsWvJXtMsEPHDqHZA6dDg=",
"lastModified": 1684195081,
"narHash": "sha256-IKnQUSBhQTChFERxW2AzuauVpY1HRgeVzAjNMAA4B6I=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "fb58866e20af98779017134319b5663b8215d912",
"rev": "96eabec58248ed8f4b0ad59e7ce9398018684fdc",
"type": "github"
},
"original": {
@ -408,7 +428,7 @@
"colmena": "colmena",
"disko": "disko",
"flake-utils": "flake-utils",
"home-manager": "home-manager",
"home-manager": "home-manager_2",
"impermanence": "impermanence",
"lib-net": "lib-net",
"microvm": "microvm",

View file

@ -86,6 +86,7 @@ in {
matchConfig.Kind = "macvtap";
networkConfig.LinkLocalAddressing = "no";
linkConfig.ActivationPolicy = "manual";
linkConfig.Unmanaged = "yes";
};
};

View file

@ -34,9 +34,9 @@
# Configuration for each microvm
microvmConfig = vmName: vmCfg: {
# Add the required datasets to the disko configuration of the machine
disko.devices.zpool = mkIf (vmCfg.zfs.enable && vmCfg.zfs.disko) {
disko.devices.zpool = mkIf vmCfg.zfs.enable {
${vmCfg.zfs.pool}.datasets."${vmCfg.zfs.dataset}" =
extraLib.disko.zfs.filesystem "${vmCfg.zfs.mountpoint}";
extraLib.disko.zfs.filesystem vmCfg.zfs.mountpoint;
};
# TODO not cool, this might change or require more creation options.
@ -50,11 +50,10 @@
in
mkIf vmCfg.zfs.enable ''
if ! ${pkgs.zfs}/bin/zfs list -H -o type ${escapeShellArg poolDataset} &>/dev/null ; then
${pkgs.zfs}/bin/zfs create -o canmount=on -o mountpoint=${escapeShellArg vmCfg.zfs.mountpoint} ${escapeShellArg poolDataset}
${config.disko.devices.zpool.${vmCfg.zfs.pool}.datasets.${vmCfg.zfs.dataset}._create {zpool = vmCfg.zfs.pool;}}
fi
'';
microvm.autostart = mkIf vmCfg.autostart [vmName];
microvm.vms.${vmName} = let
node =
(import ../nix/generate-node.nix inputs)
@ -64,6 +63,7 @@
};
in {
inherit (node) pkgs specialArgs;
inherit (vmCfg) autostart;
config = {
imports = [microvm.microvm] ++ node.imports;
@ -139,13 +139,6 @@ in {
microvm.host
# This is opt-out, so we can't put this into the mkIf below
{microvm.host.enable = cfg != {};}
# This module requires declarativeUpdates and restartIfChanged.
{
microvm = mkIf (cfg != {}) {
declarativeUpdates = true;
restartIfChanged = true;
};
}
];
options.extra.microvms = mkOption {
@ -170,12 +163,6 @@ in {
type = types.str;
description = mdDoc "The host's mountpoint for the vm's dataset (will be shared via virtofs as /persist in the vm)";
};
disko = mkOption {
type = types.bool;
default = true;
description = mdDoc "Add this dataset to the host's disko configuration";
};
};
autostart = mkOption {

View file

@ -16,12 +16,9 @@
foldAttrs
foldl'
genAttrs
getAttrs
head
mapAttrs
mapAttrs'
mergeAttrs
mkMerge
nameValuePair
optionalAttrs
partition
@ -53,13 +50,6 @@ in rec {
# True if the path or string starts with /
isAbsolutePath = x: substring 0 1 x == "/";
# Used to merge multiple toplevel configuration entries
# https://gist.github.com/udf/4d9301bdc02ab38439fd64fbda06ea43
mkMergeTopLevel = names: attrs:
getAttrs names (
mapAttrs (_: mkMerge) (foldAttrs (n: a: [n] ++ a) [] attrs)
);
disko = {
gpt = {
partEfi = name: start: end: {