mirror of
https://github.com/mjallen18/snowfall-lib.git
synced 2026-04-18 09:05:58 -05:00
style: fmt
This commit is contained in:
23
default.nix
23
default.nix
@@ -1,14 +1,9 @@
|
|||||||
(
|
(import (
|
||||||
import
|
let
|
||||||
(
|
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||||
let
|
in
|
||||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
fetchTarball {
|
||||||
in
|
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||||
fetchTarball {
|
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
}
|
||||||
sha256 = lock.nodes.flake-compat.locked.narHash;
|
) { src = ./.; }).defaultNix
|
||||||
}
|
|
||||||
)
|
|
||||||
{src = ./.;}
|
|
||||||
)
|
|
||||||
.defaultNix
|
|
||||||
|
|||||||
159
flake.nix
159
flake.nix
@@ -11,89 +11,92 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = {
|
outputs =
|
||||||
self,
|
{
|
||||||
...
|
self,
|
||||||
} @ inputs: let
|
|
||||||
core-inputs =
|
|
||||||
inputs
|
|
||||||
// {
|
|
||||||
src = self;
|
|
||||||
};
|
|
||||||
|
|
||||||
# Create the library, extending the nixpkgs library and merging
|
|
||||||
# libraries from other inputs to make them available like
|
|
||||||
# `lib.flake-utils-plus.mkApp`.
|
|
||||||
# Usage: mkLib { inherit inputs; src = ./.; }
|
|
||||||
# result: lib
|
|
||||||
mkLib = import ./snowfall-lib core-inputs;
|
|
||||||
|
|
||||||
# A convenience wrapper to create the library and then call `lib.mkFlake`.
|
|
||||||
# Usage: mkFlake { inherit inputs; src = ./.; ... }
|
|
||||||
# result: <flake-outputs>
|
|
||||||
mkFlake = flake-and-lib-options @ {
|
|
||||||
inputs,
|
|
||||||
src,
|
|
||||||
snowfall ? {},
|
|
||||||
...
|
...
|
||||||
}: let
|
}@inputs:
|
||||||
lib = mkLib {
|
let
|
||||||
inherit inputs src snowfall;
|
core-inputs = inputs // {
|
||||||
};
|
|
||||||
flake-options = builtins.removeAttrs flake-and-lib-options ["inputs" "src"];
|
|
||||||
in
|
|
||||||
lib.mkFlake flake-options;
|
|
||||||
in {
|
|
||||||
inherit mkLib mkFlake;
|
|
||||||
|
|
||||||
nixosModules = {
|
|
||||||
user = ./modules/nixos/user/default.nix;
|
|
||||||
};
|
|
||||||
|
|
||||||
darwinModules = {
|
|
||||||
user = ./modules/darwin/user/default.nix;
|
|
||||||
};
|
|
||||||
|
|
||||||
homeModules = {
|
|
||||||
user = ./modules/home/user/default.nix;
|
|
||||||
};
|
|
||||||
|
|
||||||
formatter = {
|
|
||||||
x86_64-linux = inputs.nixpkgs.legacyPackages.x86_64-linux.nixfmt-tree;
|
|
||||||
aarch64-linux = inputs.nixpkgs.legacyPackages.aarch64-linux.nixfmt-tree;
|
|
||||||
x86_64-darwin = inputs.nixpkgs.legacyPackages.x86_64-darwin.nixfmt-tree;
|
|
||||||
aarch64-darwin = inputs.nixpkgs.legacyPackages.aarch64-darwin.nixfmt-tree;
|
|
||||||
};
|
|
||||||
|
|
||||||
snowfall = rec {
|
|
||||||
raw-config = config;
|
|
||||||
|
|
||||||
config = {
|
|
||||||
root = self;
|
|
||||||
src = self;
|
src = self;
|
||||||
namespace = "snowfall";
|
|
||||||
lib-dir = "snowfall-lib";
|
|
||||||
|
|
||||||
meta = {
|
|
||||||
name = "snowfall-lib";
|
|
||||||
title = "Snowfall Lib";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
internal-lib = let
|
# Create the library, extending the nixpkgs library and merging
|
||||||
lib = mkLib {
|
# libraries from other inputs to make them available like
|
||||||
src = self;
|
# `lib.flake-utils-plus.mkApp`.
|
||||||
|
# Usage: mkLib { inherit inputs; src = ./.; }
|
||||||
|
# result: lib
|
||||||
|
mkLib = import ./snowfall-lib core-inputs;
|
||||||
|
|
||||||
inputs =
|
# A convenience wrapper to create the library and then call `lib.mkFlake`.
|
||||||
inputs
|
# Usage: mkFlake { inherit inputs; src = ./.; ... }
|
||||||
// {
|
# result: <flake-outputs>
|
||||||
self = {};
|
mkFlake =
|
||||||
};
|
flake-and-lib-options@{
|
||||||
|
inputs,
|
||||||
|
src,
|
||||||
|
snowfall ? { },
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
lib = mkLib {
|
||||||
|
inherit inputs src snowfall;
|
||||||
|
};
|
||||||
|
flake-options = builtins.removeAttrs flake-and-lib-options [
|
||||||
|
"inputs"
|
||||||
|
"src"
|
||||||
|
];
|
||||||
|
in
|
||||||
|
lib.mkFlake flake-options;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit mkLib mkFlake;
|
||||||
|
|
||||||
|
nixosModules = {
|
||||||
|
user = ./modules/nixos/user/default.nix;
|
||||||
|
};
|
||||||
|
|
||||||
|
darwinModules = {
|
||||||
|
user = ./modules/darwin/user/default.nix;
|
||||||
|
};
|
||||||
|
|
||||||
|
homeModules = {
|
||||||
|
user = ./modules/home/user/default.nix;
|
||||||
|
};
|
||||||
|
|
||||||
|
formatter = {
|
||||||
|
x86_64-linux = inputs.nixpkgs.legacyPackages.x86_64-linux.nixfmt-tree;
|
||||||
|
aarch64-linux = inputs.nixpkgs.legacyPackages.aarch64-linux.nixfmt-tree;
|
||||||
|
x86_64-darwin = inputs.nixpkgs.legacyPackages.x86_64-darwin.nixfmt-tree;
|
||||||
|
aarch64-darwin = inputs.nixpkgs.legacyPackages.aarch64-darwin.nixfmt-tree;
|
||||||
|
};
|
||||||
|
|
||||||
|
snowfall = rec {
|
||||||
|
raw-config = config;
|
||||||
|
|
||||||
|
config = {
|
||||||
|
root = self;
|
||||||
|
src = self;
|
||||||
|
namespace = "snowfall";
|
||||||
|
lib-dir = "snowfall-lib";
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
name = "snowfall-lib";
|
||||||
|
title = "Snowfall Lib";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
in
|
|
||||||
builtins.removeAttrs
|
internal-lib =
|
||||||
lib.snowfall
|
let
|
||||||
["internal"];
|
lib = mkLib {
|
||||||
|
src = self;
|
||||||
|
|
||||||
|
inputs = inputs // {
|
||||||
|
self = { };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
builtins.removeAttrs lib.snowfall [ "internal" ];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
config,
|
config,
|
||||||
inputs,
|
inputs,
|
||||||
...
|
...
|
||||||
}: let
|
}:
|
||||||
inherit
|
let
|
||||||
(lib)
|
inherit (lib)
|
||||||
types
|
types
|
||||||
mkOption
|
mkOption
|
||||||
mkDefault
|
mkDefault
|
||||||
@@ -20,9 +20,11 @@
|
|||||||
|
|
||||||
user-names = builtins.attrNames cfg.users;
|
user-names = builtins.attrNames cfg.users;
|
||||||
|
|
||||||
create-system-users = system-users: name: let
|
create-system-users =
|
||||||
user = cfg.users.${name};
|
system-users: name:
|
||||||
in
|
let
|
||||||
|
user = cfg.users.${name};
|
||||||
|
in
|
||||||
system-users
|
system-users
|
||||||
// (optionalAttrs user.create {
|
// (optionalAttrs user.create {
|
||||||
${name} = {
|
${name} = {
|
||||||
@@ -30,77 +32,84 @@
|
|||||||
isHidden = mkDefault false;
|
isHidden = mkDefault false;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(mkRenamedOptionModule ["snowfallorg" "user"] ["snowfallorg" "users"])
|
(mkRenamedOptionModule [ "snowfallorg" "user" ] [ "snowfallorg" "users" ])
|
||||||
];
|
];
|
||||||
|
|
||||||
options.snowfallorg = {
|
options.snowfallorg = {
|
||||||
users = mkOption {
|
users = mkOption {
|
||||||
description = "User configuration.";
|
description = "User configuration.";
|
||||||
default = {};
|
default = { };
|
||||||
type = types.attrsOf (types.submodule ({name, ...}: {
|
type = types.attrsOf (
|
||||||
options = {
|
types.submodule (
|
||||||
create = mkOption {
|
{ name, ... }:
|
||||||
description = "Whether to create the user automatically.";
|
{
|
||||||
type = types.bool;
|
options = {
|
||||||
default = true;
|
create = mkOption {
|
||||||
};
|
description = "Whether to create the user automatically.";
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
|
|
||||||
home = {
|
home = {
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
path = mkOption {
|
path = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "/Users/${name}";
|
default = "/Users/${name}";
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkOption {
|
config = mkOption {
|
||||||
# HM-compatible options taken from:
|
# HM-compatible options taken from:
|
||||||
# https://github.com/nix-community/home-manager/blob/0ee5ab611dc1fbb5180bd7d88d2aeb7841a4d179/nixos/common.nix#L14
|
# https://github.com/nix-community/home-manager/blob/0ee5ab611dc1fbb5180bd7d88d2aeb7841a4d179/nixos/common.nix#L14
|
||||||
type = types.submoduleWith {
|
type = types.submoduleWith {
|
||||||
specialArgs =
|
specialArgs = {
|
||||||
{
|
osConfig = config;
|
||||||
osConfig = config;
|
modulesPath = "${inputs.home-manager}/modules";
|
||||||
modulesPath = "${inputs.home-manager}/modules";
|
}
|
||||||
}
|
// config.home-manager.extraSpecialArgs;
|
||||||
// config.home-manager.extraSpecialArgs;
|
modules = [
|
||||||
modules =
|
(
|
||||||
[
|
{
|
||||||
({
|
lib,
|
||||||
lib,
|
modulesPath,
|
||||||
modulesPath,
|
...
|
||||||
...
|
}:
|
||||||
}: {
|
{
|
||||||
imports = import "${modulesPath}/modules.nix" {
|
imports = import "${modulesPath}/modules.nix" {
|
||||||
inherit pkgs lib;
|
inherit pkgs lib;
|
||||||
useNixpkgsModule = !config.home-manager.useGlobalPkgs;
|
useNixpkgsModule = !config.home-manager.useGlobalPkgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
submoduleSupport.enable = true;
|
submoduleSupport.enable = true;
|
||||||
submoduleSupport.externalPackageInstall = config.home-manager.useUserPackages;
|
submoduleSupport.externalPackageInstall = config.home-manager.useUserPackages;
|
||||||
|
|
||||||
home.username = config.users.users.${name}.name;
|
home.username = config.users.users.${name}.name;
|
||||||
home.homeDirectory = config.users.users.${name}.home;
|
home.homeDirectory = config.users.users.${name}.home;
|
||||||
|
|
||||||
nix.package = config.nix.package;
|
nix.package = config.nix.package;
|
||||||
};
|
};
|
||||||
})
|
}
|
||||||
]
|
)
|
||||||
++ config.home-manager.sharedModules;
|
]
|
||||||
|
++ config.home-manager.sharedModules;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
};
|
)
|
||||||
}));
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
users.users = foldl create-system-users {} user-names;
|
users.users = foldl create-system-users { } user-names;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
inputs @ {
|
inputs@{
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
lib,
|
||||||
options,
|
options,
|
||||||
config,
|
config,
|
||||||
...
|
...
|
||||||
}: let
|
}:
|
||||||
inherit (lib) types mkOption mkIf mkDefault;
|
let
|
||||||
|
inherit (lib)
|
||||||
|
types
|
||||||
|
mkOption
|
||||||
|
mkIf
|
||||||
|
mkDefault
|
||||||
|
;
|
||||||
|
|
||||||
cfg = config.snowfallorg;
|
cfg = config.snowfallorg;
|
||||||
|
|
||||||
@@ -16,12 +22,14 @@ inputs @ {
|
|||||||
has-user-name = (cfg.user.name or null) != null;
|
has-user-name = (cfg.user.name or null) != null;
|
||||||
|
|
||||||
default-home-directory =
|
default-home-directory =
|
||||||
if (os-user-home != null)
|
if (os-user-home != null) then
|
||||||
then os-user-home
|
os-user-home
|
||||||
else if pkgs.stdenv.isDarwin
|
else if pkgs.stdenv.isDarwin then
|
||||||
then "/Users/${cfg.user.name}"
|
"/Users/${cfg.user.name}"
|
||||||
else "/home/${cfg.user.name}";
|
else
|
||||||
in {
|
"/home/${cfg.user.name}";
|
||||||
|
in
|
||||||
|
{
|
||||||
options.snowfallorg = {
|
options.snowfallorg = {
|
||||||
user = {
|
user = {
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
args @ {
|
args@{
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
lib,
|
||||||
options,
|
options,
|
||||||
config,
|
config,
|
||||||
...
|
...
|
||||||
}: let
|
}:
|
||||||
inherit
|
let
|
||||||
(lib)
|
inherit (lib)
|
||||||
types
|
types
|
||||||
mkOption
|
mkOption
|
||||||
mkDefault
|
mkDefault
|
||||||
@@ -18,13 +18,15 @@ args @ {
|
|||||||
|
|
||||||
cfg = config.snowfallorg;
|
cfg = config.snowfallorg;
|
||||||
|
|
||||||
inputs = args.inputs or {};
|
inputs = args.inputs or { };
|
||||||
|
|
||||||
user-names = builtins.attrNames cfg.users;
|
user-names = builtins.attrNames cfg.users;
|
||||||
|
|
||||||
create-system-users = system-users: name: let
|
create-system-users =
|
||||||
user = cfg.users.${name};
|
system-users: name:
|
||||||
in
|
let
|
||||||
|
user = cfg.users.${name};
|
||||||
|
in
|
||||||
system-users
|
system-users
|
||||||
// (optionalAttrs user.create {
|
// (optionalAttrs user.create {
|
||||||
${name} = {
|
${name} = {
|
||||||
@@ -38,88 +40,95 @@ args @ {
|
|||||||
extraGroups = optional user.admin "wheel";
|
extraGroups = optional user.admin "wheel";
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(mkRenamedOptionModule ["snowfallorg" "user"] ["snowfallorg" "users"])
|
(mkRenamedOptionModule [ "snowfallorg" "user" ] [ "snowfallorg" "users" ])
|
||||||
];
|
];
|
||||||
|
|
||||||
options.snowfallorg = {
|
options.snowfallorg = {
|
||||||
users = mkOption {
|
users = mkOption {
|
||||||
description = "User configuration.";
|
description = "User configuration.";
|
||||||
default = {};
|
default = { };
|
||||||
type = types.attrsOf (types.submodule ({name, ...}: {
|
type = types.attrsOf (
|
||||||
options = {
|
types.submodule (
|
||||||
create = mkOption {
|
{ name, ... }:
|
||||||
description = "Whether to create the user automatically.";
|
{
|
||||||
type = types.bool;
|
options = {
|
||||||
default = true;
|
create = mkOption {
|
||||||
};
|
description = "Whether to create the user automatically.";
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
|
|
||||||
admin = mkOption {
|
admin = mkOption {
|
||||||
description = "Whether the user should be added to the wheel group.";
|
description = "Whether the user should be added to the wheel group.";
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
home = {
|
home = {
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
path = mkOption {
|
path = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "/home/${name}";
|
default = "/home/${name}";
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkOption {
|
config = mkOption {
|
||||||
# HM-compatible options taken from:
|
# HM-compatible options taken from:
|
||||||
# https://github.com/nix-community/home-manager/blob/0ee5ab611dc1fbb5180bd7d88d2aeb7841a4d179/nixos/common.nix#L14
|
# https://github.com/nix-community/home-manager/blob/0ee5ab611dc1fbb5180bd7d88d2aeb7841a4d179/nixos/common.nix#L14
|
||||||
# NOTE: This has been adapted to support documentation generation without
|
# NOTE: This has been adapted to support documentation generation without
|
||||||
# having home-manager options fully declared.
|
# having home-manager options fully declared.
|
||||||
type = types.submoduleWith {
|
type = types.submoduleWith {
|
||||||
specialArgs =
|
specialArgs = {
|
||||||
{
|
osConfig = config;
|
||||||
osConfig = config;
|
modulesPath = "${inputs.home-manager or "/"}/modules";
|
||||||
modulesPath = "${inputs.home-manager or "/"}/modules";
|
}
|
||||||
}
|
// (config.home-manager.extraSpecialArgs or { });
|
||||||
// (config.home-manager.extraSpecialArgs or {});
|
modules = [
|
||||||
modules =
|
(
|
||||||
[
|
{
|
||||||
({
|
lib,
|
||||||
lib,
|
modulesPath,
|
||||||
modulesPath,
|
...
|
||||||
...
|
}:
|
||||||
}:
|
if inputs ? home-manager then
|
||||||
if inputs ? home-manager
|
{
|
||||||
then {
|
imports = import "${modulesPath}/modules.nix" {
|
||||||
imports = import "${modulesPath}/modules.nix" {
|
inherit pkgs lib;
|
||||||
inherit pkgs lib;
|
useNixpkgsModule = !(config.home-manager.useGlobalPkgs or false);
|
||||||
useNixpkgsModule = !(config.home-manager.useGlobalPkgs or false);
|
};
|
||||||
};
|
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
submoduleSupport.enable = true;
|
submoduleSupport.enable = true;
|
||||||
submoduleSupport.externalPackageInstall = config.home-manager.useUserPackages;
|
submoduleSupport.externalPackageInstall = config.home-manager.useUserPackages;
|
||||||
|
|
||||||
home.username = config.users.users.${name}.name;
|
home.username = config.users.users.${name}.name;
|
||||||
home.homeDirectory = config.users.users.${name}.home;
|
home.homeDirectory = config.users.users.${name}.home;
|
||||||
|
|
||||||
nix.package = config.nix.package;
|
nix.package = config.nix.package;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {})
|
else
|
||||||
]
|
{ }
|
||||||
++ (config.home-manager.sharedModules or []);
|
)
|
||||||
|
]
|
||||||
|
++ (config.home-manager.sharedModules or [ ]);
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
};
|
)
|
||||||
}));
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
users.users = foldl create-system-users {} user-names;
|
users.users = foldl create-system-users { } user-names;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
snowfall-lib,
|
snowfall-lib,
|
||||||
snowfall-config,
|
snowfall-config,
|
||||||
}: let
|
}:
|
||||||
inherit
|
let
|
||||||
(core-inputs.nixpkgs.lib)
|
inherit (core-inputs.nixpkgs.lib)
|
||||||
assertMsg
|
assertMsg
|
||||||
mapAttrsToList
|
mapAttrsToList
|
||||||
mapAttrs
|
mapAttrs
|
||||||
@@ -15,7 +15,8 @@
|
|||||||
mergeAttrs
|
mergeAttrs
|
||||||
isDerivation
|
isDerivation
|
||||||
;
|
;
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
attrs = {
|
attrs = {
|
||||||
## Map and flatten an attribute set into a list.
|
## Map and flatten an attribute set into a list.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -27,8 +28,7 @@ in {
|
|||||||
## [ "x" 1 "y" 2 ]
|
## [ "x" 1 "y" 2 ]
|
||||||
## ```
|
## ```
|
||||||
#@ (a -> b -> [c]) -> Attrs -> [c]
|
#@ (a -> b -> [c]) -> Attrs -> [c]
|
||||||
map-concat-attrs-to-list = f: attrs:
|
map-concat-attrs-to-list = f: attrs: flatten (mapAttrsToList f attrs);
|
||||||
flatten (mapAttrsToList f attrs);
|
|
||||||
|
|
||||||
## Recursively merge a list of attribute sets.
|
## Recursively merge a list of attribute sets.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -40,7 +40,7 @@ in {
|
|||||||
## { x = 2; }
|
## { x = 2; }
|
||||||
## ```
|
## ```
|
||||||
#@ [Attrs] -> Attrs
|
#@ [Attrs] -> Attrs
|
||||||
merge-deep = foldl recursiveUpdate {};
|
merge-deep = foldl recursiveUpdate { };
|
||||||
|
|
||||||
## Merge the root of a list of attribute sets.
|
## Merge the root of a list of attribute sets.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -52,7 +52,7 @@ in {
|
|||||||
## { x = 2; }
|
## { x = 2; }
|
||||||
## ```
|
## ```
|
||||||
#@ [Attrs] -> Attrs
|
#@ [Attrs] -> Attrs
|
||||||
merge-shallow = foldl mergeAttrs {};
|
merge-shallow = foldl mergeAttrs { };
|
||||||
|
|
||||||
## Merge shallow for packages, but allow one deeper layer of attribute sets.
|
## Merge shallow for packages, but allow one deeper layer of attribute sets.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -64,23 +64,20 @@ in {
|
|||||||
## { vim = ...; some.value = false; }
|
## { vim = ...; some.value = false; }
|
||||||
## ```
|
## ```
|
||||||
#@ [Attrs] -> Attrs
|
#@ [Attrs] -> Attrs
|
||||||
merge-shallow-packages = items:
|
merge-shallow-packages =
|
||||||
foldl
|
items:
|
||||||
(
|
foldl (
|
||||||
result: item:
|
result: item:
|
||||||
result
|
result
|
||||||
// (mapAttrs
|
// (mapAttrs (
|
||||||
(
|
name: value:
|
||||||
name: value:
|
if isDerivation value then
|
||||||
if isDerivation value
|
value
|
||||||
then value
|
else if builtins.isAttrs value then
|
||||||
else if builtins.isAttrs value
|
(result.${name} or { }) // value
|
||||||
then (result.${name} or {}) // value
|
else
|
||||||
else value
|
value
|
||||||
)
|
) item)
|
||||||
item)
|
) { } items;
|
||||||
)
|
|
||||||
{}
|
|
||||||
items;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,19 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
snowfall-lib,
|
snowfall-lib,
|
||||||
snowfall-config,
|
snowfall-config,
|
||||||
}: let
|
}:
|
||||||
|
let
|
||||||
inherit (core-inputs.flake-utils-plus.lib) filterPackages;
|
inherit (core-inputs.flake-utils-plus.lib) filterPackages;
|
||||||
inherit (core-inputs.nixpkgs.lib) assertMsg foldl mapAttrs callPackageWith;
|
inherit (core-inputs.nixpkgs.lib)
|
||||||
|
assertMsg
|
||||||
|
foldl
|
||||||
|
mapAttrs
|
||||||
|
callPackageWith
|
||||||
|
;
|
||||||
|
|
||||||
user-checks-root = snowfall-lib.fs.get-snowfall-file "checks";
|
user-checks-root = snowfall-lib.fs.get-snowfall-file "checks";
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
check = {
|
check = {
|
||||||
## Create flake output packages.
|
## Create flake output packages.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -20,37 +27,41 @@ in {
|
|||||||
## { another-check = ...; my-check = ...; default = ...; }
|
## { another-check = ...; my-check = ...; default = ...; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-checks = {
|
create-checks =
|
||||||
channels,
|
{
|
||||||
src ? user-checks-root,
|
channels,
|
||||||
pkgs ? channels.nixpkgs,
|
src ? user-checks-root,
|
||||||
overrides ? {},
|
pkgs ? channels.nixpkgs,
|
||||||
alias ? {},
|
overrides ? { },
|
||||||
}: let
|
alias ? { },
|
||||||
user-checks = snowfall-lib.fs.get-default-nix-files-recursive src;
|
}:
|
||||||
create-check-metadata = check: let
|
let
|
||||||
extra-inputs =
|
user-checks = snowfall-lib.fs.get-default-nix-files-recursive src;
|
||||||
pkgs
|
create-check-metadata =
|
||||||
// {
|
check:
|
||||||
inherit channels;
|
let
|
||||||
lib = snowfall-lib.internal.system-lib;
|
extra-inputs = pkgs // {
|
||||||
inputs = snowfall-lib.flake.without-src user-inputs;
|
inherit channels;
|
||||||
namespace = snowfall-config.namespace;
|
lib = snowfall-lib.internal.system-lib;
|
||||||
|
inputs = snowfall-lib.flake.without-src user-inputs;
|
||||||
|
namespace = snowfall-config.namespace;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory check);
|
||||||
|
drv = callPackageWith extra-inputs check { };
|
||||||
};
|
};
|
||||||
in {
|
checks-metadata = builtins.map create-check-metadata user-checks;
|
||||||
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory check);
|
merge-checks =
|
||||||
drv = callPackageWith extra-inputs check {};
|
checks: metadata:
|
||||||
};
|
checks
|
||||||
checks-metadata = builtins.map create-check-metadata user-checks;
|
// {
|
||||||
merge-checks = checks: metadata:
|
${metadata.name} = metadata.drv;
|
||||||
checks
|
};
|
||||||
// {
|
checks-without-aliases = foldl merge-checks { } checks-metadata;
|
||||||
${metadata.name} = metadata.drv;
|
aliased-checks = mapAttrs (name: value: checks-without-aliases.${value}) alias;
|
||||||
};
|
checks = checks-without-aliases // aliased-checks // overrides;
|
||||||
checks-without-aliases = foldl merge-checks {} checks-metadata;
|
in
|
||||||
aliased-checks = mapAttrs (name: value: checks-without-aliases.${value}) alias;
|
|
||||||
checks = checks-without-aliases // aliased-checks // overrides;
|
|
||||||
in
|
|
||||||
filterPackages pkgs.stdenv.hostPlatform.system checks;
|
filterPackages pkgs.stdenv.hostPlatform.system checks;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,35 +2,45 @@
|
|||||||
# Snowfall library. There is some duplication shared between this
|
# Snowfall library. There is some duplication shared between this
|
||||||
# file and the library itself due to the library needing to pass through
|
# file and the library itself due to the library needing to pass through
|
||||||
# another extended library for its own applications.
|
# another extended library for its own applications.
|
||||||
core-inputs: user-options: let
|
core-inputs: user-options:
|
||||||
raw-snowfall-config = user-options.snowfall or {};
|
let
|
||||||
snowfall-config =
|
raw-snowfall-config = user-options.snowfall or { };
|
||||||
raw-snowfall-config
|
snowfall-config = raw-snowfall-config // {
|
||||||
// {
|
src = user-options.src;
|
||||||
src = user-options.src;
|
root = raw-snowfall-config.root or user-options.src;
|
||||||
root = raw-snowfall-config.root or user-options.src;
|
namespace = raw-snowfall-config.namespace or "internal";
|
||||||
namespace = raw-snowfall-config.namespace or "internal";
|
meta = {
|
||||||
meta = {
|
name = raw-snowfall-config.meta.name or null;
|
||||||
name = raw-snowfall-config.meta.name or null;
|
title = raw-snowfall-config.meta.title or null;
|
||||||
title = raw-snowfall-config.meta.title or null;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
user-inputs = user-options.inputs // {src = user-options.src;};
|
user-inputs = user-options.inputs // {
|
||||||
|
src = user-options.src;
|
||||||
|
};
|
||||||
|
|
||||||
inherit (core-inputs.nixpkgs.lib) assertMsg fix filterAttrs mergeAttrs fold recursiveUpdate callPackageWith isFunction;
|
inherit (core-inputs.nixpkgs.lib)
|
||||||
|
assertMsg
|
||||||
|
fix
|
||||||
|
filterAttrs
|
||||||
|
mergeAttrs
|
||||||
|
fold
|
||||||
|
recursiveUpdate
|
||||||
|
callPackageWith
|
||||||
|
isFunction
|
||||||
|
;
|
||||||
|
|
||||||
# Recursively merge a list of attribute sets.
|
# Recursively merge a list of attribute sets.
|
||||||
# Type: [Attrs] -> Attrs
|
# Type: [Attrs] -> Attrs
|
||||||
# Usage: merge-deep [{ x = 1; } { x = 2; }]
|
# Usage: merge-deep [{ x = 1; } { x = 2; }]
|
||||||
# result: { x = 2; }
|
# result: { x = 2; }
|
||||||
merge-deep = fold recursiveUpdate {};
|
merge-deep = fold recursiveUpdate { };
|
||||||
|
|
||||||
# Merge the root of a list of attribute sets.
|
# Merge the root of a list of attribute sets.
|
||||||
# Type: [Attrs] -> Attrs
|
# Type: [Attrs] -> Attrs
|
||||||
# Usage: merge-shallow [{ x = 1; } { x = 2; }]
|
# Usage: merge-shallow [{ x = 1; } { x = 2; }]
|
||||||
# result: { x = 2; }
|
# result: { x = 2; }
|
||||||
merge-shallow = fold mergeAttrs {};
|
merge-shallow = fold mergeAttrs { };
|
||||||
|
|
||||||
# Transform an attribute set of inputs into an attribute set where
|
# Transform an attribute set of inputs into an attribute set where
|
||||||
# the values are the inputs' `lib` attribute. Entries without a `lib`
|
# the values are the inputs' `lib` attribute. Entries without a `lib`
|
||||||
@@ -38,22 +48,20 @@ core-inputs: user-options: let
|
|||||||
# Type: Attrs -> Attrs
|
# Type: Attrs -> Attrs
|
||||||
# Usage: get-lib { x = nixpkgs; y = {}; }
|
# Usage: get-lib { x = nixpkgs; y = {}; }
|
||||||
# result: { x = nixpkgs.lib; }
|
# result: { x = nixpkgs.lib; }
|
||||||
get-libs = attrs: let
|
get-libs =
|
||||||
# @PERF(jakehamilton): Replace filter+map with a fold.
|
attrs:
|
||||||
attrs-with-libs =
|
let
|
||||||
filterAttrs
|
# @PERF(jakehamilton): Replace filter+map with a fold.
|
||||||
(name: value: builtins.isAttrs (value.lib or null))
|
attrs-with-libs = filterAttrs (name: value: builtins.isAttrs (value.lib or null)) attrs;
|
||||||
attrs;
|
libs = builtins.mapAttrs (name: input: input.lib) attrs-with-libs;
|
||||||
libs =
|
in
|
||||||
builtins.mapAttrs (name: input: input.lib) attrs-with-libs;
|
|
||||||
in
|
|
||||||
libs;
|
libs;
|
||||||
|
|
||||||
# Remove the `self` attribute from an attribute set.
|
# Remove the `self` attribute from an attribute set.
|
||||||
# Type: Attrs -> Attrs
|
# Type: Attrs -> Attrs
|
||||||
# Usage: without-self { self = {}; x = true; }
|
# Usage: without-self { self = {}; x = true; }
|
||||||
# result: { x = true; }
|
# result: { x = true; }
|
||||||
without-self = attrs: builtins.removeAttrs attrs ["self"];
|
without-self = attrs: builtins.removeAttrs attrs [ "self" ];
|
||||||
|
|
||||||
core-inputs-libs = get-libs (without-self core-inputs);
|
core-inputs-libs = get-libs (without-self core-inputs);
|
||||||
user-inputs-libs = get-libs (without-self user-inputs);
|
user-inputs-libs = get-libs (without-self user-inputs);
|
||||||
@@ -61,24 +69,28 @@ core-inputs: user-options: let
|
|||||||
# NOTE: This root is different to accommodate the creation
|
# NOTE: This root is different to accommodate the creation
|
||||||
# of a fake user-lib in order to run documentation on this flake.
|
# of a fake user-lib in order to run documentation on this flake.
|
||||||
snowfall-lib-root = "${core-inputs.src}/snowfall-lib";
|
snowfall-lib-root = "${core-inputs.src}/snowfall-lib";
|
||||||
snowfall-lib-dirs = let
|
snowfall-lib-dirs =
|
||||||
files = builtins.readDir snowfall-lib-root;
|
let
|
||||||
dirs = filterAttrs (name: kind: kind == "directory") files;
|
files = builtins.readDir snowfall-lib-root;
|
||||||
names = builtins.attrNames dirs;
|
dirs = filterAttrs (name: kind: kind == "directory") files;
|
||||||
in
|
names = builtins.attrNames dirs;
|
||||||
|
in
|
||||||
names;
|
names;
|
||||||
|
|
||||||
snowfall-lib = fix (
|
snowfall-lib = fix (
|
||||||
snowfall-lib: let
|
snowfall-lib:
|
||||||
|
let
|
||||||
attrs = {
|
attrs = {
|
||||||
inherit snowfall-lib snowfall-config core-inputs user-inputs;
|
inherit
|
||||||
|
snowfall-lib
|
||||||
|
snowfall-config
|
||||||
|
core-inputs
|
||||||
|
user-inputs
|
||||||
|
;
|
||||||
};
|
};
|
||||||
libs =
|
libs = builtins.map (dir: import "${snowfall-lib-root}/${dir}" attrs) snowfall-lib-dirs;
|
||||||
builtins.map
|
|
||||||
(dir: import "${snowfall-lib-root}/${dir}" attrs)
|
|
||||||
snowfall-lib-dirs;
|
|
||||||
in
|
in
|
||||||
merge-deep libs
|
merge-deep libs
|
||||||
);
|
);
|
||||||
|
|
||||||
snowfall-top-level-lib = filterAttrs (name: value: !builtins.isAttrs value) snowfall-lib;
|
snowfall-top-level-lib = filterAttrs (name: value: !builtins.isAttrs value) snowfall-lib;
|
||||||
@@ -88,34 +100,37 @@ core-inputs: user-options: let
|
|||||||
core-inputs-libs
|
core-inputs-libs
|
||||||
user-inputs-libs
|
user-inputs-libs
|
||||||
snowfall-top-level-lib
|
snowfall-top-level-lib
|
||||||
{snowfall = snowfall-lib;}
|
{ snowfall = snowfall-lib; }
|
||||||
];
|
];
|
||||||
|
|
||||||
user-lib-root = "${user-inputs.src}/lib";
|
user-lib-root = "${user-inputs.src}/lib";
|
||||||
user-lib-modules = snowfall-lib.fs.get-default-nix-files-recursive user-lib-root;
|
user-lib-modules = snowfall-lib.fs.get-default-nix-files-recursive user-lib-root;
|
||||||
|
|
||||||
user-lib = fix (
|
user-lib = fix (
|
||||||
user-lib: let
|
user-lib:
|
||||||
|
let
|
||||||
attrs = {
|
attrs = {
|
||||||
inherit (user-options) inputs;
|
inherit (user-options) inputs;
|
||||||
snowfall-inputs = core-inputs;
|
snowfall-inputs = core-inputs;
|
||||||
namespace = snowfall-config.namespace;
|
namespace = snowfall-config.namespace;
|
||||||
lib = merge-shallow [base-lib {${snowfall-config.namespace} = user-lib;}];
|
lib = merge-shallow [
|
||||||
|
base-lib
|
||||||
|
{ ${snowfall-config.namespace} = user-lib; }
|
||||||
|
];
|
||||||
};
|
};
|
||||||
libs =
|
libs = builtins.map (
|
||||||
builtins.map
|
path:
|
||||||
(
|
let
|
||||||
path: let
|
imported-module = import path;
|
||||||
imported-module = import path;
|
in
|
||||||
in
|
if isFunction imported-module then
|
||||||
if isFunction imported-module
|
callPackageWith attrs path { }
|
||||||
then callPackageWith attrs path {}
|
# the only difference is that there is no `override` and `overrideDerivation` on returned value
|
||||||
# the only difference is that there is no `override` and `overrideDerivation` on returned value
|
else
|
||||||
else imported-module
|
imported-module
|
||||||
)
|
) user-lib-modules;
|
||||||
user-lib-modules;
|
|
||||||
in
|
in
|
||||||
merge-deep libs
|
merge-deep libs
|
||||||
);
|
);
|
||||||
|
|
||||||
lib = merge-deep [
|
lib = merge-deep [
|
||||||
@@ -126,5 +141,6 @@ core-inputs: user-options: let
|
|||||||
user-inputs-has-self = builtins.elem "self" (builtins.attrNames user-inputs);
|
user-inputs-has-self = builtins.elem "self" (builtins.attrNames user-inputs);
|
||||||
user-inputs-has-src = builtins.elem "src" (builtins.attrNames user-inputs);
|
user-inputs-has-src = builtins.elem "src" (builtins.attrNames user-inputs);
|
||||||
in
|
in
|
||||||
assert (assertMsg user-inputs-has-self "Missing attribute `self` for mkLib.");
|
assert (assertMsg user-inputs-has-self "Missing attribute `self` for mkLib.");
|
||||||
assert (assertMsg user-inputs-has-src "Missing attribute `src` for mkLib."); lib
|
assert (assertMsg user-inputs-has-src "Missing attribute `src` for mkLib.");
|
||||||
|
lib
|
||||||
|
|||||||
@@ -3,9 +3,22 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
snowfall-lib,
|
snowfall-lib,
|
||||||
snowfall-config,
|
snowfall-config,
|
||||||
}: let
|
}:
|
||||||
inherit (core-inputs.nixpkgs.lib) assertMsg foldl filterAttrs const mapAttrs mapAttrs' hasSuffix removeSuffix nameValuePair traceVal;
|
let
|
||||||
in rec {
|
inherit (core-inputs.nixpkgs.lib)
|
||||||
|
assertMsg
|
||||||
|
foldl
|
||||||
|
filterAttrs
|
||||||
|
const
|
||||||
|
mapAttrs
|
||||||
|
mapAttrs'
|
||||||
|
hasSuffix
|
||||||
|
removeSuffix
|
||||||
|
nameValuePair
|
||||||
|
traceVal
|
||||||
|
;
|
||||||
|
in
|
||||||
|
rec {
|
||||||
flake = rec {
|
flake = rec {
|
||||||
## Remove the `self` attribute from an attribute set.
|
## Remove the `self` attribute from an attribute set.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -17,7 +30,7 @@ in rec {
|
|||||||
## { x = true; }
|
## { x = true; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
without-self = flake-inputs: builtins.removeAttrs flake-inputs ["self"];
|
without-self = flake-inputs: builtins.removeAttrs flake-inputs [ "self" ];
|
||||||
|
|
||||||
## Remove the `src` attribute from an attribute set.
|
## Remove the `src` attribute from an attribute set.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -29,7 +42,7 @@ in rec {
|
|||||||
## { x = true; }
|
## { x = true; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
without-src = flake-inputs: builtins.removeAttrs flake-inputs ["src"];
|
without-src = flake-inputs: builtins.removeAttrs flake-inputs [ "src" ];
|
||||||
|
|
||||||
## Remove the `src` and `self` attributes from an attribute set.
|
## Remove the `src` and `self` attributes from an attribute set.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -53,10 +66,9 @@ in rec {
|
|||||||
## { x = true; }
|
## { x = true; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
without-snowfall-options = flake-options:
|
without-snowfall-options =
|
||||||
builtins.removeAttrs
|
flake-options:
|
||||||
flake-options
|
builtins.removeAttrs flake-options [
|
||||||
[
|
|
||||||
"systems"
|
"systems"
|
||||||
"modules"
|
"modules"
|
||||||
"overlays"
|
"overlays"
|
||||||
@@ -83,86 +95,91 @@ in rec {
|
|||||||
## { x = nixpkgs.lib; }
|
## { x = nixpkgs.lib; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
get-libs = attrs: let
|
get-libs =
|
||||||
# @PERF(jakehamilton): Replace filter+map with a fold.
|
attrs:
|
||||||
attrs-with-libs =
|
let
|
||||||
filterAttrs
|
# @PERF(jakehamilton): Replace filter+map with a fold.
|
||||||
(name: value: builtins.isAttrs (value.lib or null))
|
attrs-with-libs = filterAttrs (name: value: builtins.isAttrs (value.lib or null)) attrs;
|
||||||
attrs;
|
libs = builtins.mapAttrs (name: input: input.lib) attrs-with-libs;
|
||||||
libs =
|
in
|
||||||
builtins.mapAttrs (name: input: input.lib) attrs-with-libs;
|
|
||||||
in
|
|
||||||
libs;
|
libs;
|
||||||
};
|
};
|
||||||
|
|
||||||
mkFlake = full-flake-options: let
|
mkFlake =
|
||||||
namespace = snowfall-config.namespace or "internal";
|
full-flake-options:
|
||||||
custom-flake-options = flake.without-snowfall-options full-flake-options;
|
let
|
||||||
alias = full-flake-options.alias or {};
|
namespace = snowfall-config.namespace or "internal";
|
||||||
homes = snowfall-lib.home.create-homes (full-flake-options.homes or {});
|
custom-flake-options = flake.without-snowfall-options full-flake-options;
|
||||||
systems = snowfall-lib.system.create-systems {
|
alias = full-flake-options.alias or { };
|
||||||
systems = full-flake-options.systems or {};
|
homes = snowfall-lib.home.create-homes (full-flake-options.homes or { });
|
||||||
homes = full-flake-options.homes or {};
|
systems = snowfall-lib.system.create-systems {
|
||||||
};
|
systems = full-flake-options.systems or { };
|
||||||
hosts = snowfall-lib.attrs.merge-shallow [(full-flake-options.systems.hosts or {}) systems homes];
|
homes = full-flake-options.homes or { };
|
||||||
templates = snowfall-lib.template.create-templates {
|
|
||||||
overrides = full-flake-options.templates or {};
|
|
||||||
alias = alias.templates or {};
|
|
||||||
};
|
|
||||||
nixos-modules = snowfall-lib.module.create-modules {
|
|
||||||
src = snowfall-lib.fs.get-snowfall-file "modules/nixos";
|
|
||||||
overrides = full-flake-options.modules.nixos or {};
|
|
||||||
alias = alias.modules.nixos or {};
|
|
||||||
};
|
|
||||||
darwin-modules = snowfall-lib.module.create-modules {
|
|
||||||
src = snowfall-lib.fs.get-snowfall-file "modules/darwin";
|
|
||||||
overrides = full-flake-options.modules.darwin or {};
|
|
||||||
alias = alias.modules.darwin or {};
|
|
||||||
};
|
|
||||||
home-modules = snowfall-lib.module.create-modules {
|
|
||||||
src = snowfall-lib.fs.get-snowfall-file "modules/home";
|
|
||||||
overrides = full-flake-options.modules.home or {};
|
|
||||||
alias = alias.modules.home or {};
|
|
||||||
};
|
|
||||||
overlays = snowfall-lib.overlay.create-overlays {
|
|
||||||
inherit namespace;
|
|
||||||
extra-overlays = full-flake-options.extra-exported-overlays or {};
|
|
||||||
};
|
|
||||||
channels = full-flake-options.channels or {};
|
|
||||||
|
|
||||||
outputs-builder = channels: let
|
|
||||||
user-outputs-builder =
|
|
||||||
full-flake-options.outputs-builder
|
|
||||||
or full-flake-options.outputsBuilder
|
|
||||||
or (const {});
|
|
||||||
user-outputs = user-outputs-builder channels;
|
|
||||||
packages = snowfall-lib.package.create-packages {
|
|
||||||
inherit channels namespace;
|
|
||||||
overrides = (full-flake-options.packages or {}) // (user-outputs.packages or {});
|
|
||||||
alias = alias.packages or {};
|
|
||||||
};
|
};
|
||||||
shells = snowfall-lib.shell.create-shells {
|
hosts = snowfall-lib.attrs.merge-shallow [
|
||||||
inherit channels;
|
(full-flake-options.systems.hosts or { })
|
||||||
overrides = (full-flake-options.shells or {}) // (user-outputs.devShells or {});
|
systems
|
||||||
alias = alias.shells or {};
|
homes
|
||||||
|
];
|
||||||
|
templates = snowfall-lib.template.create-templates {
|
||||||
|
overrides = full-flake-options.templates or { };
|
||||||
|
alias = alias.templates or { };
|
||||||
};
|
};
|
||||||
checks = snowfall-lib.check.create-checks {
|
nixos-modules = snowfall-lib.module.create-modules {
|
||||||
inherit channels;
|
src = snowfall-lib.fs.get-snowfall-file "modules/nixos";
|
||||||
overrides = (full-flake-options.checks or {}) // (user-outputs.checks or {});
|
overrides = full-flake-options.modules.nixos or { };
|
||||||
alias = alias.checks or {};
|
alias = alias.modules.nixos or { };
|
||||||
};
|
};
|
||||||
|
darwin-modules = snowfall-lib.module.create-modules {
|
||||||
outputs = {
|
src = snowfall-lib.fs.get-snowfall-file "modules/darwin";
|
||||||
inherit packages checks;
|
overrides = full-flake-options.modules.darwin or { };
|
||||||
|
alias = alias.modules.darwin or { };
|
||||||
devShells = shells;
|
|
||||||
};
|
};
|
||||||
in
|
home-modules = snowfall-lib.module.create-modules {
|
||||||
snowfall-lib.attrs.merge-deep [user-outputs outputs];
|
src = snowfall-lib.fs.get-snowfall-file "modules/home";
|
||||||
|
overrides = full-flake-options.modules.home or { };
|
||||||
|
alias = alias.modules.home or { };
|
||||||
|
};
|
||||||
|
overlays = snowfall-lib.overlay.create-overlays {
|
||||||
|
inherit namespace;
|
||||||
|
extra-overlays = full-flake-options.extra-exported-overlays or { };
|
||||||
|
};
|
||||||
|
channels = full-flake-options.channels or { };
|
||||||
|
|
||||||
flake-options =
|
outputs-builder =
|
||||||
custom-flake-options
|
channels:
|
||||||
// {
|
let
|
||||||
|
user-outputs-builder =
|
||||||
|
full-flake-options.outputs-builder or full-flake-options.outputsBuilder or (const { });
|
||||||
|
user-outputs = user-outputs-builder channels;
|
||||||
|
packages = snowfall-lib.package.create-packages {
|
||||||
|
inherit channels namespace;
|
||||||
|
overrides = (full-flake-options.packages or { }) // (user-outputs.packages or { });
|
||||||
|
alias = alias.packages or { };
|
||||||
|
};
|
||||||
|
shells = snowfall-lib.shell.create-shells {
|
||||||
|
inherit channels;
|
||||||
|
overrides = (full-flake-options.shells or { }) // (user-outputs.devShells or { });
|
||||||
|
alias = alias.shells or { };
|
||||||
|
};
|
||||||
|
checks = snowfall-lib.check.create-checks {
|
||||||
|
inherit channels;
|
||||||
|
overrides = (full-flake-options.checks or { }) // (user-outputs.checks or { });
|
||||||
|
alias = alias.checks or { };
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = {
|
||||||
|
inherit packages checks;
|
||||||
|
|
||||||
|
devShells = shells;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
snowfall-lib.attrs.merge-deep [
|
||||||
|
user-outputs
|
||||||
|
outputs
|
||||||
|
];
|
||||||
|
|
||||||
|
flake-options = custom-flake-options // {
|
||||||
inherit hosts templates;
|
inherit hosts templates;
|
||||||
inherit (user-inputs) self;
|
inherit (user-inputs) self;
|
||||||
|
|
||||||
@@ -173,41 +190,34 @@ in rec {
|
|||||||
darwinModules = darwin-modules;
|
darwinModules = darwin-modules;
|
||||||
homeModules = home-modules;
|
homeModules = home-modules;
|
||||||
|
|
||||||
channelsConfig =
|
channelsConfig = full-flake-options.channels-config or full-flake-options.channelsConfig or { };
|
||||||
full-flake-options.channels-config
|
|
||||||
or full-flake-options.channelsConfig
|
|
||||||
or {};
|
|
||||||
|
|
||||||
channels =
|
channels = mapAttrs (
|
||||||
mapAttrs
|
channel: config:
|
||||||
(channel: config:
|
config
|
||||||
config
|
// {
|
||||||
// {
|
overlaysBuilder = snowfall-lib.overlay.create-overlays-builder {
|
||||||
overlaysBuilder = snowfall-lib.overlay.create-overlays-builder {
|
inherit namespace;
|
||||||
inherit namespace;
|
extra-overlays = full-flake-options.overlays or [ ];
|
||||||
extra-overlays = full-flake-options.overlays or [];
|
};
|
||||||
};
|
}
|
||||||
})
|
) ({ nixpkgs = { }; } // channels);
|
||||||
({nixpkgs = {};} // channels);
|
|
||||||
|
|
||||||
outputsBuilder = outputs-builder;
|
outputsBuilder = outputs-builder;
|
||||||
|
|
||||||
snowfall = {
|
snowfall = {
|
||||||
config = snowfall-config;
|
config = snowfall-config;
|
||||||
raw-config = full-flake-options.snowfall or {};
|
raw-config = full-flake-options.snowfall or { };
|
||||||
user-lib = snowfall-lib.internal.user-lib;
|
user-lib = snowfall-lib.internal.user-lib;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
flake-utils-plus-outputs =
|
flake-utils-plus-outputs = core-inputs.flake-utils-plus.lib.mkFlake flake-options;
|
||||||
core-inputs.flake-utils-plus.lib.mkFlake flake-options;
|
|
||||||
|
|
||||||
flake-outputs =
|
flake-outputs = flake-utils-plus-outputs // {
|
||||||
flake-utils-plus-outputs
|
|
||||||
// {
|
|
||||||
inherit overlays;
|
inherit overlays;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
flake-outputs
|
flake-outputs
|
||||||
// {
|
// {
|
||||||
packages =
|
packages =
|
||||||
@@ -215,23 +225,23 @@ in rec {
|
|||||||
// (builtins.listToAttrs (
|
// (builtins.listToAttrs (
|
||||||
builtins.map (system: {
|
builtins.map (system: {
|
||||||
name = system;
|
name = system;
|
||||||
value =
|
value = flake-outputs.packages.${system} // {
|
||||||
flake-outputs.packages.${system}
|
homeConfigurations =
|
||||||
// {
|
let
|
||||||
homeConfigurations = let
|
|
||||||
homeNames = filterAttrs (_: home: home.system == system) homes;
|
homeNames = filterAttrs (_: home: home.system == system) homes;
|
||||||
homeConfigurations = mapAttrs (home-name: _: flake-outputs.homeConfigurations.${home-name}) homeNames;
|
homeConfigurations = mapAttrs (
|
||||||
renamedHomeConfigurations =
|
home-name: _: flake-outputs.homeConfigurations.${home-name}
|
||||||
mapAttrs' (
|
) homeNames;
|
||||||
name: value:
|
renamedHomeConfigurations = mapAttrs' (
|
||||||
if hasSuffix "@${system}" name
|
name: value:
|
||||||
then nameValuePair (removeSuffix "@${system}" name) value
|
if hasSuffix "@${system}" name then
|
||||||
else nameValuePair name value
|
nameValuePair (removeSuffix "@${system}" name) value
|
||||||
)
|
else
|
||||||
homeConfigurations;
|
nameValuePair name value
|
||||||
|
) homeConfigurations;
|
||||||
in
|
in
|
||||||
renamedHomeConfigurations;
|
renamedHomeConfigurations;
|
||||||
};
|
};
|
||||||
}) (builtins.attrNames flake-outputs.pkgs)
|
}) (builtins.attrNames flake-outputs.pkgs)
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,10 +3,12 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
snowfall-lib,
|
snowfall-lib,
|
||||||
snowfall-config,
|
snowfall-config,
|
||||||
}: let
|
}:
|
||||||
|
let
|
||||||
inherit (builtins) baseNameOf dirOf;
|
inherit (builtins) baseNameOf dirOf;
|
||||||
inherit (core-inputs.nixpkgs.lib) id foldr flip;
|
inherit (core-inputs.nixpkgs.lib) id foldr flip;
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
fp = rec {
|
fp = rec {
|
||||||
## Compose two functions.
|
## Compose two functions.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -18,7 +20,9 @@ in {
|
|||||||
## (x: add-two (add-one x))
|
## (x: add-two (add-one x))
|
||||||
## ```
|
## ```
|
||||||
#@ (b -> c) -> (a -> b) -> a -> c
|
#@ (b -> c) -> (a -> b) -> a -> c
|
||||||
compose = f: g: x: f (g x);
|
compose =
|
||||||
|
f: g: x:
|
||||||
|
f (g x);
|
||||||
|
|
||||||
## Compose many functions.
|
## Compose many functions.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
|
|||||||
@@ -3,13 +3,20 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
snowfall-lib,
|
snowfall-lib,
|
||||||
snowfall-config,
|
snowfall-config,
|
||||||
}: let
|
}:
|
||||||
|
let
|
||||||
inherit (builtins) readDir pathExists;
|
inherit (builtins) readDir pathExists;
|
||||||
inherit (core-inputs) flake-utils-plus;
|
inherit (core-inputs) flake-utils-plus;
|
||||||
inherit (core-inputs.nixpkgs.lib) assertMsg filterAttrs mapAttrsToList flatten;
|
inherit (core-inputs.nixpkgs.lib)
|
||||||
|
assertMsg
|
||||||
|
filterAttrs
|
||||||
|
mapAttrsToList
|
||||||
|
flatten
|
||||||
|
;
|
||||||
|
|
||||||
file-name-regex = "(.*)\\.(.*)$";
|
file-name-regex = "(.*)\\.(.*)$";
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
fs = rec {
|
fs = rec {
|
||||||
## Matchers for file kinds. These are often used with `readDir`.
|
## Matchers for file kinds. These are often used with `readDir`.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -72,10 +79,7 @@ in {
|
|||||||
## { "my-file.txt" = "regular"; }
|
## { "my-file.txt" = "regular"; }
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> Attrs
|
#@ Path -> Attrs
|
||||||
safe-read-directory = path:
|
safe-read-directory = path: if pathExists path then readDir path else { };
|
||||||
if pathExists path
|
|
||||||
then readDir path
|
|
||||||
else {};
|
|
||||||
|
|
||||||
## Get directories at a given path.
|
## Get directories at a given path.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -87,10 +91,12 @@ in {
|
|||||||
## [ "./something/a-directory" ]
|
## [ "./something/a-directory" ]
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-directories = path: let
|
get-directories =
|
||||||
entries = safe-read-directory path;
|
path:
|
||||||
filtered-entries = filterAttrs (name: kind: is-directory-kind kind) entries;
|
let
|
||||||
in
|
entries = safe-read-directory path;
|
||||||
|
filtered-entries = filterAttrs (name: kind: is-directory-kind kind) entries;
|
||||||
|
in
|
||||||
mapAttrsToList (name: kind: "${path}/${name}") filtered-entries;
|
mapAttrsToList (name: kind: "${path}/${name}") filtered-entries;
|
||||||
|
|
||||||
## Get files at a given path.
|
## Get files at a given path.
|
||||||
@@ -103,10 +109,12 @@ in {
|
|||||||
## [ "./something/a-file" ]
|
## [ "./something/a-file" ]
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-files = path: let
|
get-files =
|
||||||
entries = safe-read-directory path;
|
path:
|
||||||
filtered-entries = filterAttrs (name: kind: is-file-kind kind) entries;
|
let
|
||||||
in
|
entries = safe-read-directory path;
|
||||||
|
filtered-entries = filterAttrs (name: kind: is-file-kind kind) entries;
|
||||||
|
in
|
||||||
mapAttrsToList (name: kind: "${path}/${name}") filtered-entries;
|
mapAttrsToList (name: kind: "${path}/${name}") filtered-entries;
|
||||||
|
|
||||||
## Get files at a given path, traversing any directories within.
|
## Get files at a given path, traversing any directories within.
|
||||||
@@ -119,23 +127,21 @@ in {
|
|||||||
## [ "./something/some-directory/a-file" ]
|
## [ "./something/some-directory/a-file" ]
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-files-recursive = path: let
|
get-files-recursive =
|
||||||
entries = safe-read-directory path;
|
path:
|
||||||
filtered-entries =
|
let
|
||||||
filterAttrs
|
entries = safe-read-directory path;
|
||||||
(name: kind: (is-file-kind kind) || (is-directory-kind kind))
|
filtered-entries = filterAttrs (
|
||||||
entries;
|
name: kind: (is-file-kind kind) || (is-directory-kind kind)
|
||||||
map-file = name: kind: let
|
) entries;
|
||||||
path' = "${path}/${name}";
|
map-file =
|
||||||
|
name: kind:
|
||||||
|
let
|
||||||
|
path' = "${path}/${name}";
|
||||||
|
in
|
||||||
|
if is-directory-kind kind then get-files-recursive path' else path';
|
||||||
|
files = snowfall-lib.attrs.map-concat-attrs-to-list map-file filtered-entries;
|
||||||
in
|
in
|
||||||
if is-directory-kind kind
|
|
||||||
then get-files-recursive path'
|
|
||||||
else path';
|
|
||||||
files =
|
|
||||||
snowfall-lib.attrs.map-concat-attrs-to-list
|
|
||||||
map-file
|
|
||||||
filtered-entries;
|
|
||||||
in
|
|
||||||
files;
|
files;
|
||||||
|
|
||||||
## Get nix files at a given path.
|
## Get nix files at a given path.
|
||||||
@@ -148,10 +154,7 @@ in {
|
|||||||
## [ "./something/a.nix" ]
|
## [ "./something/a.nix" ]
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-nix-files = path:
|
get-nix-files = path: builtins.filter (snowfall-lib.path.has-file-extension "nix") (get-files path);
|
||||||
builtins.filter
|
|
||||||
(snowfall-lib.path.has-file-extension "nix")
|
|
||||||
(get-files path);
|
|
||||||
|
|
||||||
## Get nix files at a given path, traversing any directories within.
|
## Get nix files at a given path, traversing any directories within.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -163,10 +166,8 @@ in {
|
|||||||
## [ "./something/a.nix" ]
|
## [ "./something/a.nix" ]
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-nix-files-recursive = path:
|
get-nix-files-recursive =
|
||||||
builtins.filter
|
path: builtins.filter (snowfall-lib.path.has-file-extension "nix") (get-files-recursive path);
|
||||||
(snowfall-lib.path.has-file-extension "nix")
|
|
||||||
(get-files-recursive path);
|
|
||||||
|
|
||||||
## Get nix files at a given path named "default.nix".
|
## Get nix files at a given path named "default.nix".
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -178,10 +179,8 @@ in {
|
|||||||
## [ "./something/default.nix" ]
|
## [ "./something/default.nix" ]
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-default-nix-files = path:
|
get-default-nix-files =
|
||||||
builtins.filter
|
path: builtins.filter (name: builtins.baseNameOf name == "default.nix") (get-files path);
|
||||||
(name: builtins.baseNameOf name == "default.nix")
|
|
||||||
(get-files path);
|
|
||||||
|
|
||||||
## Get nix files at a given path named "default.nix", traversing any directories within.
|
## Get nix files at a given path named "default.nix", traversing any directories within.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -193,10 +192,8 @@ in {
|
|||||||
## [ "./something/some-directory/default.nix" ]
|
## [ "./something/some-directory/default.nix" ]
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-default-nix-files-recursive = path:
|
get-default-nix-files-recursive =
|
||||||
builtins.filter
|
path: builtins.filter (name: builtins.baseNameOf name == "default.nix") (get-files-recursive path);
|
||||||
(name: builtins.baseNameOf name == "default.nix")
|
|
||||||
(get-files-recursive path);
|
|
||||||
|
|
||||||
## Get nix files at a given path not named "default.nix".
|
## Get nix files at a given path not named "default.nix".
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -208,14 +205,12 @@ in {
|
|||||||
## [ "./something/a.nix" ]
|
## [ "./something/a.nix" ]
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-non-default-nix-files = path:
|
get-non-default-nix-files =
|
||||||
builtins.filter
|
path:
|
||||||
(
|
builtins.filter (
|
||||||
name:
|
name:
|
||||||
(snowfall-lib.path.has-file-extension "nix" name)
|
(snowfall-lib.path.has-file-extension "nix" name) && (builtins.baseNameOf name != "default.nix")
|
||||||
&& (builtins.baseNameOf name != "default.nix")
|
) (get-files path);
|
||||||
)
|
|
||||||
(get-files path);
|
|
||||||
|
|
||||||
## Get nix files at a given path not named "default.nix", traversing any directories within.
|
## Get nix files at a given path not named "default.nix", traversing any directories within.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -227,13 +222,11 @@ in {
|
|||||||
## [ "./something/some-directory/a.nix" ]
|
## [ "./something/some-directory/a.nix" ]
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-non-default-nix-files-recursive = path:
|
get-non-default-nix-files-recursive =
|
||||||
builtins.filter
|
path:
|
||||||
(
|
builtins.filter (
|
||||||
name:
|
name:
|
||||||
(snowfall-lib.path.has-file-extension "nix" name)
|
(snowfall-lib.path.has-file-extension "nix" name) && (builtins.baseNameOf name != "default.nix")
|
||||||
&& (builtins.baseNameOf name != "default.nix")
|
) (get-files-recursive path);
|
||||||
)
|
|
||||||
(get-files-recursive path);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
snowfall-lib,
|
snowfall-lib,
|
||||||
snowfall-config,
|
snowfall-config,
|
||||||
}: let
|
}:
|
||||||
inherit
|
let
|
||||||
(core-inputs.nixpkgs.lib)
|
inherit (core-inputs.nixpkgs.lib)
|
||||||
assertMsg
|
assertMsg
|
||||||
foldl
|
foldl
|
||||||
head
|
head
|
||||||
@@ -30,24 +30,26 @@
|
|||||||
|
|
||||||
user-homes-root = snowfall-lib.fs.get-snowfall-file "homes";
|
user-homes-root = snowfall-lib.fs.get-snowfall-file "homes";
|
||||||
user-modules-root = snowfall-lib.fs.get-snowfall-file "modules";
|
user-modules-root = snowfall-lib.fs.get-snowfall-file "modules";
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
home = rec {
|
home = rec {
|
||||||
# Modules in home-manager expect `hm` to be available directly on `lib` itself.
|
# Modules in home-manager expect `hm` to be available directly on `lib` itself.
|
||||||
home-lib =
|
home-lib =
|
||||||
# NOTE: This prevents an error during evaluation if the input does
|
# NOTE: This prevents an error during evaluation if the input does
|
||||||
# not exist.
|
# not exist.
|
||||||
if user-inputs ? home-manager
|
if user-inputs ? home-manager then
|
||||||
then
|
snowfall-lib.internal.system-lib.extend (
|
||||||
snowfall-lib.internal.system-lib.extend
|
final: prev:
|
||||||
(final: prev:
|
|
||||||
# NOTE: This order is important, this library's extend and other utilities must write
|
# NOTE: This order is important, this library's extend and other utilities must write
|
||||||
# _over_ the original `system-lib`.
|
# _over_ the original `system-lib`.
|
||||||
snowfall-lib.internal.system-lib
|
snowfall-lib.internal.system-lib
|
||||||
// prev
|
// prev
|
||||||
// {
|
// {
|
||||||
hm = snowfall-lib.internal.system-lib.home-manager.hm;
|
hm = snowfall-lib.internal.system-lib.home-manager.hm;
|
||||||
})
|
}
|
||||||
else {};
|
)
|
||||||
|
else
|
||||||
|
{ };
|
||||||
|
|
||||||
## Get the user and host from a combined string.
|
## Get the user and host from a combined string.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -59,18 +61,18 @@ in {
|
|||||||
## { user = "myuser"; host = "myhost"; }
|
## { user = "myuser"; host = "myhost"; }
|
||||||
## ```
|
## ```
|
||||||
#@ String -> Attrs
|
#@ String -> Attrs
|
||||||
split-user-and-host = target: let
|
split-user-and-host =
|
||||||
raw-name-parts = builtins.split "@" target;
|
target:
|
||||||
name-parts = builtins.filter builtins.isString raw-name-parts;
|
let
|
||||||
|
raw-name-parts = builtins.split "@" target;
|
||||||
|
name-parts = builtins.filter builtins.isString raw-name-parts;
|
||||||
|
|
||||||
user = builtins.elemAt name-parts 0;
|
user = builtins.elemAt name-parts 0;
|
||||||
host =
|
host = if builtins.length name-parts > 1 then builtins.elemAt name-parts 1 else "";
|
||||||
if builtins.length name-parts > 1
|
in
|
||||||
then builtins.elemAt name-parts 1
|
{
|
||||||
else "";
|
inherit user host;
|
||||||
in {
|
};
|
||||||
inherit user host;
|
|
||||||
};
|
|
||||||
|
|
||||||
## Create a home.
|
## Create a home.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -82,36 +84,40 @@ in {
|
|||||||
## <flake-utils-plus-home-configuration>
|
## <flake-utils-plus-home-configuration>
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-home = {
|
create-home =
|
||||||
path,
|
{
|
||||||
name ? builtins.unsafeDiscardStringContext (snowfall-lib.system.get-inferred-system-name path),
|
path,
|
||||||
modules ? [],
|
name ? builtins.unsafeDiscardStringContext (snowfall-lib.system.get-inferred-system-name path),
|
||||||
specialArgs ? {},
|
modules ? [ ],
|
||||||
channelName ? "nixpkgs",
|
specialArgs ? { },
|
||||||
system ? "x86_64-linux",
|
channelName ? "nixpkgs",
|
||||||
}: let
|
system ? "x86_64-linux",
|
||||||
user-metadata = split-user-and-host name;
|
}:
|
||||||
unique-name =
|
let
|
||||||
if user-metadata.host == ""
|
user-metadata = split-user-and-host name;
|
||||||
then "${user-metadata.user}@${system}"
|
unique-name = if user-metadata.host == "" then "${user-metadata.user}@${system}" else name;
|
||||||
else name;
|
|
||||||
|
|
||||||
# NOTE: home-manager has trouble with `pkgs` recursion if it isn't passed in here.
|
# NOTE: home-manager has trouble with `pkgs` recursion if it isn't passed in here.
|
||||||
pkgs = user-inputs.self.pkgs.${system}.${channelName} // {lib = home-lib;};
|
pkgs = user-inputs.self.pkgs.${system}.${channelName} // {
|
||||||
lib = home-lib;
|
lib = home-lib;
|
||||||
in
|
};
|
||||||
assert assertMsg (user-inputs ? home-manager) "In order to create home-manager configurations, you must include `home-manager` as a flake input.";
|
lib = home-lib;
|
||||||
assert assertMsg ((user-metadata.host != "") || !(hasInfix "@" name)) "Snowfall Lib homes must be named with the format: user@system"; {
|
in
|
||||||
|
assert assertMsg (user-inputs ? home-manager)
|
||||||
|
"In order to create home-manager configurations, you must include `home-manager` as a flake input.";
|
||||||
|
assert assertMsg (
|
||||||
|
(user-metadata.host != "") || !(hasInfix "@" name)
|
||||||
|
) "Snowfall Lib homes must be named with the format: user@system";
|
||||||
|
{
|
||||||
inherit channelName system;
|
inherit channelName system;
|
||||||
|
|
||||||
output = "homeConfigurations";
|
output = "homeConfigurations";
|
||||||
|
|
||||||
modules =
|
modules = [
|
||||||
[
|
path
|
||||||
path
|
../../modules/home/user/default.nix
|
||||||
../../modules/home/user/default.nix
|
]
|
||||||
]
|
++ modules;
|
||||||
++ modules;
|
|
||||||
|
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
inherit system;
|
inherit system;
|
||||||
@@ -127,30 +133,37 @@ in {
|
|||||||
inherit pkgs lib;
|
inherit pkgs lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
builder = args:
|
builder =
|
||||||
user-inputs.home-manager.lib.homeManagerConfiguration
|
args:
|
||||||
((builtins.removeAttrs args ["system" "specialArgs"])
|
user-inputs.home-manager.lib.homeManagerConfiguration (
|
||||||
|
(builtins.removeAttrs args [
|
||||||
|
"system"
|
||||||
|
"specialArgs"
|
||||||
|
])
|
||||||
// {
|
// {
|
||||||
inherit pkgs lib;
|
inherit pkgs lib;
|
||||||
|
|
||||||
modules =
|
modules = args.modules ++ [
|
||||||
args.modules
|
(
|
||||||
++ [
|
module-args:
|
||||||
(module-args:
|
import ./nix-registry-module.nix (
|
||||||
import ./nix-registry-module.nix (module-args
|
module-args
|
||||||
// {
|
// {
|
||||||
inherit user-inputs core-inputs;
|
inherit user-inputs core-inputs;
|
||||||
}))
|
}
|
||||||
{
|
)
|
||||||
snowfallorg.user = {
|
)
|
||||||
name = mkDefault user-metadata.user;
|
{
|
||||||
enable = mkDefault true;
|
snowfallorg.user = {
|
||||||
};
|
name = mkDefault user-metadata.user;
|
||||||
}
|
enable = mkDefault true;
|
||||||
];
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
extraSpecialArgs = specialArgs // args.specialArgs;
|
extraSpecialArgs = specialArgs // args.specialArgs;
|
||||||
});
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
## Get structured data about all homes for a given target.
|
## Get structured data about all homes for a given target.
|
||||||
@@ -163,28 +176,30 @@ in {
|
|||||||
## [ { system = "x86_64-linux"; name = "my-home"; path = "/homes/x86_64-linux/my-home";} ]
|
## [ { system = "x86_64-linux"; name = "my-home"; path = "/homes/x86_64-linux/my-home";} ]
|
||||||
## ```
|
## ```
|
||||||
#@ String -> [Attrs]
|
#@ String -> [Attrs]
|
||||||
get-target-homes-metadata = target: let
|
get-target-homes-metadata =
|
||||||
homes = snowfall-lib.fs.get-directories target;
|
target:
|
||||||
existing-homes = builtins.filter (home: builtins.pathExists "${home}/default.nix") homes;
|
let
|
||||||
create-home-metadata = path: let
|
homes = snowfall-lib.fs.get-directories target;
|
||||||
# We are building flake outputs based on file contents. Nix doesn't like this
|
existing-homes = builtins.filter (home: builtins.pathExists "${home}/default.nix") homes;
|
||||||
# so we have to explicitly discard the string's path context to allow us to
|
create-home-metadata =
|
||||||
# use the name as a variable.
|
path:
|
||||||
basename = builtins.unsafeDiscardStringContext (builtins.baseNameOf path);
|
let
|
||||||
# We are building flake outputs based on file contents. Nix doesn't like this
|
# We are building flake outputs based on file contents. Nix doesn't like this
|
||||||
# so we have to explicitly discard the string's path context to allow us to
|
# so we have to explicitly discard the string's path context to allow us to
|
||||||
# use the name as a variable.
|
# use the name as a variable.
|
||||||
system = builtins.unsafeDiscardStringContext (builtins.baseNameOf target);
|
basename = builtins.unsafeDiscardStringContext (builtins.baseNameOf path);
|
||||||
name =
|
# We are building flake outputs based on file contents. Nix doesn't like this
|
||||||
if !(hasInfix "@" basename)
|
# so we have to explicitly discard the string's path context to allow us to
|
||||||
then "${basename}@${system}"
|
# use the name as a variable.
|
||||||
else basename;
|
system = builtins.unsafeDiscardStringContext (builtins.baseNameOf target);
|
||||||
in {
|
name = if !(hasInfix "@" basename) then "${basename}@${system}" else basename;
|
||||||
path = "${path}/default.nix";
|
in
|
||||||
inherit name system;
|
{
|
||||||
};
|
path = "${path}/default.nix";
|
||||||
home-configurations = builtins.map create-home-metadata existing-homes;
|
inherit name system;
|
||||||
in
|
};
|
||||||
|
home-configurations = builtins.map create-home-metadata existing-homes;
|
||||||
|
in
|
||||||
home-configurations;
|
home-configurations;
|
||||||
|
|
||||||
## Create all available homes.
|
## Create all available homes.
|
||||||
@@ -197,36 +212,45 @@ in {
|
|||||||
## { "my-user@my-system" = <flake-utils-plus-home-configuration>; }
|
## { "my-user@my-system" = <flake-utils-plus-home-configuration>; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-homes = homes: let
|
create-homes =
|
||||||
targets = snowfall-lib.fs.get-directories user-homes-root;
|
homes:
|
||||||
target-homes-metadata = concatMap get-target-homes-metadata targets;
|
let
|
||||||
|
targets = snowfall-lib.fs.get-directories user-homes-root;
|
||||||
|
target-homes-metadata = concatMap get-target-homes-metadata targets;
|
||||||
|
|
||||||
user-home-modules = snowfall-lib.module.create-modules {
|
user-home-modules = snowfall-lib.module.create-modules {
|
||||||
src = "${user-modules-root}/home";
|
src = "${user-modules-root}/home";
|
||||||
};
|
};
|
||||||
|
|
||||||
user-home-modules-list =
|
user-home-modules-list = mapAttrsToList (
|
||||||
mapAttrsToList
|
module-path: module:
|
||||||
(module-path: module: args @ {pkgs, ...}:
|
args@{ pkgs, ... }:
|
||||||
(module args)
|
(module args)
|
||||||
// {
|
// {
|
||||||
_file = "${user-homes-root}/${module-path}/default.nix";
|
_file = "${user-homes-root}/${module-path}/default.nix";
|
||||||
})
|
}
|
||||||
user-home-modules;
|
) user-home-modules;
|
||||||
|
|
||||||
create-home' = home-metadata: let
|
create-home' =
|
||||||
inherit (home-metadata) name;
|
home-metadata:
|
||||||
overrides = homes.users.${name} or {};
|
let
|
||||||
in {
|
inherit (home-metadata) name;
|
||||||
"${name}" = create-home (overrides
|
overrides = homes.users.${name} or { };
|
||||||
// home-metadata
|
in
|
||||||
// {
|
{
|
||||||
modules = user-home-modules-list ++ (homes.users.${name}.modules or []) ++ (homes.modules or []);
|
"${name}" = create-home (
|
||||||
});
|
overrides
|
||||||
};
|
// home-metadata
|
||||||
|
// {
|
||||||
|
modules = user-home-modules-list ++ (homes.users.${name}.modules or [ ]) ++ (homes.modules or [ ]);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
created-homes = foldl (homes: home-metadata: homes // (create-home' home-metadata)) {} target-homes-metadata;
|
created-homes = foldl (
|
||||||
in
|
homes: home-metadata: homes // (create-home' home-metadata)
|
||||||
|
) { } target-homes-metadata;
|
||||||
|
in
|
||||||
created-homes;
|
created-homes;
|
||||||
|
|
||||||
## Create system modules for home-manager integration.
|
## Create system modules for home-manager integration.
|
||||||
@@ -239,147 +263,163 @@ in {
|
|||||||
## [Module]
|
## [Module]
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> [Module]
|
#@ Attrs -> [Module]
|
||||||
create-home-system-modules = users: let
|
create-home-system-modules =
|
||||||
created-users = create-homes users;
|
users:
|
||||||
user-home-modules = snowfall-lib.module.create-modules {
|
let
|
||||||
src = "${user-modules-root}/home";
|
created-users = create-homes users;
|
||||||
};
|
user-home-modules = snowfall-lib.module.create-modules {
|
||||||
|
src = "${user-modules-root}/home";
|
||||||
|
};
|
||||||
|
|
||||||
shared-modules = builtins.map (module: {
|
shared-modules = builtins.map (module: {
|
||||||
config.home-manager.sharedModules = [module];
|
config.home-manager.sharedModules = [ module ];
|
||||||
}) (users.modules or []);
|
}) (users.modules or [ ]);
|
||||||
|
|
||||||
shared-user-modules =
|
shared-user-modules = mapAttrsToList (module-path: module: {
|
||||||
mapAttrsToList
|
|
||||||
(module-path: module: {
|
|
||||||
_file = "${user-modules-root}/home/${module-path}/default.nix";
|
_file = "${user-modules-root}/home/${module-path}/default.nix";
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
home-manager.sharedModules = [module];
|
home-manager.sharedModules = [ module ];
|
||||||
};
|
};
|
||||||
})
|
}) user-home-modules;
|
||||||
user-home-modules;
|
|
||||||
|
|
||||||
snowfall-user-home-module = {
|
snowfall-user-home-module = {
|
||||||
_file = "virtual:snowfallorg/modules/home/user/default.nix";
|
_file = "virtual:snowfallorg/modules/home/user/default.nix";
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
home-manager.sharedModules = [
|
home-manager.sharedModules = [
|
||||||
../../modules/home/user/default.nix
|
../../modules/home/user/default.nix
|
||||||
];
|
];
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
extra-special-args-module = args @ {
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
system ? pkgs.stdenv.hostPlatform.system,
|
|
||||||
target ? system,
|
|
||||||
format ? "home",
|
|
||||||
host ? "",
|
|
||||||
virtual ? (snowfall-lib.system.is-virtual target),
|
|
||||||
systems ? {},
|
|
||||||
...
|
|
||||||
}: {
|
|
||||||
_file = "virtual:snowfallorg/home/extra-special-args";
|
|
||||||
|
|
||||||
config = {
|
|
||||||
home-manager.extraSpecialArgs = {
|
|
||||||
inherit system target format virtual systems host;
|
|
||||||
inherit (snowfall-config) namespace;
|
|
||||||
|
|
||||||
lib = home-lib;
|
|
||||||
|
|
||||||
inputs = snowfall-lib.flake.without-src user-inputs;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
system-modules =
|
extra-special-args-module =
|
||||||
builtins.map
|
args@{
|
||||||
(
|
config,
|
||||||
name: let
|
pkgs,
|
||||||
|
system ? pkgs.stdenv.hostPlatform.system,
|
||||||
|
target ? system,
|
||||||
|
format ? "home",
|
||||||
|
host ? "",
|
||||||
|
virtual ? (snowfall-lib.system.is-virtual target),
|
||||||
|
systems ? { },
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
_file = "virtual:snowfallorg/home/extra-special-args";
|
||||||
|
|
||||||
|
config = {
|
||||||
|
home-manager.extraSpecialArgs = {
|
||||||
|
inherit
|
||||||
|
system
|
||||||
|
target
|
||||||
|
format
|
||||||
|
virtual
|
||||||
|
systems
|
||||||
|
host
|
||||||
|
;
|
||||||
|
inherit (snowfall-config) namespace;
|
||||||
|
|
||||||
|
lib = home-lib;
|
||||||
|
|
||||||
|
inputs = snowfall-lib.flake.without-src user-inputs;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
system-modules = builtins.map (
|
||||||
|
name:
|
||||||
|
let
|
||||||
created-user = created-users.${name};
|
created-user = created-users.${name};
|
||||||
user-module = head created-user.modules;
|
user-module = head created-user.modules;
|
||||||
other-modules = users.users.${name}.modules or [];
|
other-modules = users.users.${name}.modules or [ ];
|
||||||
user-name = created-user.specialArgs.user;
|
user-name = created-user.specialArgs.user;
|
||||||
in
|
in
|
||||||
args @ {
|
args@{
|
||||||
config,
|
config,
|
||||||
options,
|
options,
|
||||||
pkgs,
|
pkgs,
|
||||||
host ? "",
|
host ? "",
|
||||||
system ? pkgs.stdenv.hostPlatform.system,
|
system ? pkgs.stdenv.hostPlatform.system,
|
||||||
...
|
...
|
||||||
}: let
|
}:
|
||||||
host-matches =
|
let
|
||||||
(name == "${user-name}@${host}")
|
host-matches = (name == "${user-name}@${host}") || (name == "${user-name}@${system}");
|
||||||
|| (name == "${user-name}@${system}");
|
|
||||||
|
|
||||||
# NOTE: To conform to the config structure of home-manager, we have to
|
# NOTE: To conform to the config structure of home-manager, we have to
|
||||||
# remap the options coming from `snowfallorg.user.<name>.home.config` since `mkAliasDefinitions`
|
# remap the options coming from `snowfallorg.user.<name>.home.config` since `mkAliasDefinitions`
|
||||||
# does not let us target options within a submodule.
|
# does not let us target options within a submodule.
|
||||||
wrap-user-options = user-option:
|
wrap-user-options =
|
||||||
if (user-option ? "_type") && user-option._type == "merge"
|
user-option:
|
||||||
then
|
if (user-option ? "_type") && user-option._type == "merge" then
|
||||||
user-option
|
user-option
|
||||||
// {
|
// {
|
||||||
contents =
|
contents = builtins.map (
|
||||||
builtins.map
|
merge-entry: merge-entry.${user-name}.home.config or { }
|
||||||
(
|
) user-option.contents;
|
||||||
merge-entry:
|
}
|
||||||
merge-entry.${user-name}.home.config or {}
|
else
|
||||||
)
|
(builtins.trace ''
|
||||||
user-option.contents;
|
=============
|
||||||
}
|
Snowfall Lib:
|
||||||
else
|
Option value for `snowfallorg.users.${user-name}` was not detected to be merged.
|
||||||
(builtins.trace ''
|
|
||||||
=============
|
|
||||||
Snowfall Lib:
|
|
||||||
Option value for `snowfallorg.users.${user-name}` was not detected to be merged.
|
|
||||||
|
|
||||||
Please report the issue on GitHub with a link to your configuration so we can debug the problem:
|
Please report the issue on GitHub with a link to your configuration so we can debug the problem:
|
||||||
https://github.com/snowfallorg/lib/issues/new
|
https://github.com/snowfallorg/lib/issues/new
|
||||||
=============
|
=============
|
||||||
'')
|
'')
|
||||||
user-option;
|
user-option;
|
||||||
|
|
||||||
home-config = mkAliasAndWrapDefinitions wrap-user-options options.snowfallorg.users;
|
home-config = mkAliasAndWrapDefinitions wrap-user-options options.snowfallorg.users;
|
||||||
in {
|
in
|
||||||
_file = "virtual:snowfallorg/home/user/${name}";
|
{
|
||||||
|
_file = "virtual:snowfallorg/home/user/${name}";
|
||||||
|
|
||||||
config = mkIf host-matches {
|
config = mkIf host-matches {
|
||||||
# Initialize user information.
|
# Initialize user information.
|
||||||
snowfallorg.users.${user-name}.home.config = {
|
snowfallorg.users.${user-name}.home.config = {
|
||||||
snowfallorg.user = {
|
snowfallorg.user = {
|
||||||
enable = mkDefault true;
|
enable = mkDefault true;
|
||||||
name = mkDefault user-name;
|
name = mkDefault user-name;
|
||||||
};
|
|
||||||
|
|
||||||
# NOTE: specialArgs are not propagated by Home-Manager without this.
|
|
||||||
# However, not all specialArgs values can be set when using `_module.args`.
|
|
||||||
_module.args = builtins.removeAttrs ((users.users.${name}.specialArgs or {})
|
|
||||||
// {
|
|
||||||
namespace = snowfall-config.namespace;
|
|
||||||
})
|
|
||||||
["options" "config" "lib" "pkgs" "specialArgs" "host"];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
home-manager = {
|
# NOTE: specialArgs are not propagated by Home-Manager without this.
|
||||||
users.${user-name} = mkIf config.snowfallorg.users.${user-name}.home.enable ({pkgs, ...}: {
|
# However, not all specialArgs values can be set when using `_module.args`.
|
||||||
imports = (home-config.imports or []) ++ other-modules ++ [user-module];
|
_module.args =
|
||||||
config = builtins.removeAttrs home-config ["imports"];
|
builtins.removeAttrs
|
||||||
});
|
(
|
||||||
|
(users.users.${name}.specialArgs or { })
|
||||||
# NOTE: Without this home-manager will instead create its own package set which won't contain the same config and
|
// {
|
||||||
# user-defined packages/overlays as the flake's nixpkgs channel.
|
namespace = snowfall-config.namespace;
|
||||||
useGlobalPkgs = mkDefault true;
|
}
|
||||||
};
|
)
|
||||||
|
[
|
||||||
|
"options"
|
||||||
|
"config"
|
||||||
|
"lib"
|
||||||
|
"pkgs"
|
||||||
|
"specialArgs"
|
||||||
|
"host"
|
||||||
|
];
|
||||||
};
|
};
|
||||||
}
|
|
||||||
)
|
home-manager = {
|
||||||
(builtins.attrNames created-users);
|
users.${user-name} = mkIf config.snowfallorg.users.${user-name}.home.enable (
|
||||||
in
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
imports = (home-config.imports or [ ]) ++ other-modules ++ [ user-module ];
|
||||||
|
config = builtins.removeAttrs home-config [ "imports" ];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
# NOTE: Without this home-manager will instead create its own package set which won't contain the same config and
|
||||||
|
# user-defined packages/overlays as the flake's nixpkgs channel.
|
||||||
|
useGlobalPkgs = mkDefault true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
) (builtins.attrNames created-users);
|
||||||
|
in
|
||||||
[
|
[
|
||||||
extra-special-args-module
|
extra-special-args-module
|
||||||
snowfall-user-home-module
|
snowfall-user-home-module
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
core-inputs,
|
core-inputs,
|
||||||
...
|
...
|
||||||
}: {
|
}:
|
||||||
|
{
|
||||||
disabledModules = [
|
disabledModules = [
|
||||||
# The module from flake-utils-plus only works on NixOS and nix-darwin. For home-manager
|
# The module from flake-utils-plus only works on NixOS and nix-darwin. For home-manager
|
||||||
# to build, this module needs to be disabled.
|
# to build, this module needs to be disabled.
|
||||||
|
|||||||
@@ -3,8 +3,14 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
snowfall-lib,
|
snowfall-lib,
|
||||||
snowfall-config,
|
snowfall-config,
|
||||||
}: let
|
}:
|
||||||
inherit (core-inputs.nixpkgs.lib) fix filterAttrs callPackageWith isFunction;
|
let
|
||||||
|
inherit (core-inputs.nixpkgs.lib)
|
||||||
|
fix
|
||||||
|
filterAttrs
|
||||||
|
callPackageWith
|
||||||
|
isFunction
|
||||||
|
;
|
||||||
|
|
||||||
core-inputs-libs = snowfall-lib.flake.get-libs (snowfall-lib.flake.without-self core-inputs);
|
core-inputs-libs = snowfall-lib.flake.get-libs (snowfall-lib.flake.without-self core-inputs);
|
||||||
user-inputs-libs = snowfall-lib.flake.get-libs (snowfall-lib.flake.without-self user-inputs);
|
user-inputs-libs = snowfall-lib.flake.get-libs (snowfall-lib.flake.without-self user-inputs);
|
||||||
@@ -16,44 +22,45 @@
|
|||||||
core-inputs-libs
|
core-inputs-libs
|
||||||
user-inputs-libs
|
user-inputs-libs
|
||||||
snowfall-top-level-lib
|
snowfall-top-level-lib
|
||||||
{snowfall = snowfall-lib;}
|
{ snowfall = snowfall-lib; }
|
||||||
];
|
];
|
||||||
|
|
||||||
user-lib-root = snowfall-lib.fs.get-snowfall-file "lib";
|
user-lib-root = snowfall-lib.fs.get-snowfall-file "lib";
|
||||||
user-lib-modules = snowfall-lib.fs.get-default-nix-files-recursive user-lib-root;
|
user-lib-modules = snowfall-lib.fs.get-default-nix-files-recursive user-lib-root;
|
||||||
|
|
||||||
user-lib = fix (
|
user-lib = fix (
|
||||||
user-lib: let
|
user-lib:
|
||||||
|
let
|
||||||
attrs = {
|
attrs = {
|
||||||
inputs = snowfall-lib.flake.without-snowfall-inputs user-inputs;
|
inputs = snowfall-lib.flake.without-snowfall-inputs user-inputs;
|
||||||
snowfall-inputs = core-inputs;
|
snowfall-inputs = core-inputs;
|
||||||
namespace = snowfall-config.namespace;
|
namespace = snowfall-config.namespace;
|
||||||
lib = snowfall-lib.attrs.merge-shallow [
|
lib = snowfall-lib.attrs.merge-shallow [
|
||||||
base-lib
|
base-lib
|
||||||
{"${snowfall-config.namespace}" = user-lib;}
|
{ "${snowfall-config.namespace}" = user-lib; }
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
libs =
|
libs = builtins.map (
|
||||||
builtins.map
|
path:
|
||||||
(
|
let
|
||||||
path: let
|
imported-module = import path;
|
||||||
imported-module = import path;
|
in
|
||||||
in
|
if isFunction imported-module then
|
||||||
if isFunction imported-module
|
callPackageWith attrs path { }
|
||||||
then callPackageWith attrs path {}
|
# the only difference is that there is no `override` and `overrideDerivation` on returned value
|
||||||
# the only difference is that there is no `override` and `overrideDerivation` on returned value
|
else
|
||||||
else imported-module
|
imported-module
|
||||||
)
|
) user-lib-modules;
|
||||||
user-lib-modules;
|
|
||||||
in
|
in
|
||||||
snowfall-lib.attrs.merge-deep libs
|
snowfall-lib.attrs.merge-deep libs
|
||||||
);
|
);
|
||||||
|
|
||||||
system-lib = snowfall-lib.attrs.merge-shallow [
|
system-lib = snowfall-lib.attrs.merge-shallow [
|
||||||
base-lib
|
base-lib
|
||||||
{"${snowfall-config.namespace}" = user-lib;}
|
{ "${snowfall-config.namespace}" = user-lib; }
|
||||||
];
|
];
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
internal = {
|
internal = {
|
||||||
inherit system-lib user-lib;
|
inherit system-lib user-lib;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,12 +3,22 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
snowfall-lib,
|
snowfall-lib,
|
||||||
snowfall-config,
|
snowfall-config,
|
||||||
}: let
|
}:
|
||||||
|
let
|
||||||
inherit (builtins) baseNameOf;
|
inherit (builtins) baseNameOf;
|
||||||
inherit (core-inputs.nixpkgs.lib) foldl mapAttrs hasPrefix hasSuffix isFunction splitString tail;
|
inherit (core-inputs.nixpkgs.lib)
|
||||||
|
foldl
|
||||||
|
mapAttrs
|
||||||
|
hasPrefix
|
||||||
|
hasSuffix
|
||||||
|
isFunction
|
||||||
|
splitString
|
||||||
|
tail
|
||||||
|
;
|
||||||
|
|
||||||
user-modules-root = snowfall-lib.fs.get-snowfall-file "modules";
|
user-modules-root = snowfall-lib.fs.get-snowfall-file "modules";
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
module = {
|
module = {
|
||||||
## Create flake output modules.
|
## Create flake output modules.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -20,65 +30,75 @@ in {
|
|||||||
## { another-module = ...; my-module = ...; default = ...; }
|
## { another-module = ...; my-module = ...; default = ...; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-modules = {
|
create-modules =
|
||||||
src ? "${user-modules-root}/nixos",
|
{
|
||||||
overrides ? {},
|
src ? "${user-modules-root}/nixos",
|
||||||
alias ? {},
|
overrides ? { },
|
||||||
}: let
|
alias ? { },
|
||||||
user-modules = snowfall-lib.fs.get-default-nix-files-recursive src;
|
}:
|
||||||
create-module-metadata = module: {
|
let
|
||||||
name = let
|
user-modules = snowfall-lib.fs.get-default-nix-files-recursive src;
|
||||||
path-name = builtins.replaceStrings [(builtins.toString src) "/default.nix"] ["" ""] (builtins.unsafeDiscardStringContext module);
|
create-module-metadata = module: {
|
||||||
in
|
name =
|
||||||
if hasPrefix "/" path-name
|
let
|
||||||
then builtins.substring 1 ((builtins.stringLength path-name) - 1) path-name
|
path-name = builtins.replaceStrings [ (builtins.toString src) "/default.nix" ] [ "" "" ] (
|
||||||
else path-name;
|
builtins.unsafeDiscardStringContext module
|
||||||
path = module;
|
);
|
||||||
};
|
|
||||||
modules-metadata = builtins.map create-module-metadata user-modules;
|
|
||||||
merge-modules = modules: metadata:
|
|
||||||
modules
|
|
||||||
// {
|
|
||||||
# NOTE: home-manager *requires* modules to specify named arguments or it will not
|
|
||||||
# pass values in. For this reason we must specify things like `pkgs` as a named attribute.
|
|
||||||
${metadata.name} = args @ {pkgs, ...}: let
|
|
||||||
system = args.system or args.pkgs.stdenv.hostPlatform.system;
|
|
||||||
target = args.target or system;
|
|
||||||
|
|
||||||
format = let
|
|
||||||
virtual-system-type = snowfall-lib.system.get-virtual-system-type target;
|
|
||||||
in
|
in
|
||||||
if virtual-system-type != ""
|
if hasPrefix "/" path-name then
|
||||||
then virtual-system-type
|
builtins.substring 1 ((builtins.stringLength path-name) - 1) path-name
|
||||||
else if snowfall-lib.system.is-darwin target
|
else
|
||||||
then "darwin"
|
path-name;
|
||||||
else "linux";
|
path = module;
|
||||||
|
|
||||||
# Replicates the specialArgs from Snowfall Lib's system builder.
|
|
||||||
modified-args =
|
|
||||||
args
|
|
||||||
// {
|
|
||||||
inherit system target format;
|
|
||||||
virtual = args.virtual or (snowfall-lib.system.get-virtual-system-type target != "");
|
|
||||||
systems = args.systems or {};
|
|
||||||
|
|
||||||
lib = snowfall-lib.internal.system-lib;
|
|
||||||
|
|
||||||
inputs = snowfall-lib.flake.without-src user-inputs;
|
|
||||||
namespace = snowfall-config.namespace;
|
|
||||||
};
|
|
||||||
imported-user-module = import metadata.path;
|
|
||||||
user-module =
|
|
||||||
if isFunction imported-user-module
|
|
||||||
then imported-user-module modified-args
|
|
||||||
else imported-user-module;
|
|
||||||
in
|
|
||||||
user-module // {_file = metadata.path;};
|
|
||||||
};
|
};
|
||||||
modules-without-aliases = foldl merge-modules {} modules-metadata;
|
modules-metadata = builtins.map create-module-metadata user-modules;
|
||||||
aliased-modules = mapAttrs (name: value: modules-without-aliases.${value}) alias;
|
merge-modules =
|
||||||
modules = modules-without-aliases // aliased-modules // overrides;
|
modules: metadata:
|
||||||
in
|
modules
|
||||||
|
// {
|
||||||
|
# NOTE: home-manager *requires* modules to specify named arguments or it will not
|
||||||
|
# pass values in. For this reason we must specify things like `pkgs` as a named attribute.
|
||||||
|
${metadata.name} =
|
||||||
|
args@{ pkgs, ... }:
|
||||||
|
let
|
||||||
|
system = args.system or args.pkgs.stdenv.hostPlatform.system;
|
||||||
|
target = args.target or system;
|
||||||
|
|
||||||
|
format =
|
||||||
|
let
|
||||||
|
virtual-system-type = snowfall-lib.system.get-virtual-system-type target;
|
||||||
|
in
|
||||||
|
if virtual-system-type != "" then
|
||||||
|
virtual-system-type
|
||||||
|
else if snowfall-lib.system.is-darwin target then
|
||||||
|
"darwin"
|
||||||
|
else
|
||||||
|
"linux";
|
||||||
|
|
||||||
|
# Replicates the specialArgs from Snowfall Lib's system builder.
|
||||||
|
modified-args = args // {
|
||||||
|
inherit system target format;
|
||||||
|
virtual = args.virtual or (snowfall-lib.system.get-virtual-system-type target != "");
|
||||||
|
systems = args.systems or { };
|
||||||
|
|
||||||
|
lib = snowfall-lib.internal.system-lib;
|
||||||
|
|
||||||
|
inputs = snowfall-lib.flake.without-src user-inputs;
|
||||||
|
namespace = snowfall-config.namespace;
|
||||||
|
};
|
||||||
|
imported-user-module = import metadata.path;
|
||||||
|
user-module =
|
||||||
|
if isFunction imported-user-module then
|
||||||
|
imported-user-module modified-args
|
||||||
|
else
|
||||||
|
imported-user-module;
|
||||||
|
in
|
||||||
|
user-module // { _file = metadata.path; };
|
||||||
|
};
|
||||||
|
modules-without-aliases = foldl merge-modules { } modules-metadata;
|
||||||
|
aliased-modules = mapAttrs (name: value: modules-without-aliases.${value}) alias;
|
||||||
|
modules = modules-without-aliases // aliased-modules // overrides;
|
||||||
|
in
|
||||||
modules;
|
modules;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
snowfall-lib,
|
snowfall-lib,
|
||||||
snowfall-config,
|
snowfall-config,
|
||||||
}: let
|
}:
|
||||||
|
let
|
||||||
inherit (core-inputs.nixpkgs.lib) assertMsg foldl concatStringsSep;
|
inherit (core-inputs.nixpkgs.lib) assertMsg foldl concatStringsSep;
|
||||||
|
|
||||||
user-overlays-root = snowfall-lib.fs.get-snowfall-file "overlays";
|
user-overlays-root = snowfall-lib.fs.get-snowfall-file "overlays";
|
||||||
user-packages-root = snowfall-lib.fs.get-snowfall-file "packages";
|
user-packages-root = snowfall-lib.fs.get-snowfall-file "packages";
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
overlay = {
|
overlay = {
|
||||||
## Create a flake-utils-plus overlays builder.
|
## Create a flake-utils-plus overlays builder.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -20,36 +22,44 @@ in {
|
|||||||
## (channels: [ ... ])
|
## (channels: [ ... ])
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs -> [(a -> b -> c)]
|
#@ Attrs -> Attrs -> [(a -> b -> c)]
|
||||||
create-overlays-builder = {
|
create-overlays-builder =
|
||||||
src ? user-overlays-root,
|
{
|
||||||
namespace ? snowfall-config.namespace,
|
src ? user-overlays-root,
|
||||||
extra-overlays ? [],
|
namespace ? snowfall-config.namespace,
|
||||||
}: channels: let
|
extra-overlays ? [ ],
|
||||||
user-overlays = snowfall-lib.fs.get-default-nix-files-recursive src;
|
}:
|
||||||
create-overlay = overlay:
|
channels:
|
||||||
import overlay (
|
let
|
||||||
# Deprecated: Use `inputs.*` instead of referencing the input name directly.
|
user-overlays = snowfall-lib.fs.get-default-nix-files-recursive src;
|
||||||
user-inputs
|
create-overlay =
|
||||||
// {
|
overlay:
|
||||||
inherit channels;
|
import overlay (
|
||||||
inherit (snowfall-config) namespace;
|
# Deprecated: Use `inputs.*` instead of referencing the input name directly.
|
||||||
inputs = user-inputs;
|
user-inputs
|
||||||
lib = snowfall-lib.internal.system-lib;
|
// {
|
||||||
}
|
inherit channels;
|
||||||
);
|
inherit (snowfall-config) namespace;
|
||||||
user-packages-overlay = final: prev: let
|
inputs = user-inputs;
|
||||||
user-packages = snowfall-lib.package.create-packages {
|
lib = snowfall-lib.internal.system-lib;
|
||||||
pkgs = final;
|
}
|
||||||
inherit channels namespace;
|
);
|
||||||
};
|
user-packages-overlay =
|
||||||
in {
|
final: prev:
|
||||||
${namespace} =
|
let
|
||||||
(prev.${namespace} or {})
|
user-packages = snowfall-lib.package.create-packages {
|
||||||
// user-packages;
|
pkgs = final;
|
||||||
};
|
inherit channels namespace;
|
||||||
overlays =
|
};
|
||||||
[user-packages-overlay] ++ extra-overlays ++ (builtins.map create-overlay user-overlays);
|
in
|
||||||
in
|
{
|
||||||
|
${namespace} = (prev.${namespace} or { }) // user-packages;
|
||||||
|
};
|
||||||
|
overlays = [
|
||||||
|
user-packages-overlay
|
||||||
|
]
|
||||||
|
++ extra-overlays
|
||||||
|
++ (builtins.map create-overlay user-overlays);
|
||||||
|
in
|
||||||
overlays;
|
overlays;
|
||||||
|
|
||||||
## Create exported overlays from the user flake. Adapted [from flake-utils-plus](https://github.com/gytis-ivaskevicius/flake-utils-plus/blob/2bf0f91643c2e5ae38c1b26893ac2927ac9bd82a/lib/exportOverlays.nix).
|
## Create exported overlays from the user flake. Adapted [from flake-utils-plus](https://github.com/gytis-ivaskevicius/flake-utils-plus/blob/2bf0f91643c2e5ae38c1b26893ac2927ac9bd82a/lib/exportOverlays.nix).
|
||||||
@@ -63,136 +73,133 @@ in {
|
|||||||
## { default = final: prev: ...; some-overlay = final: prev: ...; }
|
## { default = final: prev: ...; some-overlay = final: prev: ...; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-overlays = {
|
create-overlays =
|
||||||
src ? user-overlays-root,
|
{
|
||||||
packages-src ? user-packages-root,
|
src ? user-overlays-root,
|
||||||
namespace ? snowfall-config.namespace,
|
packages-src ? user-packages-root,
|
||||||
extra-overlays ? {},
|
namespace ? snowfall-config.namespace,
|
||||||
}: let
|
extra-overlays ? { },
|
||||||
fake-pkgs = {
|
}:
|
||||||
callPackage = x: x;
|
let
|
||||||
isFakePkgs = true;
|
fake-pkgs = {
|
||||||
lib = {};
|
callPackage = x: x;
|
||||||
system = "fake-system";
|
isFakePkgs = true;
|
||||||
};
|
lib = { };
|
||||||
|
system = "fake-system";
|
||||||
user-overlays = snowfall-lib.fs.get-default-nix-files-recursive src;
|
|
||||||
|
|
||||||
channel-systems = user-inputs.self.pkgs;
|
|
||||||
|
|
||||||
user-packages-overlay = final: prev: let
|
|
||||||
user-packages = snowfall-lib.package.create-packages {
|
|
||||||
pkgs = final;
|
|
||||||
channels = channel-systems.${prev.system};
|
|
||||||
inherit namespace;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
if namespace == null
|
|
||||||
then user-packages
|
|
||||||
else {
|
|
||||||
${namespace} =
|
|
||||||
(prev.${namespace} or {})
|
|
||||||
// user-packages;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
create-overlay = (
|
user-overlays = snowfall-lib.fs.get-default-nix-files-recursive src;
|
||||||
overlays: file: let
|
|
||||||
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory file);
|
channel-systems = user-inputs.self.pkgs;
|
||||||
overlay = final: prev: let
|
|
||||||
channels = channel-systems.${prev.system};
|
user-packages-overlay =
|
||||||
user-overlay = import file (
|
final: prev:
|
||||||
# Deprecated: Use `inputs.*` instead of referencing the input name directly.
|
let
|
||||||
user-inputs
|
user-packages = snowfall-lib.package.create-packages {
|
||||||
// {
|
pkgs = final;
|
||||||
inherit channels namespace;
|
channels = channel-systems.${prev.system};
|
||||||
inputs = user-inputs;
|
inherit namespace;
|
||||||
lib = snowfall-lib.internal.system-lib;
|
};
|
||||||
}
|
|
||||||
);
|
|
||||||
packages = user-packages-overlay final prev;
|
|
||||||
prev-with-packages =
|
|
||||||
if namespace == null
|
|
||||||
then prev // packages
|
|
||||||
else
|
|
||||||
prev
|
|
||||||
// {
|
|
||||||
${namespace} =
|
|
||||||
(prev.${namespace} or {})
|
|
||||||
// packages.${namespace};
|
|
||||||
};
|
|
||||||
user-overlay-packages =
|
|
||||||
user-overlay
|
|
||||||
final
|
|
||||||
prev-with-packages;
|
|
||||||
outputs =
|
|
||||||
user-overlay-packages;
|
|
||||||
in
|
in
|
||||||
if user-overlay-packages.__dontExport or false == true
|
if namespace == null then
|
||||||
then outputs // {__dontExport = true;}
|
user-packages
|
||||||
else outputs;
|
else
|
||||||
fake-overlay-result = overlay fake-pkgs fake-pkgs;
|
{
|
||||||
in
|
${namespace} = (prev.${namespace} or { }) // user-packages;
|
||||||
if fake-overlay-result.__dontExport or false == true
|
};
|
||||||
then overlays
|
|
||||||
|
create-overlay = (
|
||||||
|
overlays: file:
|
||||||
|
let
|
||||||
|
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory file);
|
||||||
|
overlay =
|
||||||
|
final: prev:
|
||||||
|
let
|
||||||
|
channels = channel-systems.${prev.system};
|
||||||
|
user-overlay = import file (
|
||||||
|
# Deprecated: Use `inputs.*` instead of referencing the input name directly.
|
||||||
|
user-inputs
|
||||||
|
// {
|
||||||
|
inherit channels namespace;
|
||||||
|
inputs = user-inputs;
|
||||||
|
lib = snowfall-lib.internal.system-lib;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
packages = user-packages-overlay final prev;
|
||||||
|
prev-with-packages =
|
||||||
|
if namespace == null then
|
||||||
|
prev // packages
|
||||||
|
else
|
||||||
|
prev
|
||||||
|
// {
|
||||||
|
${namespace} = (prev.${namespace} or { }) // packages.${namespace};
|
||||||
|
};
|
||||||
|
user-overlay-packages = user-overlay final prev-with-packages;
|
||||||
|
outputs = user-overlay-packages;
|
||||||
|
in
|
||||||
|
if user-overlay-packages.__dontExport or false == true then
|
||||||
|
outputs // { __dontExport = true; }
|
||||||
|
else
|
||||||
|
outputs;
|
||||||
|
fake-overlay-result = overlay fake-pkgs fake-pkgs;
|
||||||
|
in
|
||||||
|
if fake-overlay-result.__dontExport or false == true then
|
||||||
|
overlays
|
||||||
else
|
else
|
||||||
overlays
|
overlays
|
||||||
// {
|
// {
|
||||||
${name} = overlay;
|
${name} = overlay;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
overlays =
|
overlays = foldl create-overlay { } user-overlays;
|
||||||
foldl
|
|
||||||
create-overlay
|
|
||||||
{}
|
|
||||||
user-overlays;
|
|
||||||
|
|
||||||
user-packages = snowfall-lib.fs.get-default-nix-files-recursive packages-src;
|
user-packages = snowfall-lib.fs.get-default-nix-files-recursive packages-src;
|
||||||
|
|
||||||
create-package-overlay = package-overlays: file: let
|
create-package-overlay =
|
||||||
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory file);
|
package-overlays: file:
|
||||||
overlay = final: prev: let
|
let
|
||||||
channels = channel-systems.${prev.system};
|
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory file);
|
||||||
packages = snowfall-lib.package.create-packages {
|
overlay =
|
||||||
inherit namespace;
|
final: prev:
|
||||||
channels = channel-systems.${prev.system};
|
let
|
||||||
};
|
channels = channel-systems.${prev.system};
|
||||||
in
|
packages = snowfall-lib.package.create-packages {
|
||||||
if namespace == null
|
inherit namespace;
|
||||||
then {${name} = packages.${name};}
|
channels = channel-systems.${prev.system};
|
||||||
else {
|
};
|
||||||
${namespace} =
|
in
|
||||||
(prev.${namespace} or {})
|
if namespace == null then
|
||||||
// {${name} = packages.${name};};
|
{ ${name} = packages.${name}; }
|
||||||
|
else
|
||||||
|
{
|
||||||
|
${namespace} = (prev.${namespace} or { }) // {
|
||||||
|
${name} = packages.${name};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
package-overlays
|
||||||
|
// {
|
||||||
|
"package/${name}" = overlay;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
package-overlays = foldl create-package-overlay { } user-packages;
|
||||||
|
|
||||||
|
default-overlay =
|
||||||
|
final: prev:
|
||||||
|
let
|
||||||
|
overlays-list = builtins.attrValues overlays;
|
||||||
|
package-overlays-list = builtins.attrValues package-overlays;
|
||||||
|
|
||||||
|
overlays-results = builtins.map (overlay: overlay final prev) overlays-list;
|
||||||
|
package-overlays-results = builtins.map (overlay: overlay final prev) package-overlays-list;
|
||||||
|
|
||||||
|
merged-results = snowfall-lib.attrs.merge-shallow-packages (
|
||||||
|
package-overlays-results ++ overlays-results
|
||||||
|
);
|
||||||
|
in
|
||||||
|
merged-results;
|
||||||
in
|
in
|
||||||
package-overlays
|
package-overlays // overlays // { default = default-overlay; } // extra-overlays;
|
||||||
// {
|
|
||||||
"package/${name}" = overlay;
|
|
||||||
};
|
|
||||||
|
|
||||||
package-overlays =
|
|
||||||
foldl
|
|
||||||
create-package-overlay
|
|
||||||
{}
|
|
||||||
user-packages;
|
|
||||||
|
|
||||||
default-overlay = final: prev: let
|
|
||||||
overlays-list = builtins.attrValues overlays;
|
|
||||||
package-overlays-list = builtins.attrValues package-overlays;
|
|
||||||
|
|
||||||
overlays-results = builtins.map (overlay: overlay final prev) overlays-list;
|
|
||||||
package-overlays-results = builtins.map (overlay: overlay final prev) package-overlays-list;
|
|
||||||
|
|
||||||
merged-results =
|
|
||||||
snowfall-lib.attrs.merge-shallow-packages
|
|
||||||
(package-overlays-results ++ overlays-results);
|
|
||||||
in
|
|
||||||
merged-results;
|
|
||||||
in
|
|
||||||
package-overlays
|
|
||||||
// overlays
|
|
||||||
// {default = default-overlay;}
|
|
||||||
// extra-overlays;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,20 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
snowfall-lib,
|
snowfall-lib,
|
||||||
snowfall-config,
|
snowfall-config,
|
||||||
}: let
|
}:
|
||||||
|
let
|
||||||
inherit (core-inputs.flake-utils-plus.lib) filterPackages allSystems;
|
inherit (core-inputs.flake-utils-plus.lib) filterPackages allSystems;
|
||||||
inherit (core-inputs.nixpkgs.lib) assertMsg foldl mapAttrs filterAttrs callPackageWith;
|
inherit (core-inputs.nixpkgs.lib)
|
||||||
|
assertMsg
|
||||||
|
foldl
|
||||||
|
mapAttrs
|
||||||
|
filterAttrs
|
||||||
|
callPackageWith
|
||||||
|
;
|
||||||
|
|
||||||
user-packages-root = snowfall-lib.fs.get-snowfall-file "packages";
|
user-packages-root = snowfall-lib.fs.get-snowfall-file "packages";
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
package = rec {
|
package = rec {
|
||||||
## Create flake output packages.
|
## Create flake output packages.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -20,54 +28,59 @@ in {
|
|||||||
## { another-package = ...; my-package = ...; default = ...; }
|
## { another-package = ...; my-package = ...; default = ...; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-packages = {
|
create-packages =
|
||||||
channels,
|
{
|
||||||
src ? user-packages-root,
|
channels,
|
||||||
pkgs ? channels.nixpkgs,
|
src ? user-packages-root,
|
||||||
overrides ? {},
|
pkgs ? channels.nixpkgs,
|
||||||
alias ? {},
|
overrides ? { },
|
||||||
namespace ? snowfall-config.namespace,
|
alias ? { },
|
||||||
}: let
|
namespace ? snowfall-config.namespace,
|
||||||
user-packages = snowfall-lib.fs.get-default-nix-files-recursive src;
|
}:
|
||||||
create-package-metadata = package: let
|
let
|
||||||
namespaced-packages = {
|
user-packages = snowfall-lib.fs.get-default-nix-files-recursive src;
|
||||||
${namespace} = packages-without-aliases;
|
create-package-metadata =
|
||||||
};
|
package:
|
||||||
extra-inputs =
|
let
|
||||||
pkgs
|
namespaced-packages = {
|
||||||
// namespaced-packages
|
${namespace} = packages-without-aliases;
|
||||||
// {
|
};
|
||||||
inherit channels namespace;
|
extra-inputs =
|
||||||
lib = snowfall-lib.internal.system-lib;
|
pkgs
|
||||||
pkgs = pkgs // namespaced-packages;
|
// namespaced-packages
|
||||||
inputs = user-inputs;
|
|
||||||
};
|
|
||||||
in {
|
|
||||||
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory package);
|
|
||||||
drv = let
|
|
||||||
pkg = callPackageWith extra-inputs package {};
|
|
||||||
in
|
|
||||||
pkg
|
|
||||||
// {
|
|
||||||
meta =
|
|
||||||
(pkg.meta or {})
|
|
||||||
// {
|
// {
|
||||||
snowfall = {
|
inherit channels namespace;
|
||||||
path = package;
|
lib = snowfall-lib.internal.system-lib;
|
||||||
|
pkgs = pkgs // namespaced-packages;
|
||||||
|
inputs = user-inputs;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory package);
|
||||||
|
drv =
|
||||||
|
let
|
||||||
|
pkg = callPackageWith extra-inputs package { };
|
||||||
|
in
|
||||||
|
pkg
|
||||||
|
// {
|
||||||
|
meta = (pkg.meta or { }) // {
|
||||||
|
snowfall = {
|
||||||
|
path = package;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
packages-metadata = builtins.map create-package-metadata user-packages;
|
||||||
packages-metadata = builtins.map create-package-metadata user-packages;
|
merge-packages =
|
||||||
merge-packages = packages: metadata:
|
packages: metadata:
|
||||||
packages
|
packages
|
||||||
// {
|
// {
|
||||||
${metadata.name} = metadata.drv;
|
${metadata.name} = metadata.drv;
|
||||||
};
|
};
|
||||||
packages-without-aliases = foldl merge-packages {} packages-metadata;
|
packages-without-aliases = foldl merge-packages { } packages-metadata;
|
||||||
aliased-packages = mapAttrs (name: value: packages-without-aliases.${value}) alias;
|
aliased-packages = mapAttrs (name: value: packages-without-aliases.${value}) alias;
|
||||||
packages = packages-without-aliases // aliased-packages // overrides;
|
packages = packages-without-aliases // aliased-packages // overrides;
|
||||||
in
|
in
|
||||||
filterPackages pkgs.stdenv.hostPlatform.system packages;
|
filterPackages pkgs.stdenv.hostPlatform.system packages;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,19 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
snowfall-lib,
|
snowfall-lib,
|
||||||
snowfall-config,
|
snowfall-config,
|
||||||
}: let
|
}:
|
||||||
inherit (builtins) toString baseNameOf dirOf concatStringsSep;
|
let
|
||||||
|
inherit (builtins)
|
||||||
|
toString
|
||||||
|
baseNameOf
|
||||||
|
dirOf
|
||||||
|
concatStringsSep
|
||||||
|
;
|
||||||
inherit (core-inputs.nixpkgs.lib) assertMsg last init;
|
inherit (core-inputs.nixpkgs.lib) assertMsg last init;
|
||||||
|
|
||||||
file-name-regex = "(.*)\\.(.*)$";
|
file-name-regex = "(.*)\\.(.*)$";
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
path = rec {
|
path = rec {
|
||||||
## Split a file name and its extension.
|
## Split a file name and its extension.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -20,10 +27,15 @@ in {
|
|||||||
## [ "my-file" "md" ]
|
## [ "my-file" "md" ]
|
||||||
## ```
|
## ```
|
||||||
#@ String -> [String]
|
#@ String -> [String]
|
||||||
split-file-extension = file: let
|
split-file-extension =
|
||||||
match = builtins.match file-name-regex file;
|
file:
|
||||||
in
|
let
|
||||||
assert assertMsg (match != null) "lib.snowfall.split-file-extension: File must have an extension to split."; match;
|
match = builtins.match file-name-regex file;
|
||||||
|
in
|
||||||
|
assert assertMsg (
|
||||||
|
match != null
|
||||||
|
) "lib.snowfall.split-file-extension: File must have an extension to split.";
|
||||||
|
match;
|
||||||
|
|
||||||
## Check if a file name has a file extension.
|
## Check if a file name has a file extension.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -35,9 +47,11 @@ in {
|
|||||||
## true
|
## true
|
||||||
## ```
|
## ```
|
||||||
#@ String -> Bool
|
#@ String -> Bool
|
||||||
has-any-file-extension = file: let
|
has-any-file-extension =
|
||||||
match = builtins.match file-name-regex (toString file);
|
file:
|
||||||
in
|
let
|
||||||
|
match = builtins.match file-name-regex (toString file);
|
||||||
|
in
|
||||||
match != null;
|
match != null;
|
||||||
|
|
||||||
## Get the file extension of a file name.
|
## Get the file extension of a file name.
|
||||||
@@ -50,13 +64,15 @@ in {
|
|||||||
## "txt"
|
## "txt"
|
||||||
## ```
|
## ```
|
||||||
#@ String -> String
|
#@ String -> String
|
||||||
get-file-extension = file:
|
get-file-extension =
|
||||||
if has-any-file-extension file
|
file:
|
||||||
then let
|
if has-any-file-extension file then
|
||||||
match = builtins.match file-name-regex (toString file);
|
let
|
||||||
in
|
match = builtins.match file-name-regex (toString file);
|
||||||
|
in
|
||||||
last match
|
last match
|
||||||
else "";
|
else
|
||||||
|
"";
|
||||||
|
|
||||||
## Check if a file name has a specific file extension.
|
## Check if a file name has a specific file extension.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -68,10 +84,9 @@ in {
|
|||||||
## true
|
## true
|
||||||
## ```
|
## ```
|
||||||
#@ String -> String -> Bool
|
#@ String -> String -> Bool
|
||||||
has-file-extension = extension: file:
|
has-file-extension =
|
||||||
if has-any-file-extension file
|
extension: file:
|
||||||
then extension == get-file-extension file
|
if has-any-file-extension file then extension == get-file-extension file else false;
|
||||||
else false;
|
|
||||||
|
|
||||||
## Get the parent directory for a given path.
|
## Get the parent directory for a given path.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -95,11 +110,14 @@ in {
|
|||||||
## "my-file"
|
## "my-file"
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> String
|
#@ Path -> String
|
||||||
get-file-name-without-extension = path: let
|
get-file-name-without-extension =
|
||||||
file-name = baseNameOf path;
|
path:
|
||||||
in
|
let
|
||||||
if has-any-file-extension file-name
|
file-name = baseNameOf path;
|
||||||
then concatStringsSep "" (init (split-file-extension file-name))
|
in
|
||||||
else file-name;
|
if has-any-file-extension file-name then
|
||||||
|
concatStringsSep "" (init (split-file-extension file-name))
|
||||||
|
else
|
||||||
|
file-name;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,19 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
snowfall-lib,
|
snowfall-lib,
|
||||||
snowfall-config,
|
snowfall-config,
|
||||||
}: let
|
}:
|
||||||
|
let
|
||||||
inherit (core-inputs.flake-utils-plus.lib) filterPackages;
|
inherit (core-inputs.flake-utils-plus.lib) filterPackages;
|
||||||
inherit (core-inputs.nixpkgs.lib) assertMsg foldl mapAttrs callPackageWith;
|
inherit (core-inputs.nixpkgs.lib)
|
||||||
|
assertMsg
|
||||||
|
foldl
|
||||||
|
mapAttrs
|
||||||
|
callPackageWith
|
||||||
|
;
|
||||||
|
|
||||||
user-shells-root = snowfall-lib.fs.get-snowfall-file "shells";
|
user-shells-root = snowfall-lib.fs.get-snowfall-file "shells";
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
shell = {
|
shell = {
|
||||||
## Create flake output packages.
|
## Create flake output packages.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -20,37 +27,41 @@ in {
|
|||||||
## { another-shell = ...; my-shell = ...; default = ...; }
|
## { another-shell = ...; my-shell = ...; default = ...; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-shells = {
|
create-shells =
|
||||||
channels,
|
{
|
||||||
src ? user-shells-root,
|
channels,
|
||||||
pkgs ? channels.nixpkgs,
|
src ? user-shells-root,
|
||||||
overrides ? {},
|
pkgs ? channels.nixpkgs,
|
||||||
alias ? {},
|
overrides ? { },
|
||||||
}: let
|
alias ? { },
|
||||||
user-shells = snowfall-lib.fs.get-default-nix-files-recursive src;
|
}:
|
||||||
create-shell-metadata = shell: let
|
let
|
||||||
extra-inputs =
|
user-shells = snowfall-lib.fs.get-default-nix-files-recursive src;
|
||||||
pkgs
|
create-shell-metadata =
|
||||||
// {
|
shell:
|
||||||
inherit channels;
|
let
|
||||||
lib = snowfall-lib.internal.system-lib;
|
extra-inputs = pkgs // {
|
||||||
inputs = snowfall-lib.flake.without-src user-inputs;
|
inherit channels;
|
||||||
namespace = snowfall-config.namespace;
|
lib = snowfall-lib.internal.system-lib;
|
||||||
|
inputs = snowfall-lib.flake.without-src user-inputs;
|
||||||
|
namespace = snowfall-config.namespace;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory shell);
|
||||||
|
drv = callPackageWith extra-inputs shell { };
|
||||||
};
|
};
|
||||||
in {
|
shells-metadata = builtins.map create-shell-metadata user-shells;
|
||||||
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory shell);
|
merge-shells =
|
||||||
drv = callPackageWith extra-inputs shell {};
|
shells: metadata:
|
||||||
};
|
shells
|
||||||
shells-metadata = builtins.map create-shell-metadata user-shells;
|
// {
|
||||||
merge-shells = shells: metadata:
|
${metadata.name} = metadata.drv;
|
||||||
shells
|
};
|
||||||
// {
|
shells-without-aliases = foldl merge-shells { } shells-metadata;
|
||||||
${metadata.name} = metadata.drv;
|
aliased-shells = mapAttrs (name: value: shells-without-aliases.${value}) alias;
|
||||||
};
|
shells = shells-without-aliases // aliased-shells // overrides;
|
||||||
shells-without-aliases = foldl merge-shells {} shells-metadata;
|
in
|
||||||
aliased-shells = mapAttrs (name: value: shells-without-aliases.${value}) alias;
|
|
||||||
shells = shells-without-aliases // aliased-shells // overrides;
|
|
||||||
in
|
|
||||||
filterPackages pkgs.stdenv.hostPlatform.system shells;
|
filterPackages pkgs.stdenv.hostPlatform.system shells;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,25 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
snowfall-lib,
|
snowfall-lib,
|
||||||
snowfall-config,
|
snowfall-config,
|
||||||
}: let
|
}:
|
||||||
|
let
|
||||||
inherit (builtins) dirOf baseNameOf;
|
inherit (builtins) dirOf baseNameOf;
|
||||||
inherit (core-inputs.nixpkgs.lib) assertMsg fix hasInfix concatMap foldl optionals singleton;
|
inherit (core-inputs.nixpkgs.lib)
|
||||||
|
assertMsg
|
||||||
|
fix
|
||||||
|
hasInfix
|
||||||
|
concatMap
|
||||||
|
foldl
|
||||||
|
optionals
|
||||||
|
singleton
|
||||||
|
;
|
||||||
|
|
||||||
virtual-systems = import ./virtual-systems.nix;
|
virtual-systems = import ./virtual-systems.nix;
|
||||||
|
|
||||||
user-systems-root = snowfall-lib.fs.get-snowfall-file "systems";
|
user-systems-root = snowfall-lib.fs.get-snowfall-file "systems";
|
||||||
user-modules-root = snowfall-lib.fs.get-snowfall-file "modules";
|
user-modules-root = snowfall-lib.fs.get-snowfall-file "modules";
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
system = rec {
|
system = rec {
|
||||||
## Get the name of a system based on its file path.
|
## Get the name of a system based on its file path.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -23,10 +33,12 @@ in {
|
|||||||
## "my-system"
|
## "my-system"
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> String
|
#@ Path -> String
|
||||||
get-inferred-system-name = path:
|
get-inferred-system-name =
|
||||||
if snowfall-lib.path.has-file-extension "nix" path
|
path:
|
||||||
then snowfall-lib.path.get-parent-directory path
|
if snowfall-lib.path.has-file-extension "nix" path then
|
||||||
else baseNameOf path;
|
snowfall-lib.path.get-parent-directory path
|
||||||
|
else
|
||||||
|
baseNameOf path;
|
||||||
|
|
||||||
## Check whether a named system is macOS.
|
## Check whether a named system is macOS.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -62,8 +74,7 @@ in {
|
|||||||
## true
|
## true
|
||||||
## ```
|
## ```
|
||||||
#@ String -> Bool
|
#@ String -> Bool
|
||||||
is-virtual = target:
|
is-virtual = target: (get-virtual-system-type target) != "";
|
||||||
(get-virtual-system-type target) != "";
|
|
||||||
|
|
||||||
## Get the virtual system type of a system target.
|
## Get the virtual system type of a system target.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -75,16 +86,12 @@ in {
|
|||||||
## "iso"
|
## "iso"
|
||||||
## ```
|
## ```
|
||||||
#@ String -> String
|
#@ String -> String
|
||||||
get-virtual-system-type = target:
|
get-virtual-system-type =
|
||||||
foldl
|
target:
|
||||||
(
|
foldl (
|
||||||
result: virtual-system:
|
result: virtual-system:
|
||||||
if result == "" && hasInfix virtual-system target
|
if result == "" && hasInfix virtual-system target then virtual-system else result
|
||||||
then virtual-system
|
) "" virtual-systems;
|
||||||
else result
|
|
||||||
)
|
|
||||||
""
|
|
||||||
virtual-systems;
|
|
||||||
|
|
||||||
## Get structured data about all systems for a given target.
|
## Get structured data about all systems for a given target.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -96,22 +103,24 @@ in {
|
|||||||
## [ { target = "x86_64-linux"; name = "my-machine"; path = "/systems/x86_64-linux/my-machine"; } ]
|
## [ { target = "x86_64-linux"; name = "my-machine"; path = "/systems/x86_64-linux/my-machine"; } ]
|
||||||
## ```
|
## ```
|
||||||
#@ String -> [Attrs]
|
#@ String -> [Attrs]
|
||||||
get-target-systems-metadata = target: let
|
get-target-systems-metadata =
|
||||||
systems = snowfall-lib.fs.get-directories target;
|
target:
|
||||||
existing-systems = builtins.filter (system: builtins.pathExists "${system}/default.nix") systems;
|
let
|
||||||
create-system-metadata = path: {
|
systems = snowfall-lib.fs.get-directories target;
|
||||||
path = "${path}/default.nix";
|
existing-systems = builtins.filter (system: builtins.pathExists "${system}/default.nix") systems;
|
||||||
# We are building flake outputs based on file contents. Nix doesn't like this
|
create-system-metadata = path: {
|
||||||
# so we have to explicitly discard the string's path context to allow us to
|
path = "${path}/default.nix";
|
||||||
# use the name as a variable.
|
# We are building flake outputs based on file contents. Nix doesn't like this
|
||||||
name = builtins.unsafeDiscardStringContext (builtins.baseNameOf path);
|
# so we have to explicitly discard the string's path context to allow us to
|
||||||
# We are building flake outputs based on file contents. Nix doesn't like this
|
# use the name as a variable.
|
||||||
# so we have to explicitly discard the string's path context to allow us to
|
name = builtins.unsafeDiscardStringContext (builtins.baseNameOf path);
|
||||||
# use the name as a variable.
|
# We are building flake outputs based on file contents. Nix doesn't like this
|
||||||
target = builtins.unsafeDiscardStringContext (builtins.baseNameOf target);
|
# so we have to explicitly discard the string's path context to allow us to
|
||||||
};
|
# use the name as a variable.
|
||||||
system-configurations = builtins.map create-system-metadata existing-systems;
|
target = builtins.unsafeDiscardStringContext (builtins.baseNameOf target);
|
||||||
in
|
};
|
||||||
|
system-configurations = builtins.map create-system-metadata existing-systems;
|
||||||
|
in
|
||||||
system-configurations;
|
system-configurations;
|
||||||
|
|
||||||
## Get the system builder for a given target.
|
## Get the system builder for a given target.
|
||||||
@@ -124,62 +133,66 @@ in {
|
|||||||
## (args: <system>)
|
## (args: <system>)
|
||||||
## ```
|
## ```
|
||||||
#@ String -> Function
|
#@ String -> Function
|
||||||
get-system-builder = target: let
|
get-system-builder =
|
||||||
virtual-system-type = get-virtual-system-type target;
|
target:
|
||||||
virtual-system-builder = args:
|
let
|
||||||
assert assertMsg (user-inputs ? nixos-generators) "In order to create virtual systems, you must include `nixos-generators` as a flake input.";
|
virtual-system-type = get-virtual-system-type target;
|
||||||
user-inputs.nixos-generators.nixosGenerate
|
virtual-system-builder =
|
||||||
(args
|
args:
|
||||||
|
assert assertMsg (
|
||||||
|
user-inputs ? nixos-generators
|
||||||
|
) "In order to create virtual systems, you must include `nixos-generators` as a flake input.";
|
||||||
|
user-inputs.nixos-generators.nixosGenerate (
|
||||||
|
args
|
||||||
// {
|
// {
|
||||||
format = virtual-system-type;
|
format = virtual-system-type;
|
||||||
specialArgs =
|
specialArgs = args.specialArgs // {
|
||||||
args.specialArgs
|
format = virtual-system-type;
|
||||||
// {
|
|
||||||
format = virtual-system-type;
|
|
||||||
};
|
|
||||||
modules =
|
|
||||||
args.modules
|
|
||||||
++ [
|
|
||||||
../../modules/nixos/user/default.nix
|
|
||||||
];
|
|
||||||
});
|
|
||||||
darwin-system-builder = args:
|
|
||||||
assert assertMsg (user-inputs ? darwin) "In order to create virtual systems, you must include `darwin` as a flake input.";
|
|
||||||
user-inputs.darwin.lib.darwinSystem
|
|
||||||
((builtins.removeAttrs args ["system" "modules"])
|
|
||||||
// {
|
|
||||||
specialArgs =
|
|
||||||
args.specialArgs
|
|
||||||
// {
|
|
||||||
format = "darwin";
|
|
||||||
};
|
|
||||||
modules =
|
|
||||||
args.modules
|
|
||||||
++ [
|
|
||||||
../../modules/darwin/user/default.nix
|
|
||||||
];
|
|
||||||
});
|
|
||||||
linux-system-builder = args:
|
|
||||||
core-inputs.nixpkgs.lib.nixosSystem
|
|
||||||
(args
|
|
||||||
// {
|
|
||||||
specialArgs =
|
|
||||||
args.specialArgs
|
|
||||||
// {
|
|
||||||
format = "linux";
|
|
||||||
};
|
};
|
||||||
modules =
|
modules = args.modules ++ [
|
||||||
args.modules
|
|
||||||
++ [
|
|
||||||
../../modules/nixos/user/default.nix
|
../../modules/nixos/user/default.nix
|
||||||
];
|
];
|
||||||
});
|
}
|
||||||
in
|
);
|
||||||
if virtual-system-type != ""
|
darwin-system-builder =
|
||||||
then virtual-system-builder
|
args:
|
||||||
else if is-darwin target
|
assert assertMsg (
|
||||||
then darwin-system-builder
|
user-inputs ? darwin
|
||||||
else linux-system-builder;
|
) "In order to create virtual systems, you must include `darwin` as a flake input.";
|
||||||
|
user-inputs.darwin.lib.darwinSystem (
|
||||||
|
(builtins.removeAttrs args [
|
||||||
|
"system"
|
||||||
|
"modules"
|
||||||
|
])
|
||||||
|
// {
|
||||||
|
specialArgs = args.specialArgs // {
|
||||||
|
format = "darwin";
|
||||||
|
};
|
||||||
|
modules = args.modules ++ [
|
||||||
|
../../modules/darwin/user/default.nix
|
||||||
|
];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
linux-system-builder =
|
||||||
|
args:
|
||||||
|
core-inputs.nixpkgs.lib.nixosSystem (
|
||||||
|
args
|
||||||
|
// {
|
||||||
|
specialArgs = args.specialArgs // {
|
||||||
|
format = "linux";
|
||||||
|
};
|
||||||
|
modules = args.modules ++ [
|
||||||
|
../../modules/nixos/user/default.nix
|
||||||
|
];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
in
|
||||||
|
if virtual-system-type != "" then
|
||||||
|
virtual-system-builder
|
||||||
|
else if is-darwin target then
|
||||||
|
darwin-system-builder
|
||||||
|
else
|
||||||
|
linux-system-builder;
|
||||||
|
|
||||||
## Get the flake output attribute for a system target.
|
## Get the flake output attribute for a system target.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -191,14 +204,17 @@ in {
|
|||||||
## "darwinConfigurations"
|
## "darwinConfigurations"
|
||||||
## ```
|
## ```
|
||||||
#@ String -> String
|
#@ String -> String
|
||||||
get-system-output = target: let
|
get-system-output =
|
||||||
virtual-system-type = get-virtual-system-type target;
|
target:
|
||||||
in
|
let
|
||||||
if virtual-system-type != ""
|
virtual-system-type = get-virtual-system-type target;
|
||||||
then "${virtual-system-type}Configurations"
|
in
|
||||||
else if is-darwin target
|
if virtual-system-type != "" then
|
||||||
then "darwinConfigurations"
|
"${virtual-system-type}Configurations"
|
||||||
else "nixosConfigurations";
|
else if is-darwin target then
|
||||||
|
"darwinConfigurations"
|
||||||
|
else
|
||||||
|
"nixosConfigurations";
|
||||||
|
|
||||||
## Get the resolved (non-virtual) system target.
|
## Get the resolved (non-virtual) system target.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -210,12 +226,15 @@ in {
|
|||||||
## "x86_64-linux"
|
## "x86_64-linux"
|
||||||
## ```
|
## ```
|
||||||
#@ String -> String
|
#@ String -> String
|
||||||
get-resolved-system-target = target: let
|
get-resolved-system-target =
|
||||||
virtual-system-type = get-virtual-system-type target;
|
target:
|
||||||
in
|
let
|
||||||
if virtual-system-type != ""
|
virtual-system-type = get-virtual-system-type target;
|
||||||
then builtins.replaceStrings [virtual-system-type] ["linux"] target
|
in
|
||||||
else target;
|
if virtual-system-type != "" then
|
||||||
|
builtins.replaceStrings [ virtual-system-type ] [ "linux" ] target
|
||||||
|
else
|
||||||
|
target;
|
||||||
|
|
||||||
## Create a system.
|
## Create a system.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -227,42 +246,54 @@ in {
|
|||||||
## <flake-utils-plus-system-configuration>
|
## <flake-utils-plus-system-configuration>
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-system = {
|
create-system =
|
||||||
target ? "x86_64-linux",
|
{
|
||||||
system ? get-resolved-system-target target,
|
target ? "x86_64-linux",
|
||||||
path,
|
system ? get-resolved-system-target target,
|
||||||
name ? builtins.unsafeDiscardStringContext (get-inferred-system-name path),
|
path,
|
||||||
modules ? [],
|
name ? builtins.unsafeDiscardStringContext (get-inferred-system-name path),
|
||||||
specialArgs ? {},
|
modules ? [ ],
|
||||||
channelName ? "nixpkgs",
|
specialArgs ? { },
|
||||||
builder ? get-system-builder target,
|
channelName ? "nixpkgs",
|
||||||
output ? get-system-output target,
|
builder ? get-system-builder target,
|
||||||
systems ? {},
|
output ? get-system-output target,
|
||||||
homes ? {},
|
systems ? { },
|
||||||
}: let
|
homes ? { },
|
||||||
lib = snowfall-lib.internal.system-lib;
|
}:
|
||||||
home-system-modules = snowfall-lib.home.create-home-system-modules homes;
|
let
|
||||||
home-manager-module =
|
lib = snowfall-lib.internal.system-lib;
|
||||||
if is-darwin system
|
home-system-modules = snowfall-lib.home.create-home-system-modules homes;
|
||||||
then user-inputs.home-manager.darwinModules.home-manager
|
home-manager-module =
|
||||||
else user-inputs.home-manager.nixosModules.home-manager;
|
if is-darwin system then
|
||||||
home-manager-modules = [home-manager-module] ++ home-system-modules;
|
user-inputs.home-manager.darwinModules.home-manager
|
||||||
in {
|
else
|
||||||
inherit channelName system builder output;
|
user-inputs.home-manager.nixosModules.home-manager;
|
||||||
|
home-manager-modules = [ home-manager-module ] ++ home-system-modules;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit
|
||||||
|
channelName
|
||||||
|
system
|
||||||
|
builder
|
||||||
|
output
|
||||||
|
;
|
||||||
|
|
||||||
modules = [path] ++ modules ++ (optionals (user-inputs ? home-manager) home-manager-modules);
|
modules = [ path ] ++ modules ++ (optionals (user-inputs ? home-manager) home-manager-modules);
|
||||||
|
|
||||||
specialArgs =
|
specialArgs = specialArgs // {
|
||||||
specialArgs
|
inherit
|
||||||
// {
|
target
|
||||||
inherit target system systems lib;
|
system
|
||||||
|
systems
|
||||||
|
lib
|
||||||
|
;
|
||||||
host = name;
|
host = name;
|
||||||
|
|
||||||
virtual = (get-virtual-system-type target) != "";
|
virtual = (get-virtual-system-type target) != "";
|
||||||
inputs = snowfall-lib.flake.without-src user-inputs;
|
inputs = snowfall-lib.flake.without-src user-inputs;
|
||||||
namespace = snowfall-config.namespace;
|
namespace = snowfall-config.namespace;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
## Create all available systems.
|
## Create all available systems.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
@@ -274,52 +305,49 @@ in {
|
|||||||
## { my-host = <flake-utils-plus-system-configuration>; }
|
## { my-host = <flake-utils-plus-system-configuration>; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-systems = {
|
create-systems =
|
||||||
systems ? {},
|
{
|
||||||
homes ? {},
|
systems ? { },
|
||||||
}: let
|
homes ? { },
|
||||||
targets = snowfall-lib.fs.get-directories user-systems-root;
|
}:
|
||||||
target-systems-metadata = concatMap get-target-systems-metadata targets;
|
let
|
||||||
user-nixos-modules = snowfall-lib.module.create-modules {
|
targets = snowfall-lib.fs.get-directories user-systems-root;
|
||||||
src = "${user-modules-root}/nixos";
|
target-systems-metadata = concatMap get-target-systems-metadata targets;
|
||||||
};
|
user-nixos-modules = snowfall-lib.module.create-modules {
|
||||||
user-darwin-modules = snowfall-lib.module.create-modules {
|
src = "${user-modules-root}/nixos";
|
||||||
src = "${user-modules-root}/darwin";
|
};
|
||||||
};
|
user-darwin-modules = snowfall-lib.module.create-modules {
|
||||||
nixos-modules = systems.modules.nixos or [];
|
src = "${user-modules-root}/darwin";
|
||||||
darwin-modules = systems.modules.darwin or [];
|
};
|
||||||
|
nixos-modules = systems.modules.nixos or [ ];
|
||||||
|
darwin-modules = systems.modules.darwin or [ ];
|
||||||
|
|
||||||
create-system' = created-systems: system-metadata: let
|
create-system' =
|
||||||
overrides = systems.hosts.${system-metadata.name} or {};
|
created-systems: system-metadata:
|
||||||
user-modules =
|
let
|
||||||
if is-darwin system-metadata.target
|
overrides = systems.hosts.${system-metadata.name} or { };
|
||||||
then user-darwin-modules
|
user-modules = if is-darwin system-metadata.target then user-darwin-modules else user-nixos-modules;
|
||||||
else user-nixos-modules;
|
user-modules-list = builtins.attrValues user-modules;
|
||||||
user-modules-list = builtins.attrValues user-modules;
|
system-modules = if is-darwin system-metadata.target then darwin-modules else nixos-modules;
|
||||||
system-modules =
|
in
|
||||||
if is-darwin system-metadata.target
|
{
|
||||||
then darwin-modules
|
${system-metadata.name} = create-system (
|
||||||
else nixos-modules;
|
overrides
|
||||||
in {
|
// system-metadata
|
||||||
${system-metadata.name} = create-system (overrides
|
// {
|
||||||
// system-metadata
|
systems = created-systems;
|
||||||
// {
|
modules = user-modules-list ++ (overrides.modules or [ ]) ++ system-modules;
|
||||||
systems = created-systems;
|
inherit homes;
|
||||||
modules = user-modules-list ++ (overrides.modules or []) ++ system-modules;
|
}
|
||||||
inherit homes;
|
);
|
||||||
});
|
};
|
||||||
};
|
created-systems = fix (
|
||||||
created-systems = fix (
|
created-systems:
|
||||||
created-systems:
|
foldl (
|
||||||
foldl
|
systems: system-metadata: systems // (create-system' created-systems system-metadata)
|
||||||
(
|
) { } target-systems-metadata
|
||||||
systems: system-metadata:
|
);
|
||||||
systems // (create-system' created-systems system-metadata)
|
in
|
||||||
)
|
|
||||||
{}
|
|
||||||
target-systems-metadata
|
|
||||||
);
|
|
||||||
in
|
|
||||||
created-systems;
|
created-systems;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
user-inputs,
|
user-inputs,
|
||||||
snowfall-lib,
|
snowfall-lib,
|
||||||
snowfall-config,
|
snowfall-config,
|
||||||
}: let
|
}:
|
||||||
|
let
|
||||||
inherit (builtins) baseNameOf;
|
inherit (builtins) baseNameOf;
|
||||||
inherit (core-inputs.nixpkgs.lib) assertMsg foldl mapAttrs;
|
inherit (core-inputs.nixpkgs.lib) assertMsg foldl mapAttrs;
|
||||||
|
|
||||||
user-templates-root = snowfall-lib.fs.get-snowfall-file "templates";
|
user-templates-root = snowfall-lib.fs.get-snowfall-file "templates";
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
template = {
|
template = {
|
||||||
## Create flake templates.
|
## Create flake templates.
|
||||||
##
|
##
|
||||||
@@ -22,43 +24,42 @@ in {
|
|||||||
## { another-template = ...; my-template = ...; default = ...; }
|
## { another-template = ...; my-template = ...; default = ...; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-templates = {
|
create-templates =
|
||||||
src ? user-templates-root,
|
{
|
||||||
overrides ? {},
|
src ? user-templates-root,
|
||||||
alias ? {},
|
overrides ? { },
|
||||||
}: let
|
alias ? { },
|
||||||
user-templates = snowfall-lib.fs.get-directories src;
|
}:
|
||||||
create-template-metadata = template: let
|
let
|
||||||
flake-file = template + "/flake.nix";
|
user-templates = snowfall-lib.fs.get-directories src;
|
||||||
has-flake = builtins.pathExists flake-file;
|
create-template-metadata =
|
||||||
flake-attrs =
|
template:
|
||||||
if has-flake
|
let
|
||||||
then import flake-file
|
flake-file = template + "/flake.nix";
|
||||||
else {};
|
has-flake = builtins.pathExists flake-file;
|
||||||
description = flake-attrs.description or null;
|
flake-attrs = if has-flake then import flake-file else { };
|
||||||
in
|
description = flake-attrs.description or null;
|
||||||
{
|
in
|
||||||
name = builtins.unsafeDiscardStringContext (baseNameOf template);
|
{
|
||||||
path = template;
|
name = builtins.unsafeDiscardStringContext (baseNameOf template);
|
||||||
}
|
path = template;
|
||||||
// (
|
}
|
||||||
if description != null
|
// (if description != null then { inherit description; } else { });
|
||||||
then {inherit description;}
|
templates-metadata = builtins.map create-template-metadata user-templates;
|
||||||
else {}
|
merge-templates =
|
||||||
|
templates: metadata:
|
||||||
|
templates
|
||||||
|
// {
|
||||||
|
${metadata.name} =
|
||||||
|
(overrides.${metadata.name} or { }) // (builtins.removeAttrs metadata [ "name" ]);
|
||||||
|
};
|
||||||
|
templates-without-aliases = foldl merge-templates { } templates-metadata;
|
||||||
|
aliased-templates = mapAttrs (name: value: templates-without-aliases.${value}) alias;
|
||||||
|
unused-overrides = builtins.removeAttrs overrides (
|
||||||
|
builtins.map (metadata: metadata.name) templates-metadata
|
||||||
);
|
);
|
||||||
templates-metadata = builtins.map create-template-metadata user-templates;
|
templates = templates-without-aliases // aliased-templates // unused-overrides;
|
||||||
merge-templates = templates: metadata:
|
in
|
||||||
templates
|
|
||||||
// {
|
|
||||||
${metadata.name} =
|
|
||||||
(overrides.${metadata.name} or {})
|
|
||||||
// (builtins.removeAttrs metadata ["name"]);
|
|
||||||
};
|
|
||||||
templates-without-aliases = foldl merge-templates {} templates-metadata;
|
|
||||||
aliased-templates = mapAttrs (name: value: templates-without-aliases.${value}) alias;
|
|
||||||
unused-overrides = builtins.removeAttrs overrides (builtins.map (metadata: metadata.name) templates-metadata);
|
|
||||||
templates = templates-without-aliases // aliased-templates // unused-overrides;
|
|
||||||
in
|
|
||||||
templates;
|
templates;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user