Commit 28b12af999b3
Changed files (3)
modules/microshift/default.nix
@@ -0,0 +1,123 @@
+{
+ config,
+ lib,
+ pkgs,
+ ...
+}:
+
+with lib;
+let
+ cfg = config.services.microshift;
+in
+{
+ options = {
+ services.microshift = {
+ enable = mkEnableOption "MicroShift via CRC";
+
+ cpus = mkOption {
+ type = types.int;
+ default = 4;
+ description = "Number of CPU cores for MicroShift";
+ };
+
+ memory = mkOption {
+ type = types.int;
+ default = 8192; # 8GB
+ description = "Memory in MB for MicroShift";
+ };
+
+ diskSize = mkOption {
+ type = types.int;
+ default = 40; # GB
+ description = "Disk size in GB for MicroShift";
+ };
+
+ pullSecret = mkOption {
+ type = types.nullOr types.path;
+ default = null;
+ description = "Path to Red Hat pull secret (required for MicroShift preset)";
+ };
+
+ user = mkOption {
+ type = types.str;
+ default = "vincent";
+ description = "User to run CRC as";
+ };
+ };
+ };
+
+ config = mkIf cfg.enable {
+ assertions = [
+ {
+ assertion = cfg.cpus >= 2 && cfg.cpus <= 16;
+ message = "services.microshift.cpus must be between 2 and 16";
+ }
+ {
+ assertion = cfg.memory >= 4096;
+ message = "services.microshift.memory must be at least 4096 MB (4GB)";
+ }
+ {
+ assertion = cfg.diskSize >= 20;
+ message = "services.microshift.diskSize must be at least 20 GB";
+ }
+ ];
+
+ # Ensure required services are enabled
+ virtualisation.podman.enable = true;
+ virtualisation.libvirtd.enable = true;
+
+ # Ensure user has libvirt access
+ users.users.${cfg.user}.extraGroups = [ "libvirt" ];
+
+ environment.systemPackages = with pkgs; [
+ crc
+ kubectl
+ ];
+
+ # Systemd service to manage CRC lifecycle
+ systemd.services.crc-microshift = {
+ description = "MicroShift via CRC";
+ after = [
+ "network.target"
+ "libvirtd.service"
+ ];
+ wantedBy = [ "multi-user.target" ];
+
+ serviceConfig = {
+ Type = "oneshot";
+ RemainAfterExit = true;
+ User = cfg.user;
+ WorkingDirectory = "/home/${cfg.user}";
+ };
+
+ script = ''
+ # Setup CRC with MicroShift preset
+ ${pkgs.crc}/bin/crc config set preset microshift
+ ${pkgs.crc}/bin/crc config set cpus ${toString cfg.cpus}
+ ${pkgs.crc}/bin/crc config set memory ${toString cfg.memory}
+ ${pkgs.crc}/bin/crc config set disk-size ${toString cfg.diskSize}
+
+ ${optionalString (cfg.pullSecret != null) ''
+ ${pkgs.crc}/bin/crc config set pull-secret-file ${cfg.pullSecret}
+ ''}
+
+ # Setup (downloads images if needed)
+ ${pkgs.crc}/bin/crc setup
+
+ # Start MicroShift
+ ${pkgs.crc}/bin/crc start
+ '';
+
+ preStop = ''
+ ${pkgs.crc}/bin/crc stop
+ '';
+ };
+
+ # Environment setup for kubectl access
+ environment.extraInit = ''
+ if [ -f ~/.crc/machines/crc/kubeconfig ]; then
+ export KUBECONFIG=~/.crc/machines/crc/kubeconfig
+ fi
+ '';
+ };
+}
systems/aomi/extra.nix
@@ -32,6 +32,7 @@
# Remote build system
../../modules/job-notify
../../modules/nixpkgs-consolidate
+ ../../modules/microshift
];
# Firewall is enabled in openshift-port-forward.nix
@@ -328,4 +329,14 @@
}
];
+ # MicroShift via CRC
+ services.microshift = {
+ enable = true;
+ cpus = 4;
+ memory = 8192; # 8GB
+ diskSize = 40;
+ user = "vincent";
+ # pullSecret will be configured via agenix later
+ };
+
}
flake.nix
@@ -140,6 +140,7 @@
gosmee = ./modules/gosmee;
rsync-replica = ./modules/rsync-replica;
nixpkgs-consolidate = ./modules/nixpkgs-consolidate;
+ microshift = ./modules/microshift;
};
# system-manager configurations