Merge pull request 'features (lib)' (#1) from features into develop

Reviewed-on: #1
This commit is contained in:
Kirill Samoylenkov 2025-09-26 17:01:47 +00:00
commit 02cf5661fc
3 changed files with 175 additions and 0 deletions

36
flake.nix Normal file
View file

@ -0,0 +1,36 @@
{
description = "My NixOS Configurations Flake";
inputs = {
# Source: https://github.com/NixOS/nixpkgs
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nixpkgs-old.url = "github:nixos/nixpkgs/nixos-24.11";
nixpkgs-latest.url = "github:nixos/nixpkgs";
# Source: https://github.com/nix-community/home-manager
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
# Source: https://github.com/NixOS/nixos-hardware
nixos-hardware.url = "github:nixos/nixos-hardware";
# Source: https://github.com/Mic92/sops-nix
sops-nix.url = "github:mic92/sops-nix";
};
outputs =
{
nixpkgs,
nixpkgs-old,
nixpkgs-latest,
...
}@inputs:
let
#
in
{
#
};
}

88
lib/config.nix Normal file
View file

@ -0,0 +1,88 @@
{
inputs,
nixpkgs,
nixpkgs-old,
nixpkgs-latest,
}:
deviceName:
{
hostName,
userName,
additionalOverlays ? [ ],
systemArch ? builtins.currentSystem,
}:
let
inherit (nixpkgs) lib;
customFunctions = import ./utils.nix { inherit lib; };
baseOverlays =
import ../overlays {
inherit
systemArch
nixpkgs-old
nixpkgs-latest
packagesConfig
;
}
|> builtins.attrValues;
overlays = baseOverlays ++ additionalOverlays;
DeviceConfig = ../devices/${deviceName};
HostConfig = ../users/${hostName}/host;
HomeConfig = ../users/${userName}/home;
userData = import ../users/${userName}/data.nix {
inherit
deviceName
hostName
userName
systemArch
;
};
userPackagesConfig = import ../users/${hostName}/packages-config.nix { inherit lib; };
additionalArgs = { inherit inputs customFunctions userData; };
sops = {
defaultSopsFormat = "yaml";
defaultSopsFile = ../secrets/main.yaml;
age.keyFile = "${userData.paths.sopsKeyFile}";
};
in
lib.nixosSystem {
system = systemArch;
specialArgs = additionalArgs;
modules = [
DeviceConfig
HostConfig
{
nixpkgs = {
inherit overlays;
config = userPackagesConfig;
};
}
inputs.home-manager.nixosModules.home-manager
{
home-manager = {
users.${userName} = import HomeConfig;
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = additionalArgs;
sharedModules = [
inputs.sops-nix.homeManagerModules.sops
];
};
}
inputs.sops-nix.nixosModules.sops
{
inherit sops;
home-manager.users.${userName} = { inherit sops; };
}
];
}

51
lib/utils.nix Normal file
View file

@ -0,0 +1,51 @@
# This function is copied from:
# https://github.com/yunfachi/nypkgs/blob/master/lib/umport.nix
#
# !!! REMOVING THIS NOTICE VIOLATES THE MIT LICENSE OF THE UMPORT PROJECT !!!
# This notice must be retained in all copies of this function, including modified versions!
# The MIT License can be found here:
# https://github.com/yunfachi/nypkgs/blob/master/LICENSE
{ lib, ... }:
let
umport =
inputs@{
path ? null,
paths ? [ ],
include ? [ ],
exclude ? [ ],
recursive ? true,
}:
with lib;
with fileset;
let
excludedFiles = filter (path: pathIsRegularFile path) exclude;
excludedDirs = filter (path: pathIsDirectory path) exclude;
isExcluded =
path:
if elem path excludedFiles then
true
else
(filter (excludedDir: lib.path.hasPrefix excludedDir path) excludedDirs) != [ ];
in
unique (
(filter
(file: pathIsRegularFile file && hasSuffix ".nix" (builtins.toString file) && !isExcluded file)
(
concatMap (
_path:
if recursive then
toList _path
else
mapAttrsToList (
name: type: _path + (if type == "directory" then "/${name}/default.nix" else "/${name}")
) (builtins.readDir _path)
) (unique (if path == null then paths else [ path ] ++ paths))
)
)
++ (if recursive then concatMap (path: toList path) (unique include) else unique include)
);
in
{
scan = umport;
}