refactor: rename modules directory to nix

This commit is contained in:
Mohammad Rafiq 2025-07-06 19:11:49 +08:00
parent 5501c39e31
commit e884735f25
No known key found for this signature in database
13 changed files with 1 additions and 1 deletions

View file

@ -0,0 +1,9 @@
{ config, ... }:
let
inherit (cfg.lib) extractConfigurations;
cfg = config.flake;
hosts = cfg.hostSpec.hosts or { };
in
{
flake.nixosConfigurations = extractConfigurations "nixos/" hosts;
}

28
nix/flake-parts/files.nix Normal file
View file

@ -0,0 +1,28 @@
{
inputs,
withSystem,
lib,
config,
...
}:
let
inherit (builtins) map head;
inherit (lib) concatStringsSep;
mkListEntry = x: "- [" + x.path_ + "](" + x.path_ + ")";
listOfGeneratedFiles = withSystem (head config.systems) (psArgs: psArgs.config.files.files);
in
{
imports = [ inputs.files.flakeModules.default ];
perSystem = psArgs: {
make-shells.default.packages = [ psArgs.config.files.writer.drv ];
};
text.readme.parts."Generated Files" = concatStringsSep "\n" (
[
"This flake uses the [files flake-parts module](https://flake.parts/options/files.html) to generate documentation."
"The list of generated files are:"
]
++ (map mkListEntry listOfGeneratedFiles)
);
}

View file

@ -0,0 +1,17 @@
{ lib, config, ... }:
let
inherit (lib) concatStringsSep singleton;
in
{
text.cheatsheet = concatStringsSep "\n" [
"`__curPos.file` will give the full evaluated path of the nix file it is called in. See [this issue](https://github.com/NixOS/nix/issues/5897#issuecomment-1012165198) for more information."
];
perSystem =
{ pkgs, ... }:
{
files.files = singleton {
path_ = "docs/cheatsheet.md";
drv = pkgs.writeText "cheatsheet.md" config.text.cheatsheet;
};
};
}

View file

@ -0,0 +1,21 @@
{ config, lib, ... }:
let
inherit (lib) singleton;
in
{
text.readme = {
heading = "Pantheon";
description = ''
This flake serves as a monorepo for my systems (using IaC), dotfiles, and scripts.
'';
};
perSystem =
{ pkgs, ... }:
{
files.files = singleton {
path_ = "README.md";
drv = pkgs.writeText "README.md" config.text.readme;
};
};
}

View file

@ -0,0 +1,23 @@
{ inputs, ... }:
{
imports = [ inputs.git-hooks.flakeModule ];
perSystem = psArgs: {
pre-commit.settings.hooks = {
# Nix Linters
deadnix.enable = true;
statix.enable = true;
nil.enable = true;
nixfmt-rfc-style.enable = true;
# Flake Health Checks
flake-checker.enable = true;
# Misc
mixed-line-endings.enable = true;
trim-trailing-whitespace.enable = true;
#TODO: figure out vale
#TODO: make nix develop work
#TODO: add nix flake check
#TODO: add write-files
};
make-shells.default.shellHook = psArgs.config.pre-commit.installationScript;
};
}

View file

@ -0,0 +1,5 @@
{ inputs, ... }:
{
#TODO: add to readme
imports = [ inputs.make-shell.flakeModules.default ];
}

View file

@ -0,0 +1,4 @@
{ inputs, ... }:
{
imports = [ inputs.flake-parts.flakeModules.modules ];
}

4
nix/flake-parts/text.nix Normal file
View file

@ -0,0 +1,4 @@
{ inputs, ... }:
{
imports = [ inputs.text.flakeModules.default ];
}

52
nix/hostSpec.nix Normal file
View file

@ -0,0 +1,52 @@
let
testCfg = {
fileSystems."/" = {
device = "/dev/sda1";
fsType = "ext4";
};
nixpkgs.hostPlatform = "x86_64-linux";
};
in
{
flake.hostSpec.hosts = {
"nixos/test".extraCfg = testCfg;
"nixos/nemesis" = {
machine = {
platform = "amd";
gpu = "nvidia";
root.drive = "/dev/disk/by-id/nvme-CT2000P3SSD8_2325E6E77434";
monitors = [
{
id = "desc:OOO AN-270W04K";
scale = "2";
resolution = "3840x2160";
refresh-rate = "60";
}
];
};
# profiles = with config.flake.profiles.nixos; [
# graphical
# development
# ];
# extraModules = with config.flakes.modules.nixos; [
# sunshine
# sd-webui-forge
# comfy-ui
# ];
extraCfg = testCfg;
};
"nixos/apollo" = {
machine = {
platform = "intel";
root.drive = "/dev/disk/by-id/nvme-eui.002538d221b47b01";
};
# profiles = with config.flake.profiles.nixos; [ headless ];
# extraModules = with config.flakes.modules.nixos; [
# librechat
# forgejo
# rrv-sh
# ];
extraCfg = testCfg;
};
};
}

58
nix/lib/default.nix Normal file
View file

@ -0,0 +1,58 @@
{
lib,
config,
inputs,
...
}:
let
inherit (lib.trivial) pipe;
inherit (lib.strings) removePrefix hasPrefix;
inherit (lib.attrsets)
concatMapAttrs
mapAttrs'
filterAttrs
mergeAttrsList
;
in
{
flake.lib = rec {
flattenAttrs = attrset: concatMapAttrs (_: v: v) attrset;
mkSystem =
prefix: name: value:
let
hostName = removePrefix prefix name;
hostConfig = value;
flakeConfig = config;
mkProfileCfg =
profileList: # List of attrsets of nixos configs
pipe profileList [
(map flattenAttrs) # List of nixos configs
mergeAttrsList
];
in
{
name = hostName;
value = lib.nixosSystem {
specialArgs = {
inherit
inputs
hostName
hostConfig
flakeConfig
;
};
modules = [
config.flake.profiles.nixos.common
(mkProfileCfg (value.profiles or [ ]))
(value.extraCfg or { })
];
};
};
extractConfigurations =
prefix: hosts:
pipe hosts [
(filterAttrs (name: _: hasPrefix prefix name))
(mapAttrs' (mkSystem prefix))
];
};
}

View file

@ -0,0 +1,7 @@
{
flake.modules.nixos.networking =
{ hostName, ... }:
{
networking = { inherit hostName; };
};
}

View file

@ -0,0 +1,9 @@
{
flake.profiles.nixos.common =
{ hostName, ... }:
{
boot.loader.systemd-boot.enable = true;
system.stateVersion = "25.05";
networking = { inherit hostName; };
};
}