flake.nix 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. {
  2. inputs = {
  3. nixpkgs.url = "nixpkgs/nixos-unstable";
  4. nixos-generators = {
  5. url = "github:nix-community/nixos-generators";
  6. inputs.nixpkgs.follows = "nixpkgs";
  7. };
  8. };
  9. outputs = { self, nixpkgs, nixos-generators, ... }: {
  10. packages.x86_64-linux = {
  11. qcow2 = nixos-generators.nixosGenerate {
  12. system = "x86_64-linux";
  13. modules = [
  14. ({config, lib, modulesPath, pkgs, ...}: {
  15. virtualisation.docker.enable = true;
  16. environment.systemPackages = with pkgs; [
  17. docker-compose
  18. bash
  19. sudo
  20. coreutils
  21. ];
  22. systemd.services.my-docker-compose = {
  23. script = ''
  24. ${pkgs.coreutils}/bin/chmod -R 0777 /data
  25. ${pkgs.docker-compose}/bin/docker-compose -f /data/docker-compose.yml up
  26. '';
  27. wantedBy = ["multi-user.target"];
  28. # If you use podman
  29. #after = ["podman.service" "podman.socket"];
  30. # If you use docker
  31. after = ["docker.service" "docker.socket"];
  32. requires = ["docker.service" "docker.socket"];
  33. };
  34. system.build.qcow = lib.mkForce (import "${toString modulesPath}/../lib/make-disk-image.nix" {
  35. inherit lib config pkgs;
  36. diskSize = 30720;
  37. format = "qcow2";
  38. partitionTableType = "hybrid";
  39. contents = [
  40. {source = ./.; target = "/data";}
  41. ];
  42. });
  43. services.openssh = {
  44. enable = true;
  45. settings = {
  46. # require public key authentication for better security
  47. PasswordAuthentication = false;
  48. KbdInteractiveAuthentication = false;
  49. PermitRootLogin = "yes";
  50. };
  51. };
  52. users.users."root".openssh.authorizedKeys.keyFiles = [
  53. ./ssh/generated.pub
  54. ];
  55. system.stateVersion = "23.11";
  56. })
  57. ];
  58. format = "qcow";
  59. };
  60. };
  61. };
  62. }