Skip to content

Commit

Permalink
Rename to lite-config
Browse files Browse the repository at this point in the history
  • Loading branch information
yelite committed Mar 25, 2024
1 parent 3f66f74 commit 3960397
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 43 deletions.
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# lite-system
# lite-config

[![flakestry.dev](https://flakestry.dev/api/badge/flake/github/yelite/lite-system)](https://flakestry.dev/flake/github/yelite/lite-system/0.1.0)
[![flakestry.dev](https://flakestry.dev/api/badge/flake/github/yelite/lite-config)](https://flakestry.dev/flake/github/yelite/lite-config/0.2.0)

`lite-system` offers a convinient appraoch to build NixOS, nix-darwin and Home Manager configurations,
> [!TIP]
> lite-config is the new name of lite-system. This rename is to avoid confusion on the word 'system',
> which is commonly used to refer to platform string, like "x86_64-linux", in context of Nix.
`lite-config` offers a convinient appraoch to build NixOS, nix-darwin and Home Manager configurations,
to create a consistent environment across different devices. It addresses common patterns
when creating personal system configurations, which includes:

Expand All @@ -18,7 +22,7 @@ An example:
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
lite-system.url = "github:yelite/lite-system";
lite-config.url = "github:yelite/lite-config";
nix-darwin = {
url = "github:lnl7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
Expand All @@ -31,11 +35,11 @@ An example:
outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} ({inputs, ...}: {
imports = [
inputs.lite-system.flakeModule
inputs.lite-config.flakeModule
];
config.lite-system = {
# Configure the nixpkgs that is used in all configurations created by `lite-system`.
config.lite-config = {
# Configure the nixpkgs that is used in all configurations created by `lite-config`.
nixpkgs = {
config = {
allowUnfree = true;
Expand Down Expand Up @@ -75,15 +79,15 @@ An example:
}
```

`lite-system` aims to be light weight, as the name suggests. It offers only a fundamental
`lite-config` aims to be light weight, as the name suggests. It offers only a fundamental
framework for building flakes of system configurations. Users still need to write
NixOS (or nix-darwin) modules and home manager modules on their own, as in vanilla flake.

It requires a system module shared across all hosts, a set of per-host modules to
customize each host, and optionally a home manager module used by all hosts.

To enable the creation of unified modules for both NixOS and nix-darwin,
`lite-system` adds `hostPlatform` as a special arg to the module system.
`lite-config` adds `hostPlatform` as a special arg to the module system.
This allows modules to be conditionally imported based on system type.

# Why?
Expand All @@ -109,10 +113,10 @@ While the flexibility provided by flake-parts may not provide significant advant
creating system configurations, it comes in handy when there is need to integrate
various other components within the same flake.

## Why lite-system?
## Why lite-config?

The features offered by flake and flake-parts are rather primitive.
`lite-system` provides features that are commonly needed when building system configurations.
`lite-config` provides features that are commonly needed when building system configurations.
Since it's a flake module, it can also be easily customized and overridden when users
have more complex tasks to accomplish within the flake.

Expand All @@ -123,11 +127,11 @@ have more complex tasks to accomplish within the flake.
outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} ({inputs, ...}: {
imports = [
inputs.lite-system.flakeModule
inputs.lite-config.flakeModule
];
config.lite-system = {
# Configure the nixpkgs that is used in all configurations created by `lite-system`.
config.lite-config = {
# Configure the nixpkgs that is used in all configurations created by `lite-config`.
nixpkgs = {
# The nixpkgs flake to use. Default to `inputs.nixpkgs`.
# This option needs to set if the nixpkgs that you want to use is under a
Expand All @@ -139,14 +143,14 @@ have more complex tasks to accomplish within the flake.
overlays = [];
# Whether packages in the overlays should be exported as packages of this flake.
exportOverlayPackages = true;
# Whether the nixpkgs used in lite-system should also be set as the `pkgs` arg for
# Whether the nixpkgs used in lite-config should also be set as the `pkgs` arg for
# the perSystem module.
setPerSystemPkgs = true;
};
# The home-manager flake to use.
# This should be set if home-manager isn't named as `home-manager` in flake inputs.
# This has no effect if {option}`lite-system.homeModule` is null.
# This has no effect if {option}`lite-config.homeModule` is null.
homeManagerFlake = inputs.home-manager;
builder = {
Expand Down Expand Up @@ -175,10 +179,10 @@ have more complex tasks to accomplish within the flake.
# Per-user Home Manager module used for exporting homeConfigurations to be used
# by systems other than NixOS and nix-darwin.
#
# The exported homeConfigurations will import both `lite-system.homeModule` and the value of
# The exported homeConfigurations will import both `lite-config.homeModule` and the value of
# this attrset.
#
# This has no effect if `lite-system.homeModule` is null.
# This has no effect if `lite-config.homeModule` is null.
homeConfigurations = {
joe = {
myConfig = {
Expand All @@ -192,4 +196,4 @@ have more complex tasks to accomplish within the flake.
```

[https://github.com/yelite/system-config](https://github.com/yelite/system-config) is
a practical, real-world example on how to use `lite-system`.
a practical, real-world example on how to use `lite-config`.
48 changes: 24 additions & 24 deletions flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ toplevel @ {
isDerivation
literalExpression
;
cfg = toplevel.config.lite-system;
cfg = toplevel.config.lite-config;

overlayType = types.uniq (types.functionTo (types.functionTo (types.lazyAttrsOf types.unspecified)));
nixpkgsOptionType = types.submodule {
Expand Down Expand Up @@ -78,7 +78,7 @@ toplevel @ {
default = true;
type = types.bool;
description = ''
Whether the nixpkgs used in lite-system should also be set as the `pkgs` arg for
Whether the nixpkgs used in lite-config should also be set as the `pkgs` arg for
the perSystem module.
'';
};
Expand All @@ -102,7 +102,7 @@ toplevel @ {
default = null;
description = ''
The host module that is imported by this host.
If null, the module at "''${{option}`lite-system.hostModuleDir`}/''${hostName}"
If null, the module at "''${{option}`lite-config.hostModuleDir`}/''${hostName}"
will be used as hostModule.
'';
};
Expand All @@ -123,14 +123,14 @@ toplevel @ {
};
};
};
liteSystemType = types.submodule {
liteConfigType = types.submodule {
options = {
nixpkgs = mkOption {
type = nixpkgsOptionType;
default = {};
description = ''
Config about the nixpkgs used by lite-system.
All configurations produced by lite-system will use the nixpkgs specified in this option.
Config about the nixpkgs used by lite-config.
All configurations produced by lite-config will use the nixpkgs specified in this option.
'';
};

Expand Down Expand Up @@ -165,7 +165,7 @@ toplevel @ {
the configuration of host `hostName` by default.
The host module used by a host can be overridden in
{option}`lite-system.hosts.<hostName>.hostModule`.
{option}`lite-config.hosts.<hostName>.hostModule`.
'';
};

Expand All @@ -176,7 +176,7 @@ toplevel @ {
Options about system configuration builder.
By default, the builder for MacOS is `inputs.nix-darwin.lib.darwinSystem`
and the builder for NixOS is {option}`lite-system.nixpkgs.nixpkgs.lib.nixosSystem`.
and the builder for NixOS is {option}`lite-config.nixpkgs.nixpkgs.lib.nixosSystem`.
'';
};

Expand All @@ -190,7 +190,7 @@ toplevel @ {
The home-manager flake to use.
This should be set if home-manager isn't named as `home-manager` in flake inputs.
This has no effect if {option}`lite-system.homeModule` is null.
This has no effect if {option}`lite-config.homeModule` is null.
'';
};

Expand All @@ -201,10 +201,10 @@ toplevel @ {
Per-user Home Manager module used for exporting homeConfigurations to be used
by systems other than NixOS and nix-darwin.
The exported homeConfigurations will import both `lite-system.homeModule` and the value of
The exported homeConfigurations will import both `lite-config.homeModule` and the value of
this attrset.
This has no effect if {option}`lite-system.homeModule` is null.
This has no effect if {option}`lite-config.homeModule` is null.
'';
example =
literalExpression
Expand All @@ -224,8 +224,8 @@ toplevel @ {
useHomeManager = cfg.homeModule != null;

makeSystemConfig = hostName: hostConfig:
withSystem hostConfig.system ({liteSystemPkgs, ...}: let
hostPlatform = liteSystemPkgs.stdenv.hostPlatform;
withSystem hostConfig.system ({liteConfigPkgs, ...}: let
hostPlatform = liteConfigPkgs.stdenv.hostPlatform;
hostModule =
if hostConfig.hostModule == null
then "${cfg.hostModuleDir}/${hostName}"
Expand All @@ -245,7 +245,7 @@ toplevel @ {
cfg.systemModule
{
_file = ./.;
nixpkgs.pkgs = liteSystemPkgs;
nixpkgs.pkgs = liteConfigPkgs;
networking.hostName = hostName;
}
]
Expand Down Expand Up @@ -321,11 +321,11 @@ toplevel @ {
};
in {
options = {
lite-system = mkOption {
type = liteSystemType;
lite-config = mkOption {
type = liteConfigType;
default = {};
description = ''
The config for lite-system.
The config for lite-config.
'';
};
};
Expand All @@ -338,7 +338,7 @@ in {

perSystem = {
system,
liteSystemPkgs,
liteConfigPkgs,
...
}: {
_file = ./.;
Expand All @@ -350,21 +350,21 @@ in {
};
in {
# Make this OptionDefault so that users are able to override this pkg.
_module.args.liteSystemPkgs = lib.mkOptionDefault selectedPkgs;
_module.args.liteConfigPkgs = lib.mkOptionDefault selectedPkgs;

_module.args.pkgs = lib.mkIf cfg.nixpkgs.setPerSystemPkgs liteSystemPkgs;
_module.args.pkgs = lib.mkIf cfg.nixpkgs.setPerSystemPkgs liteConfigPkgs;

packages = let
overlayPackages = let
overlayFn = lib.composeManyExtensions liteSystemPkgs.overlays;
overlayFn = lib.composeManyExtensions liteConfigPkgs.overlays;
overlayPackageNames =
# Here we use the final pkgs as both prev and final arg for the overlay function.
# This should be fine because we only care about attr names.
attrNames (overlayFn liteSystemPkgs liteSystemPkgs);
attrNames (overlayFn liteConfigPkgs liteConfigPkgs);
overlayPackageEntries =
map (name: {
inherit name;
value = liteSystemPkgs.${name} or null;
value = liteConfigPkgs.${name} or null;
})
overlayPackageNames;
# Some overlay provides non-derivation at the top level, which
Expand All @@ -377,7 +377,7 @@ in {

homeManagerPackages = {
home-manager = cfg.homeManagerFlake.packages.${system}.default;
homeConfigurations = createHomeConfigurations liteSystemPkgs;
homeConfigurations = createHomeConfigurations liteConfigPkgs;
};
in
mkMerge [
Expand Down

1 comment on commit 3960397

@jcf
Copy link

@jcf jcf commented on 3960397 Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥 🤣

Please sign in to comment.