NixOS deployment for LinuxLab
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
3.4 KiB

1 week ago
  1. {
  2. inputs = {
  3. nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
  4. nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
  5. flake-utils.url = "github:numtide/flake-utils";
  6. git-hooks = {
  7. url = "github:cachix/git-hooks.nix";
  8. inputs.nixpkgs.follows = "nixpkgs";
  9. };
  10. colmena = {
  11. url = "github:zhaofengli/colmena";
  12. inputs.nixpkgs.follows = "nixpkgs";
  13. inputs.flake-utils.follows = "flake-utils";
  14. };
  15. disko = {
  16. url = "github:nix-community/disko";
  17. inputs.nixpkgs.follows = "nixpkgs";
  18. };
  19. nixago = {
  20. url = "github:jmgilman/nixago";
  21. inputs.nixpkgs.follows = "nixpkgs";
  22. inputs.flake-utils.follows = "flake-utils";
  23. };
  24. sops = {
  25. url = "github:Mic92/sops-nix";
  26. inputs.nixpkgs.follows = "nixpkgs";
  27. };
  28. ldap-sync = {
  29. type = "git";
  30. url = "https://gogs.informatik.hs-fulda.de/fooker/ldap-sync.git";
  31. flake = false;
  32. };
  33. };
  34. outputs =
  35. { self
  36. , nixpkgs
  37. , flake-utils
  38. , colmena
  39. , git-hooks
  40. , nixago
  41. , ...
  42. }@inputs:
  43. let
  44. # List of all machine names as defined in the machines directory
  45. machines = builtins.attrNames (builtins.readDir ./machines);
  46. in
  47. {
  48. colmena = {
  49. meta = {
  50. nixpkgs = import nixpkgs {
  51. system = "x86_64-linux";
  52. };
  53. specialArgs = {
  54. inherit inputs;
  55. };
  56. };
  57. defaults = {
  58. imports = [
  59. inputs.disko.nixosModules.disko
  60. inputs.sops.nixosModules.sops
  61. ./shared
  62. ];
  63. deployment.replaceUnknownProfiles = false;
  64. };
  65. "client" = ./client;
  66. } // (builtins.listToAttrs (builtins.map
  67. (name: {
  68. inherit name;
  69. value = ./machines/${name};
  70. })
  71. machines));
  72. } // flake-utils.lib.eachDefaultSystem (system: {
  73. checks = {
  74. pre-commit = git-hooks.lib.${system}.run {
  75. src = ./.;
  76. hooks = {
  77. nixpkgs-fmt.enable = true;
  78. statix.enable = true;
  79. shellcheck.enable = true;
  80. };
  81. };
  82. };
  83. devShells.default =
  84. let
  85. pkgs = nixpkgs.legacyPackages.${system};
  86. sops-config = nixago.lib.${system}.make {
  87. data = (pkgs.callPackage ./sops-config.nix {
  88. inherit machines;
  89. }).config;
  90. output = ".sops.yaml";
  91. format = "yaml";
  92. };
  93. in
  94. pkgs.mkShell {
  95. buildInputs =
  96. self.checks.${system}.pre-commit.enabledPackages ++
  97. [ colmena.packages.${system}.colmena ] ++
  98. (with pkgs; [
  99. bash
  100. gitAndTools.git
  101. sops
  102. age
  103. openssh
  104. ssh-to-age
  105. ]);
  106. shellHook = ''
  107. ${self.checks.${system}.pre-commit.shellHook}
  108. ${sops-config.shellHook}
  109. '';
  110. };
  111. packages.disks =
  112. let
  113. pkgs = nixpkgs.legacyPackages.${system};
  114. hive = colmena.lib.makeHive self.outputs.colmena;
  115. in pkgs.linkFarm "linuxlab-testing" (builtins.mapAttrs
  116. (_: node: node.config.system.build.diskoImages)
  117. hive.nodes);
  118. });
  119. nixConfig = {
  120. extra-substituters = [
  121. "https://colmena.cachix.org"
  122. ];
  123. extra-trusted-public-keys = [
  124. "colmena.cachix.org-1:7BzpDnjjH8ki2CT3f6GdOk7QAzPOl+1t3LvTLXqYcSg="
  125. ];
  126. };
  127. }