refactor: Tidy flake.nix and break it apart

This commit is contained in:
Madeleine Sydney
2024-12-30 19:24:07 -07:00
parent 2e3b262d05
commit c6170d5284
6 changed files with 164 additions and 97 deletions

View File

@@ -0,0 +1,26 @@
{ ... }@inputs:
let users = builtins.readDir ../users;
mkUser = username: _: {
imports = [
(import ../users/${username}/default.nix).homeConfiguration
inputs.self.homeManagerModules.default
inputs.sops-nix.homeManagerModules.sops
inputs.impermanence.homeManagerModules.impermanence
# Directory name should always match username.
({ ... }: { home.username = username; })
({ lib, ... }: {
nix = {
settings.experimental-features =
lib.mkDefault
[ "nix-command" "flakes" ];
};
})
];
};
in
builtins.mapAttrs mkUser users

View File

@@ -0,0 +1,59 @@
{ nixpkgs, ... }@inputs:
let
# Given a hostName, return a NixOS module defining each user specified by
# `sydnix.users.users`.
mkHostUsers = hostName: { config, lib, ... }: {
users.users =
(lib.mapAttrs
# Only import the user's system configuration. The code responsible for
# importing the user's home configuration lives in
# outputs/homeConfigurations.
(username: _: (import ../users/${username}).systemConfiguration)
# The directory users/ hosts a 'universe' of user profiles, which
# specific hosts may select any subset of, by setting the option
# `sydnix.users.users` to a list of choice usernames.
(lib.filterAttrs
(username: _: builtins.elem username config.sydnix.users.users)
(builtins.readDir ../users)));
};
mkHost = hostName: nixpkgs.lib.nixosSystem {
specialArgs = inputs;
system = import ../hosts/${hostName}/system.nix;
# TODO: This is very ad-hoc, and I don't like it. Organise this better.
modules = [
../hosts/${hostName}/configuration.nix
inputs.self.nixosModules.default
inputs.disko.nixosModules.disko
inputs.sops-nix.nixosModules.sops
inputs.impermanence.nixosModules.impermanence
# Directory name should always match host name.
({ ... }: { networking.hostName = hostName; })
(mkHostUsers hostName)
# home-manager configuration.
inputs.home-manager.nixosModules.home-manager
({ config, lib, self, ... }: {
home-manager.useGlobalPkgs = true;
home-manager.users =
lib.filterAttrs
(username: _: builtins.elem username config.sydnix.users.users)
self.homeConfigurations;
home-manager.extraSpecialArgs = {
utils = import ../lib/utils.nix {
inherit config lib;
pkgs = nixpkgs;
};
};
})
];
};
in
builtins.mapAttrs (dirName: _: mkHost dirName) (builtins.readDir ../hosts)