Add extra function for lib, and refactor with loadImports

This commit is contained in:
ulic-youthlic 2025-07-11 21:04:42 +08:00
parent 317a2b4a28
commit 2c997cddce
Signed by: youthlic
GPG key ID: 63E86C3C14A0D721
28 changed files with 111 additions and 204 deletions

View file

@ -2,35 +2,45 @@
description = "A simple NixOS flakes";
outputs = {
nixpkgs,
flake-parts,
flake-utils,
home-manager,
treefmt-nix,
nixpkgs,
...
} @ inputs:
flake-parts.lib.mkFlake {inherit inputs;} {
} @ inputs: let
nixpkgs-lib = nixpkgs.lib;
lib = nixpkgs-lib.extend (import ./lib);
in
flake-parts.lib.mkFlake {
inherit inputs;
specialArgs = {
inherit lib;
rootPath = ./.;
};
} ({lib, ...}: {
systems = flake-utils.lib.defaultSystems;
imports = [
home-manager.flakeModules.home-manager
treefmt-nix.flakeModule
./flake
];
imports =
[
home-manager.flakeModules.home-manager
treefmt-nix.flakeModule
]
++ lib.youthlic.loadImports ./flake;
flake = {
inherit lib;
nix.settings = {
# substituters shared in home-manager and nixos configuration
substituters = let
cachix = x: "https://${x}.cachix.org";
in
nixpkgs.lib.flatten [
lib.flatten [
(cachix "nix-community")
"https://cache.nixos.org"
(cachix "cosmic")
];
};
};
};
});
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

View file

@ -1,10 +0,0 @@
{
imports = [
./nixos.nix
./home.nix
./templates.nix
./perSystem.nix
./deploy.nix
./overlays.nix
];
}

View file

