1
Fork 0
mirror of https://github.com/RGBCube/ncc synced 2025-07-29 11:07:44 +00:00

Start refactor

This commit is contained in:
RGBCube 2025-01-11 15:51:21 +03:00
parent 99b7ccfadb
commit 06cce18e72
155 changed files with 2139 additions and 3738 deletions

View file

@ -1,6 +0,0 @@
lib: {
systemConfiguration = cfg: cfg;
systemPackages = pkgs: { environment.systemPackages = pkgs; };
systemFonts = pkgs: { fonts.packages = pkgs; };
homeConfiguration = cfg: { home-manager.sharedModules = [ cfg ]; };
}

View file

@ -1,32 +0,0 @@
lib: config: let
userHomeConfiguration = users: cfg: {
home-manager.users = lib.genAttrs users (lib.const cfg);
};
allNormalUsers = [ "root" ] ++ lib.pipe config.users.users [
(lib.filterAttrs (lib.const (lib.getAttr "isNormalUser")))
lib.attrNames
];
desktopUsers = lib.pipe config.users.users [
(lib.filterAttrs (lib.const (lib.getAttr "isDesktopUser")))
lib.attrNames
];
in rec {
inherit allNormalUsers desktopUsers;
isDesktop = desktopUsers != [];
isServer = desktopUsers == [];
desktopSystemConfiguration = cfg: lib.optionalAttrs isDesktop cfg;
desktopSystemPackages = pkgs: desktopSystemConfiguration (lib.systemPackages pkgs);
desktopSystemFonts = pkgs: desktopSystemConfiguration (lib.systemFonts pkgs);
desktopUserHomeConfiguration = cfg: userHomeConfiguration desktopUsers cfg;
desktopUserHomePackages = pkgs: desktopUserHomeConfiguration { home.packages = pkgs; };
desktopHomeConfiguration = cfg: desktopSystemConfiguration (lib.homeConfiguration cfg);
desktopHomePackages = pkgs: desktopHomeConfiguration { home.packages = pkgs; };
serverSystemConfiguration = cfg: lib.optionalAttrs isServer cfg;
serverSystemPackages = pkgs: serverSystemConfiguration (lib.systemPackages pkgs);
serverHomeConfiguration = cfg: serverSystemConfiguration (lib.homeConfiguration cfg);
}

5
lib/default.nix Normal file
View file

@ -0,0 +1,5 @@
inputs: self: super: let
option = import ./option.nix inputs self super;
system = import ./system.nix inputs self super;
values = import ./values.nix inputs self super;
in option // system // values

View file

@ -1,11 +0,0 @@
lib: {
enabled = lib.mkMerge [{
enable = true;
}] // {
__functor = self: attributes: self // {
contents = self.contents ++ [ attributes ];
};
};
disabled = { enable = lib.mkForce false; };
}

View file

@ -1,7 +0,0 @@
lib: {
merge = lib.mkMerge [] // {
__functor = self: next: self // {
contents = self.contents ++ [ next ];
};
};
}

View file

@ -1,10 +0,0 @@
lib: {
mkConst = value: lib.mkOption {
default = value;
readOnly = true;
};
mkValue = value: lib.mkOption {
default = value;
};
}

12
lib/option.nix Normal file
View file

@ -0,0 +1,12 @@
_: _: super: let
inherit (super) mkOption;
in {
mkConst = value: mkOption {
default = value;
readOnly = true;
};
mkValue = default: mkOption {
inherit default;
};
}

53
lib/system.nix Normal file
View file

@ -0,0 +1,53 @@
inputs: self: super: let
inherit (self) attrValues filter getAttrFromPath hasAttrByPath hasSuffix;
inherit (self.filesystem) listFilesRecursive;
collect = path: listFilesRecursive path
|> filter (hasSuffix ".nix");
commonModules = collect ../modules/common;
nixosModules = collect ../modules/nixos;
darwinModules = collect ../modules/darwin;
collectInputs = let
inputs' = attrValues inputs;
in path: inputs'
|> filter (hasAttrByPath path)
|> map (getAttrFromPath path);
inputNixosModules = collectInputs [ "nixosModules" "default" ];
inputDarwinModules = collectInputs [ "darwinModules" "default" ];
inputOverlays = collectInputs [ "overlays" "default" ];
overlayModule = { nixpkgs.overlays = inputOverlays; };
in {
nixosSystem = module: super.nixosSystem {
modules = [
module
overlayModule
] ++ commonModules
++ nixosModules
++ inputNixosModules;
specialArgs = inputs // {
inherit inputs;
lib = self;
};
};
darwinSystem = module: super.darwinSystem {
modules = [
module
overlayModule
] ++ commonModules
++ darwinModules
++ inputDarwinModules;
specialArgs = inputs // {
inherit inputs;
lib = self;
};
};
}

View file

@ -1,19 +1,18 @@
lib: {
normalUser = attributes: attributes // {
isNormalUser = true;
};
sudoUser = attributes: attributes // {
isNormalUser = true;
extraGroups = [ "wheel" ] ++ attributes.extraGroups or [];
};
desktopUser = attributes: attributes // {
isNormalUser = true;
isDesktopUser = true; # Defined in options/desktop.nix.
};
systemUser = attributes: attributes // {
isSystemUser = true;
_: self: _: let
inherit (self) merge mkMerge;
in {
# When the block has a `_type` attribute in the NixOS
# module system, anything not immediately relevant is
# silently ignored. We can make use of that by adding
# a `__functor` attribute, which lets us call the set.
merge = mkMerge [] // {
__functor = self: next: self // {
# Technically, `contents` is implementation defined
# but nothing ever happens, so we can rely on this.
contents = self.contents ++ [ next ];
};
};
enabled = merge { enable = true; };
disabled = merge { enable = false; };
}