Skip to content

My NixOS flake with lib, hosts, modules and options

Notifications You must be signed in to change notification settings

yunfachi/nix-config

Repository files navigation

yunfachi's NixOS configuration

Features

  • Modular modules and options inspired by nixpkgs
  • Abandoning imports in favor of umport, which recursively import all modules by path
  • Own lib for convenient generation of modules and options
  • Automatic installation of wallpapers from attrset with URLs
  • Error handling after checking flake in github workflow with quotes from Sun Tzu, The Art of War

Tree

.
├── data (Big data, inappropriate in clean code)
│   ├── ips.nix (IP ranges of services)
│   └── wallpapers.nix (URLs and hashes)
├── hosts
│   ├── ayane (Laptop)
│   │   ├── default.nix
│   │   ├── hardware.nix
│   │   └── shared.nix
│   ├── dekomori (Server)
│   │   ├── default.nix
│   │   ├── hardware.nix
│   │   └── shared.nix
│   ├── mitama (Desktop)
│   │   ├── default.nix
│   │   ├── hardware.nix
│   │   └── shared.nix
│   └── default.nix
├── lib
│   ├── lib.nix
│   ├── module-functions.nix
│   └── option-functions.nix
├── modules
│   ├── config
│   │   └── infras
│   ├── programs
│   ├── services
│   │   └── graphical
│   └── system
├── options
│   ├── config
│   │   └── infras
│   ├── programs
│   ├── services
│   │   └── graphical
│   └── system
├── constants.nix
└── flake.nix

Examples

Module
⚠️ Warning
Using the config variable in these examples will cause an infinite recursion

If config.yunfachi.programs.deshiro.enable is set to true, then programs.deshiro.enable will also be set to true.

without parameterswith parameters
{module-functions, ...}:
module-functions.module "programs" "deshiro" {
  programs.deshiro.enable = true;
}
{module-functions, ...}:
module-functions.module "programs" "deshiro" (cfg: {
  programs.deshiro.enable = true;
})

If config.yunfachi.programs.deshiro.enable is set to false, then programs.deshiro.enable will be set to true.

without parameterswith parameters
{module-functions, ...}:
module-functions.moduleIfDisabled "programs" "deshiro" {
  programs.deshiro.enable = true;
}
{module-functions, ...}:
module-functions.moduleIfDisabled "programs" "deshiro" (cfg: {
  programs.deshiro.enable = true;
})

If config.yunfachi.programs.deshiro.enable is set to true, then programs.deshiro.enable will also be set to true. If it's set to false, then programs.deshiro.enable will also be set to false.

without parameterswith parameters
{module-functions, ...}:
module-functions.moduleIfElse "programs" "deshiro" {
  programs.deshiro.enable = true;
} {
  programs.deshiro.enable = false;
}
{module-functions, ...}:
module-functions.moduleIfElse "programs" "deshiro" (cfg: {
  programs.deshiro.enable = true;
}) (cfg: {
  programs.deshiro.enable = false;
})

If config.yunfachi.programs.deshiro-gui.enable is set to true, then programs.deshiro-gui.enable will also be set to true. If it's set to false, then programs.deshiro-gui.enable will also be set to false. In both cases, programs.deshiro-server.enable will be set to true.

without parameterswith parameters
{module-functions, ...}:
module-functions.moduleIfElseFinally "programs" "deshiro-gui" {
  programs.deshiro-gui.enable = true;
} {
  programs.deshiro-gui.enable = false;
} {
  programs.deshiro-server.enable = true;
}
{module-functions, ...}:
module-functions.moduleIfElseFinally "programs" "deshiro-gui"
(cfg: {
  programs.deshiro-gui.enable = true;
}) (cfg: {
  programs.deshiro-gui.enable = false;
}) (cfg: {
  programs.deshiro-server.enable = true;
})
Option

Simple option with only the option to enable it. By default enable will be true as specified

{option-functions, ...}:
with option-functions;
  option "programs" "deshiro" {
    enable = enableOption "deshiro" true;
  }

Option that uses all features. By default enable will be true as specified and mode will be "client", its example will be "server" (automatically found)

{option-functions, ...}:
with option-functions;
  option "programs" "deshiro" {
    enable = enableOption "deshiro" true;
    mode = enumOption "mode" "client" ["client" "server"]
  }