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.

165 lines
3.7 KiB

1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
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. clients = builtins.attrNames (import ./clients.nix);
  47. in
  48. {
  49. colmena = {
  50. meta = {
  51. nixpkgs = import nixpkgs {
  52. system = "x86_64-linux";
  53. };
  54. specialArgs = {
  55. inherit inputs;
  56. };
  57. };
  58. defaults = {
  59. imports = [
  60. inputs.disko.nixosModules.disko
  61. inputs.sops.nixosModules.sops
  62. ./shared
  63. ];
  64. deployment.replaceUnknownProfiles = false;
  65. };
  66. }
  67. # Machines
  68. // (builtins.listToAttrs (builtins.map
  69. (name: {
  70. inherit name;
  71. value = ./machines/${name};
  72. })
  73. machines))
  74. # Clients
  75. // (builtins.listToAttrs (builtins.map
  76. (id: {
  77. name = "client-${id}";
  78. value = (import ./client) id;
  79. })
  80. clients))
  81. ;
  82. } // flake-utils.lib.eachDefaultSystem (system: {
  83. checks = {
  84. pre-commit = git-hooks.lib.${system}.run {
  85. src = ./.;
  86. hooks = {
  87. nixpkgs-fmt.enable = true;
  88. statix.enable = true;
  89. shellcheck.enable = true;
  90. };
  91. };
  92. };
  93. devShells.default =
  94. let
  95. pkgs = nixpkgs.legacyPackages.${system};
  96. sops-config = nixago.lib.${system}.make {
  97. data = (pkgs.callPackage ./sops-config.nix {
  98. inherit machines;
  99. }).config;
  100. output = ".sops.yaml";
  101. format = "yaml";
  102. };
  103. in
  104. pkgs.mkShell {
  105. buildInputs =
  106. self.checks.${system}.pre-commit.enabledPackages ++
  107. [ colmena.packages.${system}.colmena ] ++
  108. (with pkgs; [
  109. bash
  110. gitAndTools.git
  111. sops
  112. age
  113. openssh
  114. ssh-to-age
  115. ]);
  116. shellHook = ''
  117. ${self.checks.${system}.pre-commit.shellHook}
  118. ${sops-config.shellHook}
  119. '';
  120. };
  121. packages.disks =
  122. let
  123. pkgs = nixpkgs.legacyPackages.${system};
  124. hive = colmena.lib.makeHive self.outputs.colmena;
  125. in
  126. pkgs.linkFarm "linuxlab-testing" (builtins.mapAttrs
  127. (_: node: node.config.system.build.diskoImages)
  128. hive.nodes);
  129. });
  130. nixConfig = {
  131. extra-substituters = [
  132. "https://colmena.cachix.org"
  133. ];
  134. extra-trusted-public-keys = [
  135. "colmena.cachix.org-1:7BzpDnjjH8ki2CT3f6GdOk7QAzPOl+1t3LvTLXqYcSg="
  136. ];
  137. };
  138. }