@ -2,9 +2,9 @@
lib,
inputs,
self,
rootPath,
...
}: let
rootPath = ./..;
inherit (self) outputs;
homeModules =
(
@ -46,6 +46,11 @@
])
++ [
homeModules."${unixName}"
]
++ [
{
lib = {inherit (lib) youthlic;};
}
];
extraSpecialArgs = {
inherit

View file

@ -2,11 +2,10 @@
inputs,
lib,
self,
rootPath,
...
}: let
rootPath = ./..;
inherit (self) outputs;
inherit (inputs) nixpkgs;
in {
flake = {
nixosModules = {
@ -15,10 +14,10 @@ in {
};
nixosConfigurations = let
makeNixosConfiguration = hostName:
nixpkgs.lib.nixosSystem {
lib.nixosSystem {
modules = [(rootPath + "/nixos/configurations/${hostName}")];
specialArgs = {
inherit inputs outputs rootPath;
inherit inputs outputs rootPath lib;
};
};
in

View file

@ -2,9 +2,9 @@
self,
inputs,
lib,
rootPath,
...
}: let
rootPath = ./..;
inherit (self) outputs;
importWithArgs = lib.flip import {inherit inputs outputs;};
in {

View file

@ -1,6 +1,8 @@
{inputs, ...}: let
rootPath = ./..;
in {
{
inputs,
rootPath,
...
}: {
imports = [
(rootPath + "/treefmt.nix")
];
@ -12,7 +14,7 @@ in {
...
}: let
inherit (inputs) nixpkgs;
callPackages = lib.callPackagesWith (pkgs // {inherit callPackages inputs rootPath;});
callPackages = lib.callPackagesWith (pkgs // {inherit callPackages inputs rootPath lib;});
in {
_module.args.pkgs = import nixpkgs {
inherit system;

View file

@ -1,10 +1,9 @@
{
flake-parts-lib,
lib,
rootPath,
...
}: let
rootPath = ./..;
in {
}: {
options = {
flake = flake-parts-lib.mkSubmoduleOptions {
templates = lib.mkOption {

View file

@ -1,12 +1,11 @@
{
pkgs,
lib,
unixName,
config,
...
}: {
imports = [
./niri.nix
];
imports = lib.youthlic.loadImports ./.;
youthlic = {
xdg-dirs.enable = true;
programs = let

View file

@ -1,12 +1,11 @@
{
pkgs,
lib,
config,
unixName,
...
}: {
imports = [
./niri.nix
];
imports = lib.youthlic.loadImports ./.;
youthlic = {
xdg-dirs.enable = true;
programs = let

View file

@ -1,9 +1,9 @@
{pkgs, ...}: {
imports = [
./wallpaper.nix
./programs
./emails.nix
];
{
lib,
pkgs,
...
}: {
imports = lib.youthlic.loadImports ./.;
config = {
youthlic.programs = {
zoxide.enable = true;

View file

@ -1,22 +1,3 @@
{...}: {
imports = [
./openssh.nix
./niri
./wluma.nix
./helix.nix
./firefox.nix
./waybar.nix
./zed.nix
./alacritty
./ghostty.nix
./fuzzel.nix
./mpv.nix
./swaylock.nix
./thunderbird.nix
./chromium.nix
./foot
./swaync.nix
./espanso.nix
./waypaper.nix
];
{lib, ...}: {
imports = lib.youthlic.loadImports ./.;
}

View file

@ -1,11 +1,13 @@
{inputs, ...}: {
{
lib,
inputs,
...
}: {
imports =
(with inputs; [
niri-flake.homeModules.niri
stylix.homeManagerModules.stylix
chaotic.homeManagerModules.default
])
++ [
./nix.nix
];
++ (lib.youthlic.loadImports ./.);
}

View file

@ -1,14 +1,14 @@
{inputs, ...}: {
{
lib,
inputs,
...
}: {
imports =
(with inputs; [
sops-nix.homeManagerModules.sops
betterfox-nix.homeManagerModules.betterfox
])
++ [
./programs
./xdg-dirs.nix
./i18n
];
++ lib.youthlic.loadImports ./.;
config = {
programs.direnv = {

View file

@ -1,21 +1,3 @@
{...}: {
imports = [
./rustypaste-cli.nix
./atuin.nix
./bash.nix
./fish.nix
./kvm.nix
./starship
./gpg
./sops.nix
./git.nix
./helix
./jujutsu.nix
./yazi.nix
./zoxide.nix
./fzf.nix
./eza.nix
./ion.nix
./awscli.nix
];
{lib, ...}: {
imports = lib.youthlic.loadImports ./.;
}

17
lib/default.nix Normal file
View file

@ -0,0 +1,17 @@
final: _prev: {
youthlic = {
loadImports' = dir: f:
if (builtins.pathExists dir && (builtins.readFileType dir) == "directory")
then
with final;
pipe dir [
builtins.readDir
attrNames
(filter (name: name != "default.nix"))
f
(map (name: dir + "/${name}"))
]
else [];
loadImports = with final; flip youthlic.loadImports' (x: x);
};
}

View file

@ -1,6 +1,7 @@
{
inputs,
pkgs,
lib,
outputs,
...
}: {
@ -11,15 +12,9 @@
common-pc-laptop-ssd
])
++ [
./gui.nix
./hardware-configuration.nix
./stylix.nix
./users
./networking.nix
./disk-config.nix
outputs.nixosModules.gui
];
]
++ (lib.youthlic.loadImports ./.);
youthlic = {
users.deploy.enable = true;

View file

@ -1,20 +1,14 @@
{
pkgs,
lib,
outputs,
...
}: {
imports = [
./forgejo.nix
./networking.nix
./stylix.nix
./hardware-configuration.nix
./users
./disko-config.nix
./miniflux.nix
./radicle.nix
outputs.nixosModules.default
];
imports =
[
outputs.nixosModules.default
]
++ (lib.youthlic.loadImports ./.);
youthlic = {
home-manager = {

View file

@ -1,5 +1,6 @@
{
pkgs,
lib,
inputs,
outputs,
...
@ -13,21 +14,10 @@
common-pc-laptop-ssd
asus-battery
])
++ [
./users
./stylix.nix
./gui.nix
# Include the hardware related config
./hardware-configuration.nix
./networking.nix
./disk-config.nix
./hardware.nix
./specialisation/kde.nix
./specialisation/niri-hybrid.nix
outputs.nixosModules.gui
];
++ (with outputs; [
nixosModules.gui
])
++ (lib.youthlic.loadImports ./.);
youthlic = {
home-manager = {

View file

@ -0,0 +1,3 @@
{lib, ...}: {
imports = lib.youthlic.loadImports ./.;
}

View file

@ -5,10 +5,7 @@
}: let
cfg = config.youthlic.containers;
in {
imports = [
./forgejo.nix
./miniflux.nix
];
imports = lib.youthlic.loadImports ./.;
options = {
youthlic.containers = {
enable = lib.mkEnableOption "containers";

View file

@ -1,15 +1,3 @@
{
imports = [
./containers
./deploy
./nix.nix
./home.nix
./sops.nix
./i18n.nix
./gui
./programs
./hardware.nix
./virtualisation
./documentation.nix
];
{lib, ...}: {
imports = with lib; youthlic.loadImports' ./. (filter (name: name != "top-level"));
}

View file

@ -6,11 +6,7 @@
}: let
cfg = config.youthlic.gui;
in {
imports = [
./niri.nix
./cosmic.nix
./kde.nix
];
imports = with lib; youthlic.loadImports ./.;
options = {
youthlic.gui = {
enabled = lib.mkOption {

View file

@ -5,11 +5,7 @@
}: let
cfg = config.youthlic.programs.caddy;
in {
imports = [
./radicle-explorer.nix
./OuterWildsTextAdventure.nix
./garage.nix
];
imports = lib.youthlic.loadImports ./.;
options = {
youthlic.programs.caddy = {
enable = lib.mkEnableOption "caddy";

View file

@ -1,33 +1,3 @@
{...}: {
imports = [
./transfer-sh.nix
./rustypaste
./mautrix-telegram.nix
./caddy
./dae
./forgejo.nix
./kanata.nix
./nh.nix
./open-webui.nix
./openssh.nix
./postgresql.nix
./steam.nix
./tailscale.nix
./transmission.nix
./nix-ld.nix
./juicity
./miniflux.nix
./guix.nix
./asusd.nix
./owncast.nix
./minio.nix
./supergfxd.nix
./radicle.nix
./wshowkeys.nix
./bash.nix
./obs.nix
./sudo-rs.nix
./garage.nix
./nixvim
];
{lib, ...}: {
imports = lib.youthlic.loadImports ./.;
}

View file

@ -6,9 +6,7 @@
}: let
cfg = config.youthlic.programs.juicity;
in {
imports = [
./template.nix
];
imports = lib.youthlic.loadImports ./.;
options = {
youthlic.programs.juicity = {
client = {

View file

@ -5,7 +5,7 @@
}: let
cfg = config.youthlic.programs.nixvim;
in {
imports = [./option.nix];
imports = lib.youthlic.loadImports ./.;
options = {
youthlic.programs.nixvim = {
enable = lib.mkEnableOption "nixvim";

View file

@ -5,9 +5,7 @@
}: let
cfg = config.youthlic.programs.rustypaste;
in {
imports = [
./template.nix
];
imports = lib.youthlic.loadImports ./.;
options = {
youthlic.programs.rustypaste = {

View file

@ -1,6 +1,3 @@
{
imports = [
./kvm.nix
./waydroid.nix
];
{lib, ...}: {
imports = lib.youthlic.loadImports ./.;
}