Convert to flake-parts & easy-hosts. Users broke

convert to using flake-parts and easy-hosts for the flake system. This
allows me to remove my poor file-system based code and replace it with
the code done in easy-hosts. Which also has good knock-on effects.

This change factors users out of hosts, which is probably a good change
since users aren't a nixos-module, but aren't completely untangled
either.

I'm going to leave users broken for a minute as I decide exactly how I
want to handle them.
This commit is contained in:
Julia Lange 2025-11-17 09:05:48 -08:00
parent b416affd1f
commit 823c6d0738
Signed by: Julia
SSH key fingerprint: SHA256:5DJcfxa5/fKCYn57dcabJa2vN2e6eT0pBerYi5SUbto
9 changed files with 68 additions and 82 deletions

149
flake.nix
View file

@ -1,94 +1,79 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = with inputs; [
easy-hosts.flakeModule
# home-manager.flakeModules.home-manager
];
home-manager.url = "github:nix-community/home-manager";
systems = [ "x86-64-linux" ];
easy-hosts = {
autoConstruct = true;
path = ./hosts;
easy-hosts.onlySystem = "x86-64-linux";
lix-module.url = "https://git.lix.systems/lix-project/nixos-module/archive/2.91.1-2.tar.gz";
shared = {
modules = [
inputs.lix-module.nixosModules.default
./nixModules
];
};
};
hyprland.url = "git+https://github.com/hyprwm/Hyprland";
hyprland-contrib.url = "github:hyprwm/contrib";
niri.url = "github:sodiboo/niri-flake";
sops-nix.url = "github:Mic92/sops-nix";
ags.url = "github:Aylur/ags";
aagl.url = "github:ezKEa/aagl-gtk-on-nix";
# flake = {
# homeConfigurations = {};
# homeModules = { my-modules = ./hmModules; };
# };
};
outputs = { self, home-manager, nixpkgs, lix-module, ... }@inputs: let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
fs = pkgs.lib.fileset;
st = pkgs.lib.strings;
as = pkgs.lib.attrsets;
inputs = {
# Save data with this url. Source:
# at://did:plc:mojgntlezho4qt7uvcfkdndg/app.bsky.feed.post/3loogwsoqok2w
# cid: bafyreidhuuxs3cuabneygtxir65hnd7hvy4hwj5rwrylpwmp7jhxciasve
nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz";
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);
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);
userConfig = usernameAtHostname: userpath: home-manager.lib.homeManagerConfiguration {
inherit pkgs;
extraSpecialArgs = {
inherit inputs;
inherit usernameAtHostname;
};
modules = [
./hmModules
userpath
];
home-manager = {
type = "github";
owner = "nix-community";
repo = "home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
hostConfig = hostname: hostpath: nixpkgs.lib.nixosSystem {
specialArgs = let
hostFilteredUsers = as.filterAttrs (
name: value: let
userHostname = builtins.elemAt (st.splitString "@" name) 1;
in userHostname == hostname
) users;
hostUsers = as.mapAttrsToList (
name: value: builtins.elemAt (st.splitString "@" name) 0
) hostFilteredUsers;
in {
inherit inputs;
inherit hostname;
"usernameList" = hostUsers;
};
modules = [
./nixosModules
hostpath
];
flake-parts = {
type = "github";
owner = "hercules-ci";
repo = "flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
easy-hosts = {
type = "github";
owner = "tgirlcloud";
repo = "easy-hosts";
};
lix = {
url = "https://git.lix.systems/lix-project/lix/archive/main.tar.gz";
flake = false;
};
lix-module = {
url = "https://git.lix.systems/lix-project/nixos-module/archive/main.tar.gz";
inputs.nixpkgs.follows = "nixpkgs";
inputs.lix.follows = "lix";
};
niri = {
type = "github";
owner = "sodiboo";
repo = "niri-flake";
inputs.nixpkgs.follows = "nixpkgs";
};
sops-nix = {
type = "github";
owner = "Mic92";
repo = "sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
in {
nixosConfigurations = builtins.mapAttrs (name: path: hostConfig name path) hosts;
homeConfigurations = builtins.mapAttrs (name: path: userConfig name path) users;
};
}