johbo / k0s-nix

Nix Flake to support k0s in NixOS
Other
12 stars 4 forks source link

Possible old package references?? #6

Closed vangourd closed 1 month ago

vangourd commented 1 month ago

I am new to Nix and I think I'm realizing I cannot solve this on my own with my knowledge level.

I think I'm receiving the following error possible because some of the packages I'm using from this k0s flake are out of date.

Now I've tried running nix flake update but that's not resolving it and I've also tried. https://discourse.nixos.org/t/solved-bzimage-causes-an-error-when-running-sudo-nixos-rebuild-switch-24-05/49220

Which every description I find online recommends sudo nix-collect-garbage -d which also does not work.

If I remove the statements I have related to k0s then I get zero problems with my flake and I can rebuild without issue.

sudo nixos-rebuild switch --flake /etc/nixos#default --show-trace
building the system configuration...
failed to synthesize: failed to canonicalize /nix/store/a0x81aiwqzr8xr7m093iqy3g8yhk3cpg-nixos-system-nixos-24.11.20240723.dc14ed9/kernel-modules/bzImage: No such file or directory (os error 2)

I think I have things setup correctly in my flake.nix

Here's my flake.nix

{
  description = "A basic NixOS configuration";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    k0s = {
      url = "github:johbo/k0s-nix/main";
      inputs.nixpkgs.follows =  "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, k0s }: {
    nixosConfigurations = {
      default = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ({
              nixpkgs.system = "x86_64-linux";
              nixpkgs.pkgs = import nixpkgs {
                system = "x86_64-linux";
                overlays = [
                  k0s.overlays.default
                ];
              };
          })
          k0s.nixosModules.default
          ({ pkgs, ... }:
          {
            imports = [ 
              ./hardware-configuration.nix
            ];

            # Use the systemd-boot EFI boot loader.
            boot.loader.systemd-boot.enable = true;
            boot.loader.efi.canTouchEfiVariables = true;

            # Set your time zone.
            time.timeZone = "America/New_York";

            # Enable NetworkManager for networking
            networking.networkmanager.enable = true;

            # Disable wpa_supplicant to avoid conflicts with NetworkManager
            networking.wireless.enable = false;

            # Enable the NixOS channel
            system.autoUpgrade.channel = "nixos https://nixos.org/channels/nixos-24.05-small";

            nix.settings.experimental-features = [ "nix-command" "flakes" ];

            # List packages installed in system profile.
            environment.systemPackages = with pkgs; [
              neovim
              wget
              git
            ];
            environment.variables.EDITOR = "vim";

            # Enable the OpenSSH daemon.
            services.openssh = {
              enable = true;
              settings.PasswordAuthentication = false;
            };

            # Open ports in the firewall.
            networking.firewall.allowedTCPPorts = [ 22 ];

            # This value determines the NixOS release from which the default
            # settings for stateful data, like file locations and database versions
            # on your system were taken.
            system.stateVersion = "24.05"; # Did you read the comment?

          })
          ({pkgs, ... }: {
              boot.isContainer = true;

              services.k0s = {
                enable = true;

                role = "controller";

                # The first controller to bring up does not have a join token,
                # it has to be flagged with "isLeader".
                # isLeader = true;

                apiAddress = "192.0.2.1";
                apiSans = [
                  "192.0.2.1"
                  "192.0.2.2"
                ];
              };
            })
        ];
      };
    };
  };
}
vangourd commented 1 month ago

I tried removing boot.isContainer = true; because this is a VM, and will be bare-metal. Still didn't resolve this issue.

vangourd commented 1 month ago

Ah I figured out my issue at the least.

So I forked this repo. https://github.com/vangourd/k0s-nix. Then I ran nix flake update. Then I pointed my flake to my own github repository (probably a good idea anyway).

Then I ran sudo nix-collect-garbage -d remove the old references. And voila it seems to be working now.

I'm curious on with the intended behavior of lock file whether or not this repo could be adapted in a way that would make it easy to reference in others flakes. However because of security I think it probably is best to audit the config yourself, then fork it. One can simply run nix flake update on their own then.

Maybe I'm not even thinking about it appropriately with flakes being entry points as opposed to flakes all the way down.

Perhaps like referenced in https://github.com/johbo/k0s-nix/issues/5 a better way of composing the config would mean you aren't tying yourself to the package versions in this flake.