NixOSConfig/flake.nix

153 lines
4.8 KiB
Nix
Raw Normal View History

2023-12-01 11:29:39 +00:00
{
2024-05-01 12:00:39 +00:00
description = "NixOS Machine Configurations by manuth";
2023-12-01 11:29:39 +00:00
2024-05-01 12:00:39 +00:00
inputs = {
nixpkgs.url = "nixpkgs/38c01297e7ec11f7b9e3f2cae7d6fcec6cc767ec";
2024-05-01 16:14:25 +00:00
flake-utils.url = "github:numtide/flake-utils?ref=b1d9ab70662946ef0850d488da1c9019f3a9752a";
2024-05-09 00:06:59 +00:00
home-manager = {
url = "github:nix-community/home-manager?ref=6e277d9566de9976f47228dd8c580b97488734d4";
inputs.nixpkgs.follows = "nixpkgs";
};
2024-05-01 23:08:45 +00:00
sops-nix.url = "github:Mic92/sops-nix?ref=f1b0adc27265274e3b0c9b872a8f476a098679bd";
2024-05-01 12:00:39 +00:00
};
2023-12-01 11:29:39 +00:00
2024-05-09 00:06:59 +00:00
outputs = { self, nixpkgs, flake-utils, home-manager, sops-nix }: (
2024-05-08 22:50:42 +00:00
let
inherit (nixpkgs) lib;
2024-05-08 22:59:02 +00:00
defaultMachine = {
system = "x86_64-linux";
config = { pkgs, ... }: {
dualBoot = false;
timeZone = null;
keyMap = "us";
keyboardLayout = "us";
localeSettings = { };
users = { };
};
};
2024-05-10 23:19:06 +00:00
machineDefinitions = {
2024-05-08 22:59:02 +00:00
nixos.config = { ... }: {
};
};
machines = builtins.mapAttrs (
name: machineDefinition:
defaultMachine // machineDefinition // {
config = { callPackage, ... }:
((callPackage defaultMachine.config { }) // (callPackage machineDefinition.config { }));
})
machineDefinitions;
tryFiles = import ./lib/utils/try-files.nix { inherit lib; };
2024-05-08 22:50:42 +00:00
in
flake-utils.lib.eachDefaultSystem (
system:
2024-05-10 23:28:15 +00:00
let
pkgs = import nixpkgs {
inherit system;
config = {};
2024-05-01 23:08:45 +00:00
2024-05-10 23:28:15 +00:00
overlays = [
sops-nix.overlays.default
2024-05-08 22:50:42 +00:00
];
2024-05-10 23:28:15 +00:00
};
in {
devShells.default = pkgs.mkShellNoCC (
with pkgs;
{
sopsPGPKeyDirs = [
"${toString ./.}/keys/hosts"
"${toString ./.}/keys/users"
];
2024-05-01 23:08:45 +00:00
2024-05-10 23:28:15 +00:00
packages = [
nixos-rebuild
sops
sops-import-keys-hook
ssh-to-age
ssh-to-pgp
];
2024-05-01 23:08:45 +00:00
2024-05-10 23:28:15 +00:00
nativeBuildInputs = [
sops-import-keys-hook
];
});
}
2024-05-08 22:50:42 +00:00
) // {
nixosConfigurations =
builtins.mapAttrs (
2024-05-11 17:40:01 +00:00
hostname: { system, config }@machine: nixpkgs.lib.nixosSystem {
2024-05-08 22:50:42 +00:00
inherit system;
2024-05-01 16:58:39 +00:00
2024-05-08 22:50:42 +00:00
modules = [
(
{ pkgs, ... }: {
2024-05-11 18:28:41 +00:00
config = {
_module.args = {
machine = machine // {
name = hostname;
config = (pkgs.callPackage config { });
};
2024-05-11 17:40:01 +00:00
};
2024-05-11 18:28:41 +00:00
home-manager.sharedModules = [
sops-nix.homeManagerModules.sops
];
2024-05-08 22:50:42 +00:00
};
})
2024-05-09 00:06:59 +00:00
home-manager.nixosModules.home-manager
2024-05-08 22:50:42 +00:00
sops-nix.nixosModules.sops
./lib/configuration.nix
2024-05-10 23:19:06 +00:00
(tryFiles [ ./lib/machines/${hostname}.nix ] ./lib/hardware/base.nix)
2024-05-08 22:50:42 +00:00
];
2024-05-08 22:59:02 +00:00
})
2024-05-10 23:19:06 +00:00
machines;
2024-05-08 22:59:02 +00:00
homeConfigurations =
let
lib = nixpkgs.lib;
in
lib.attrsets.concatMapAttrs (
2024-05-10 23:19:06 +00:00
hostname: machine:
2024-05-08 22:59:02 +00:00
let
pkgs = import nixpkgs {
inherit (machine) system;
};
machineConfig = pkgs.callPackage machine.config { };
2024-05-08 22:59:02 +00:00
in
lib.attrsets.concatMapAttrs (
username: user: {
2024-05-09 00:06:59 +00:00
"${username}@${hostname}" = home-manager.lib.homeManagerConfiguration {
2024-05-08 22:59:02 +00:00
modules =
let
2024-05-11 18:24:37 +00:00
getUserConfig = pkgs.callPackage (import ./lib/utils/user-config.nix);
userConfigPath = getUserConfig { inherit hostname username; };
2024-05-08 22:59:02 +00:00
in [
(
{ pkgs, ... }: {
config._module.args = {
2024-05-11 18:04:14 +00:00
machine = machine // {
2024-05-11 17:40:01 +00:00
name = hostname;
config = machineConfig;
};
2024-05-11 18:30:29 +00:00
user = {
2024-05-11 18:11:35 +00:00
name = username;
} // user;
2024-05-08 22:59:02 +00:00
};
})
sops-nix.homeManagerModules.sops
] ++ (lib.optional (userConfigPath != null) userConfigPath);
};
})
machineConfig.users)
2024-05-08 22:59:02 +00:00
machines;
});
2023-12-01 11:29:39 +00:00
}