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"; description = "A simple NixOS flakes";
outputs = { outputs = {
nixpkgs,
flake-parts, flake-parts,
flake-utils, flake-utils,
home-manager, home-manager,
treefmt-nix, treefmt-nix,
nixpkgs,
... ...
} @ inputs: } @ inputs: let
flake-parts.lib.mkFlake {inherit inputs;} { 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; systems = flake-utils.lib.defaultSystems;
imports = [ imports =
home-manager.flakeModules.home-manager [
treefmt-nix.flakeModule home-manager.flakeModules.home-manager
treefmt-nix.flakeModule
./flake ]
]; ++ lib.youthlic.loadImports ./flake;
flake = { flake = {
inherit lib;
nix.settings = { nix.settings = {
# substituters shared in home-manager and nixos configuration # substituters shared in home-manager and nixos configuration
substituters = let substituters = let
cachix = x: "https://${x}.cachix.org"; cachix = x: "https://${x}.cachix.org";
in in
nixpkgs.lib.flatten [ lib.flatten [
(cachix "nix-community") (cachix "nix-community")
"https://cache.nixos.org" "https://cache.nixos.org"
(cachix "cosmic") (cachix "cosmic")
]; ];
}; };
}; };
}; });
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 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, lib,
inputs, inputs,
self, self,
rootPath,
... ...
}: let }: let
rootPath = ./..;
inherit (self) outputs; inherit (self) outputs;
homeModules = homeModules =
( (
@ -46,6 +46,11 @@
]) ])
++ [ ++ [
homeModules."${unixName}" homeModules."${unixName}"
]
++ [
{
lib = {inherit (lib) youthlic;};
}
]; ];
extraSpecialArgs = { extraSpecialArgs = {
inherit inherit

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,22 +1,3 @@
{...}: { {lib, ...}: {
imports = [ imports = lib.youthlic.loadImports ./.;
./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
];
} }

View file

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

View file

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

View file

@ -1,21 +1,3 @@
{...}: { {lib, ...}: {
imports = [ imports = lib.youthlic.loadImports ./.;
./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
];
} }

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

View file

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

View file

@ -1,5 +1,6 @@
{ {
pkgs, pkgs,
lib,
inputs, inputs,
outputs, outputs,
... ...
@ -13,21 +14,10 @@
common-pc-laptop-ssd common-pc-laptop-ssd
asus-battery asus-battery
]) ])
++ [ ++ (with outputs; [
./users nixosModules.gui
./stylix.nix ])
./gui.nix ++ (lib.youthlic.loadImports ./.);
# 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
];
youthlic = { youthlic = {
home-manager = { home-manager = {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,33 +1,3 @@
{...}: { {lib, ...}: {
imports = [ imports = lib.youthlic.loadImports ./.;
./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
];
} }

View file

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

View file

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

View file

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

View file

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