diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..e69de29 diff --git a/flake.lock b/flake.lock index 39860ef..334fb61 100644 --- a/flake.lock +++ b/flake.lock @@ -22,11 +22,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1734536697, - "narHash": "sha256-G/HnRTtU+ob8x967kjzMRqjNFbAdllrcjYc+IcaR15Y=", + "lastModified": 1734623593, + "narHash": "sha256-iA3kxtbds7yOc77oRBz2On9ZmOVI/1Pic+YQtYUyIsg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9c40bef08a5bdc0ccc3207f4282a1ded83e77a7a", + "rev": "8af52ff6ba2ed83047881e877718db3bb02fad85", "type": "github" }, "original": { diff --git a/hosts/base.nix b/hosts/base/default.nix similarity index 84% rename from hosts/base.nix rename to hosts/base/default.nix index f7ca25d..229d404 100644 --- a/hosts/base.nix +++ b/hosts/base/default.nix @@ -2,6 +2,10 @@ ... }: { + imports = [ + ./hardware-config.nix + ]; + nixpkgs.config.allowUnfree = true; kropcloud = { @@ -19,5 +23,7 @@ }; }; + services.qemuGuest.enable = true; + system.stateVersion = "24.11"; } diff --git a/hosts/base/hardware-config.nix b/hosts/base/hardware-config.nix new file mode 100644 index 0000000..781026e --- /dev/null +++ b/hosts/base/hardware-config.nix @@ -0,0 +1,27 @@ +{ + config, + lib, + pkgs, + modulesPath, + ... +}: + +{ + imports = [ + (modulesPath + "/profiles/qemu-guest.nix") + ]; + + boot.initrd.availableKernelModules = [ + "ata_piix" + "uhci_hcd" + "virtio_pci" + "virtio_scsi" + "sd_mod" + "sr_mod" + ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ ]; + boot.extraModulePackages = [ ]; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; +} diff --git a/hosts/hydra.nix b/hosts/hydra/default.nix similarity index 86% rename from hosts/hydra.nix rename to hosts/hydra/default.nix index 20a8624..fb5ffcc 100644 --- a/hosts/hydra.nix +++ b/hosts/hydra/default.nix @@ -3,7 +3,6 @@ kropcloud = { networking = { ipv4 = { - enable = true; address = "192.168.1.160"; prefixLength = 24; }; diff --git a/hosts/tailscale-proxy.nix b/hosts/tailscale-proxy/default.nix similarity index 100% rename from hosts/tailscale-proxy.nix rename to hosts/tailscale-proxy/default.nix diff --git a/lib.nix b/lib.nix index 671253d..a214747 100644 --- a/lib.nix +++ b/lib.nix @@ -11,8 +11,8 @@ nixpkgs.lib.nixosSystem { system = arch; modules = [ - ./hosts/base.nix - ./hosts/${name}.nix + ./hosts/base + ./hosts/${name} ./nixosModules ( { ... }: @@ -22,6 +22,8 @@ }; } ) + + inputs.disko.nixosModules.disko ]; specialArgs = { inherit inputs; diff --git a/nixosModules/default.nix b/nixosModules/default.nix index 03cdb17..4fa6802 100644 --- a/nixosModules/default.nix +++ b/nixosModules/default.nix @@ -5,5 +5,6 @@ ./networking ./users ./locale + ./drives ]; } diff --git a/nixosModules/drives/default.nix b/nixosModules/drives/default.nix new file mode 100644 index 0000000..74ff51c --- /dev/null +++ b/nixosModules/drives/default.nix @@ -0,0 +1,51 @@ +{ + config, + lib, + ... +}: +let + cfg = config.kropcloud.drives; +in +{ + options.kropcloud.drives = { + hasSecondDrive = lib.mkEnableOption "Whence this VM has second drive"; + }; + config = { + disko.devices = { + disk = { + main = { + type = "disk"; + device = "/dev/sda"; + content = { + type = "gpt"; + partitions = { + ESP = { + type = "EF00"; + size = "512M"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + root = { + end = "-8GB"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + swap = { + size = "100%"; + content = { + type = "swap"; + }; + }; + }; + }; + }; + }; + }; + }; +} diff --git a/nixosModules/networking/default.nix b/nixosModules/networking/default.nix index e589863..d30c413 100644 --- a/nixosModules/networking/default.nix +++ b/nixosModules/networking/default.nix @@ -5,6 +5,20 @@ }: let cfg = config.kropcloud.networking; + ipopts = version: { + address = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "The server IPv${version} address"; + example = if version == 4 then "192.168.1.155" else null; + default = null; + }; + prefixLength = lib.mkOption { + type = lib.types.nullOr lib.types.int; + description = "The server IPv${version} address prefix length"; + default = null; + example = if version == 4 then 24 else 64; + }; + }; in { options.kropcloud.networking = { @@ -14,31 +28,16 @@ in default = true; example = false; }; - # TODO: fix this madness - ipv4 = { - enable = lib.mkEnableOption "Whence to enable IPv4 configuration"; - address = lib.mkOption { - type = lib.types.nullOr lib.types.str; - description = "The server IPv4 address"; - example = "192.168.1.155"; - default = null; - }; - prefixLength = lib.mkOption { - type = lib.types.int; - description = "The server IPv4 address prefix length"; - default = 24; - example = 24; - }; - }; + ipv4 = ipopts 4; }; config = lib.mkIf cfg.enable { assertions = [ { - assertion = !(cfg.ipv4.enable && (cfg.ipv4.address == null || cfg.ipv4.address == "" || cfg.ipv4.prefixLength == null)); + assertion = !(cfg.ipv4.address == null || cfg.ipv4.prefixLength == null); message = '' You need to provide valid values for both `address` and `prefixLength` in `kropcloud.networking.ipv4` - when `kropcloud.networking.ipv4.enable` is true. + when either is set. ''; } ]; @@ -50,7 +49,7 @@ in }; interfaces = { ens18 = { - ipv4.addresses = lib.mkIf cfg.ipv4.enable [ + ipv4.addresses = lib.mkIf (cfg.ipv4.address != null || cfg.ipv4.prefixLength != null) [ { address = cfg.ipv4.address; prefixLength = cfg.ipv4.prefixLength; @@ -58,6 +57,7 @@ in ]; }; }; + useDHCP = (cfg.ipv4.address == null || cfg.ipv4.prefixLength == null); }; }; }