Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modulesPath should be available #9

Open
github-actions bot opened this issue Dec 21, 2023 · 0 comments
Open

modulesPath should be available #9

github-actions bot opened this issue Dec 21, 2023 · 0 comments
Labels
help wanted Extra attention is needed todo

Comments

@github-actions
Copy link
Contributor

(modulesPath + "/profiles/qemu-guest.nix")

# TODO: modulesPath should be available

{ system, pkgs, flake, ... }:
let
  inherit (flake.inputs.everyday.nixosModules) logger host-keys;
  inherit (flake.inputs.disko.nixosModules) disko;
  inherit (flake.outputs.lib) mkSystem secrets;
  agenix = flake.inputs.agenix.nixosModules.default;
  nix-serve = flake.inputs.nix-serve-ng.nixosModules.default;
  domain = "cache.64-b.it";
  home = "/home/klarkc";
  authorizedKeys.keys = [
    (builtins.readFile ../../secrets/klarkc.pub)
  ];
  cache-module = { disks ? [ "/dev/vda" ], config, ... }:
    {
      imports = [
        nix-serve
        agenix
        disko
      ];
      # cd secrets
      # nix-store --generate-binary-cache-key cache.64-b.it ./cache ./cache.skey
      # cat cache | nix run github:ryantm/agenix -- -e cache.age -i ~/.ssh/id_ed25519
      # cp ~/.ssh/id_ed25519.pub klarkc.pub
      age.secrets.cache.file = "${secrets}/cache.age";
      system.stateVersion = config.system.nixos.version;
      boot.loader.systemd-boot.enable = true;
      # nix-serve
      services.nix-serve = {
        enable = true;
        secretKeyFile = config.age.secrets.cache.path;
      };
      networking.firewall.enable = false;
      # SSH
      services.sshd.enable = true;
      users.users.root.openssh = { inherit authorizedKeys; };
      # Web server
      services.nginx.virtualHosts.${domain} = {
        forceSSL = true;
        enableACME = true;
        locations."/".extraConfig = ''
          proxy_pass http://localhost:${config.services.nix-serve.port};
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        '';
      };
      # beesd
      services.beesd.filesystems = {
        root = {
          spec = "/";
          hashTableSizeMB = 256;
          extraOptions = [ "--loadavg-target" "2" ];
        };
      };
      # disko
      disko.devices = {
        disk = {
          vdb = {
            type = "disk";
            device = builtins.elemAt disks 0;
            content = {
              type = "gpt";
              partitions = {
                ESP = {
                  priority = 1;
                  name = "ESP";
                  start = "1M";
                  end = "128M";
                  type = "EF00";
                  content = {
                    type = "filesystem";
                    format = "vfat";
                    mountpoint = "/boot";
                  };
                };
                root = {
                  size = "100%";
                  content = {
                    type = "btrfs";
                    extraArgs = [
                      "--label" "root"
                      "-f" # Override existing partition
                    ]; 
                    # Subvolumes must set a mountpoint in order to be mounted,
                    # unless their parent is mounted
                    subvolumes = {
                      # Subvolume name is different from mountpoint
                      "/rootfs" = {
                        mountpoint = "/";
                      };
                      # Parent is not mounted so the mountpoint must be set
                      "/nix" = {
                        mountOptions = [ "compress=zstd" "noatime" ];
                        mountpoint = "/nix";
                      };
                      # Subvolume for the swapfile
                      "/swap" = {
                        mountpoint = "/.swapvol";
                        swap.swapfile.size = "1024M";
                      };
                    };

                    mountpoint = "/partition-root";
                  };
                };
              };
            };
          };
        };
      };
    };
in
rec {
  modules = { inherit cache-module; };

  packages.cache-vm = mkSystem {
    modules = with modules; [
      cache-module
      ({ config, ... }:
        let inherit (config.services.nix-serve) port; in
        {
          imports = [
            logger
            # TODO: modulesPath should be available
            # (modulesPath + "/profiles/qemu-guest.nix")
            host-keys
          ];
          host-keys.source = "${home}/.ssh";
          virtualisation.forwardPorts = [
            { from = "host"; host.port = 2222; guest.port = 22; }
            { from = "host"; host.port = port; guest.port = port; }
          ];
        })
    ];
    format = "vm-nogui";
  };

  machines.cache-vultr = mkSystem {
    modules = with modules; [
      cache-module
      ({ modulesPath, lib, ... }: {
        _module.args.disks = [ "/dev/vda" ];
        imports = [
          (modulesPath + "/profiles/qemu-guest.nix")
          (modulesPath + "/installer/scan/not-detected.nix")
        ];
        networking.hostName = "cache-vultr";
        boot = {
          loader.efi.canTouchEfiVariables = true;
          initrd.availableKernelModules = [ "ahci" "xhci_pci" "virtio_pci" "sr_mod" "virtio_blk" ];
        };
        environment.systemPackages = map lib.lowPrio [
          pkgs.curl
          pkgs.gitMinimal
        ];
      })
    ];
  };
}
@github-actions github-actions bot added help wanted Extra attention is needed todo labels Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed todo
Projects
None yet
Development

No branches or pull requests

0 participants