nix-dotfiles/flake.nix

70 lines
2.3 KiB
Nix
Raw Normal View History

2023-11-19 19:31:04 -08:00
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
2024-04-09 00:00:42 -07:00
home-manager.url = "github:nix-community/home-manager";
hyprland.url = "git+https://github.com/hyprwm/Hyprland";
hyprland-contrib.url = "github:hyprwm/contrib";
2024-04-07 00:33:49 -07:00
sops-nix.url = "github:Mic92/sops-nix";
2024-02-16 21:32:55 -08:00
ags.url = "github:Aylur/ags";
2024-04-09 00:00:42 -07:00
aagl.url = "github:ezKEa/aagl-gtk-on-nix";
2023-11-19 19:31:04 -08:00
};
outputs = { self, home-manager, nixpkgs, ... }@inputs: let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
fs = pkgs.lib.fileset;
st = pkgs.lib.strings;
hostConfig = extraModules: nixpkgs.lib.nixosSystem {
2024-03-17 16:50:13 -07:00
specialArgs = { inherit inputs; };
system = system;
modules = [
2024-04-07 17:08:48 -07:00
./nixosModules
] ++ extraModules;
2023-11-19 19:31:04 -08:00
};
hosts = let
hostFilter = { name, ...}: name == "host.nix";
hostPaths = fs.toList (fs.fileFilter hostFilter ./hosts);
# Assumes dir structure is start_of_path/hosts/hostname/host.nix
extractHostName = path: builtins.unsafeDiscardStringContext (
st.removeSuffix "/host.nix" (
builtins.elemAt (st.splitString "/hosts/" path) 1
)
);
in builtins.listToAttrs (map (path: {
value = path;
name = extractHostName path;
}) hostPaths);
userConfig = extraModules: home-manager.lib.homeManagerConfiguration {
inherit pkgs;
extraSpecialArgs = { inherit inputs; };
modules = [
2024-04-14 05:40:02 -07:00
./hmModules
] ++ extraModules;
2023-11-19 19:03:46 -08:00
};
users = let
userFilter = { name, ...}: name == "user.nix";
userPaths = fs.toList (fs.fileFilter userFilter ./hosts);
in builtins.listToAttrs (map (path: let
dirsAndFiles = st.splitString "/" path;
dAFLength = builtins.length dirsAndFiles;
# Assumes dir structure is start_of_path/hosts/hostname/users/username/user.nix
hostname = builtins.unsafeDiscardStringContext (
builtins.elemAt dirsAndFiles (dAFLength - 4));
username = builtins.unsafeDiscardStringContext (
builtins.elemAt dirsAndFiles (dAFLength - 2));
in {
name = username + "@" + hostname;
value = path;
}
) userPaths);
in {
nixosConfigurations = builtins.mapAttrs (name: path: hostConfig [ path ]) hosts;
homeConfigurations = builtins.mapAttrs (name: path: userConfig [ path ]) users;
2023-11-19 19:31:04 -08:00
};
}