nixos configurations
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.

107 lines
3.2 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. {
  2. description = "Nixos config flake";
  3. # Package sources.
  4. inputs = {
  5. nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
  6. nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
  7. disko = {
  8. url = "github:nix-community/disko";
  9. inputs.nixpkgs.follows = "nixpkgs";
  10. };
  11. home-manager = {
  12. url = "github:nix-community/home-manager/release-23.11";
  13. inputs.nixpkgs.follows = "nixpkgs";
  14. };
  15. home-manager-unstable = {
  16. url = "github:nix-community/home-manager";
  17. inputs.nixpkgs.follows = "nixpkgs";
  18. };
  19. };
  20. # Flake outputs, NixOS and Home Configurations.
  21. outputs = inputs@{ self, ... }:
  22. let
  23. # Load settings.nix or the default if not exists.
  24. settings = (if (builtins.pathExists ./settings.nix)
  25. then
  26. (import ./settings.nix)
  27. else
  28. (import ./settings-default.nix)
  29. );
  30. # Based on loaded settings, set the nixpkgs version.
  31. nixpkgs = (if (settings.packages == "stable")
  32. then
  33. inputs.nixpkgs
  34. else
  35. inputs.nixpkgs-unstable
  36. );
  37. # Based on loaded settings, set the home-manager version.
  38. home-manager = (if (settings.packages == "stable")
  39. then
  40. inputs.home-manager
  41. else
  42. inputs.home-manager-unstable
  43. );
  44. # Setup an overlay for unstable packages to include on stable environments.
  45. overlay-unstable = final: prev: {
  46. unstable = import inputs.nixpkgs-unstable {
  47. system = settings.system;
  48. config.allowUnfree = true;
  49. };
  50. };
  51. # Setup the main packages config with the overlays.
  52. pkgs = (import nixpkgs {
  53. system = settings.system;
  54. config = {
  55. allowUnfree = true;
  56. allowUnfreePredicate = (_: true);
  57. };
  58. overlays = [ overlay-unstable ];
  59. });
  60. # Function to configure a system with our defaults.
  61. mkSystem = config: nixpkgs.lib.nixosSystem {
  62. system = settings.system;
  63. specialArgs = {
  64. inherit inputs;
  65. inherit pkgs;
  66. inherit settings;
  67. };
  68. modules = [
  69. config
  70. inputs.disko.nixosModules.disko
  71. home-manager.nixosModules.default
  72. ];
  73. };
  74. # Function to configure home-manager for a user.
  75. mkHome = config: home-manager.lib.homeManagerConfiguration {
  76. inherit pkgs;
  77. extraSpecialArgs = {
  78. inherit inputs;
  79. inherit settings;
  80. };
  81. modules = [ config ];
  82. };
  83. in {
  84. # NixOS configurations, in most cases we use default with a profile.
  85. # Any host that needs specific configurations separate from what is included by default,
  86. # will need its own configuration for its hostname.
  87. nixosConfigurations.default = mkSystem ./hosts/default/configuration.nix;
  88. nixosConfigurations.tama = mkSystem ./hosts/tama/configuration.nix;
  89. # Home manager configurations, we do the main user from the configuration and root.
  90. homeConfigurations = {
  91. ${settings.user.name} = mkHome ./users/main-user.nix;
  92. "root" = mkHome ./users/root.nix;
  93. };
  94. };
  95. }