refactor: standardize on formatter
This commit is contained in:
parent
723c16bbb5
commit
1284023e7a
20 changed files with 1131 additions and 1111 deletions
20
default.nix
20
default.nix
|
|
@ -1,10 +1,14 @@
|
||||||
(import
|
(
|
||||||
|
import
|
||||||
(
|
(
|
||||||
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
|
let
|
||||||
fetchTarball {
|
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
in
|
||||||
sha256 = lock.nodes.flake-compat.locked.narHash;
|
fetchTarball {
|
||||||
}
|
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||||
|
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||||
|
}
|
||||||
)
|
)
|
||||||
{ src = ./.; }
|
{src = ./.;}
|
||||||
).defaultNix
|
)
|
||||||
|
.defaultNix
|
||||||
|
|
|
||||||
139
flake.nix
139
flake.nix
|
|
@ -11,75 +11,86 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = inputs:
|
outputs = inputs: let
|
||||||
let
|
core-inputs =
|
||||||
core-inputs = inputs // {
|
inputs
|
||||||
|
// {
|
||||||
src = ./.;
|
src = ./.;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Create the library, extending the nixpkgs library and merging
|
# Create the library, extending the nixpkgs library and merging
|
||||||
# libraries from other inputs to make them available like
|
# libraries from other inputs to make them available like
|
||||||
# `lib.flake-utils-plus.mkApp`.
|
# `lib.flake-utils-plus.mkApp`.
|
||||||
# Usage: mkLib { inherit inputs; src = ./.; }
|
# Usage: mkLib { inherit inputs; src = ./.; }
|
||||||
# result: lib
|
# result: lib
|
||||||
mkLib = import ./snowfall-lib core-inputs;
|
mkLib = import ./snowfall-lib core-inputs;
|
||||||
|
|
||||||
# A convenience wrapper to create the library and then call `lib.mkFlake`.
|
# A convenience wrapper to create the library and then call `lib.mkFlake`.
|
||||||
# Usage: mkFlake { inherit inputs; src = ./.; ... }
|
# Usage: mkFlake { inherit inputs; src = ./.; ... }
|
||||||
# result: <flake-outputs>
|
# result: <flake-outputs>
|
||||||
mkFlake = flake-and-lib-options@{ inputs, src, snowfall ? { }, ... }:
|
mkFlake = flake-and-lib-options @ {
|
||||||
let
|
inputs,
|
||||||
lib = mkLib {
|
src,
|
||||||
inherit inputs src snowfall;
|
snowfall ? {},
|
||||||
};
|
...
|
||||||
flake-options = builtins.removeAttrs flake-and-lib-options [ "inputs" "src" ];
|
}: let
|
||||||
in
|
lib = mkLib {
|
||||||
lib.mkFlake flake-options;
|
inherit inputs src snowfall;
|
||||||
|
};
|
||||||
|
flake-options = builtins.removeAttrs flake-and-lib-options ["inputs" "src"];
|
||||||
in
|
in
|
||||||
{
|
lib.mkFlake flake-options;
|
||||||
inherit mkLib mkFlake;
|
in {
|
||||||
|
inherit mkLib mkFlake;
|
||||||
|
|
||||||
nixosModules = {
|
nixosModules = {
|
||||||
user = ./modules/nixos/user/default.nix;
|
user = ./modules/nixos/user/default.nix;
|
||||||
};
|
|
||||||
|
|
||||||
darwinModules = {
|
|
||||||
user = ./modules/darwin/user/default.nix;
|
|
||||||
};
|
|
||||||
|
|
||||||
homeModules = {
|
|
||||||
user = ./modules/home/user/default.nix;
|
|
||||||
};
|
|
||||||
|
|
||||||
_snowfall = rec {
|
|
||||||
|
|
||||||
raw-config = config;
|
|
||||||
|
|
||||||
config = {
|
|
||||||
root = ./.;
|
|
||||||
src = ./.;
|
|
||||||
namespace = "snowfall";
|
|
||||||
lib-dir = "snowfall-lib";
|
|
||||||
|
|
||||||
meta = {
|
|
||||||
name = "snowfall-lib";
|
|
||||||
title = "Snowfall Lib";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
internal-lib =
|
|
||||||
let
|
|
||||||
lib = mkLib {
|
|
||||||
src = ./.;
|
|
||||||
|
|
||||||
inputs = inputs // {
|
|
||||||
self = { };
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
|
||||||
builtins.removeAttrs
|
|
||||||
lib.snowfall
|
|
||||||
[ "internal" ];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
darwinModules = {
|
||||||
|
user = ./modules/darwin/user/default.nix;
|
||||||
|
};
|
||||||
|
|
||||||
|
homeModules = {
|
||||||
|
user = ./modules/home/user/default.nix;
|
||||||
|
};
|
||||||
|
|
||||||
|
formatter = {
|
||||||
|
x86_64-linux = inputs.nixpkgs.legacyPackages.x86_64-linux.alejandra;
|
||||||
|
aarch64-linux = inputs.nixpkgs.legacyPackages.aarch64-linux.alejandra;
|
||||||
|
x86_64-darwin = inputs.nixpkgs.legacyPackages.x86_64-darwin.alejandra;
|
||||||
|
aarch64-darwin = inputs.nixpkgs.legacyPackages.aarch64-darwin.alejandra;
|
||||||
|
};
|
||||||
|
|
||||||
|
_snowfall = rec {
|
||||||
|
raw-config = config;
|
||||||
|
|
||||||
|
config = {
|
||||||
|
root = ./.;
|
||||||
|
src = ./.;
|
||||||
|
namespace = "snowfall";
|
||||||
|
lib-dir = "snowfall-lib";
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
name = "snowfall-lib";
|
||||||
|
title = "Snowfall Lib";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
internal-lib = let
|
||||||
|
lib = mkLib {
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
inputs =
|
||||||
|
inputs
|
||||||
|
// {
|
||||||
|
self = {};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
builtins.removeAttrs
|
||||||
|
lib.snowfall
|
||||||
|
["internal"];
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,33 @@
|
||||||
{ pkgs, lib, options, config, inputs, ... }:
|
{
|
||||||
|
pkgs,
|
||||||
let
|
lib,
|
||||||
|
options,
|
||||||
|
config,
|
||||||
|
inputs,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
inherit (lib) types mkOption mkDefault foldl optionalAttrs;
|
inherit (lib) types mkOption mkDefault foldl optionalAttrs;
|
||||||
|
|
||||||
cfg = config.snowfallorg;
|
cfg = config.snowfallorg;
|
||||||
|
|
||||||
user-names = builtins.attrNames cfg.user;
|
user-names = builtins.attrNames cfg.user;
|
||||||
|
|
||||||
create-system-users = system-users: name:
|
create-system-users = system-users: name: let
|
||||||
let
|
user = cfg.user.${name};
|
||||||
user = cfg.user.${name};
|
in
|
||||||
in
|
system-users
|
||||||
system-users // (optionalAttrs user.create {
|
// (optionalAttrs user.create {
|
||||||
${name} = {
|
${name} = {
|
||||||
home = mkDefault user.home.path;
|
home = mkDefault user.home.path;
|
||||||
isHidden = mkDefault false;
|
isHidden = mkDefault false;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
in
|
in {
|
||||||
{
|
|
||||||
options.snowfallorg = {
|
options.snowfallorg = {
|
||||||
user = mkOption {
|
user = mkOption {
|
||||||
description = "User configuration.";
|
description = "User configuration.";
|
||||||
default = { };
|
default = {};
|
||||||
type = types.attrsOf (types.submodule ({ name, ... }: {
|
type = types.attrsOf (types.submodule ({name, ...}: {
|
||||||
options = {
|
options = {
|
||||||
create = mkOption {
|
create = mkOption {
|
||||||
description = "Whether to create the user automatically.";
|
description = "Whether to create the user automatically.";
|
||||||
|
|
@ -46,28 +50,36 @@ in
|
||||||
# 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;
|
{
|
||||||
modulesPath = "${inputs.home-manager}/modules";
|
osConfig = config;
|
||||||
} // config.home-manager.extraSpecialArgs;
|
modulesPath = "${inputs.home-manager}/modules";
|
||||||
modules = [
|
}
|
||||||
({ lib, modulesPath, ... }: {
|
// config.home-manager.extraSpecialArgs;
|
||||||
imports = import "${modulesPath}/modules.nix" {
|
modules =
|
||||||
inherit pkgs lib;
|
[
|
||||||
useNixpkgsModule = !config.home-manager.useGlobalPkgs;
|
({
|
||||||
};
|
lib,
|
||||||
|
modulesPath,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
imports = import "${modulesPath}/modules.nix" {
|
||||||
|
inherit pkgs lib;
|
||||||
|
useNixpkgsModule = !config.home-manager.useGlobalPkgs;
|
||||||
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
submoduleSupport.enable = true;
|
submoduleSupport.enable = true;
|
||||||
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
|
submoduleSupport.externalPackageInstall = cfg.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;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -77,6 +89,6 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
users.users = (foldl create-system-users { } (user-names));
|
users.users = foldl create-system-users {} user-names;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
inputs@{ pkgs, lib, options, config, ... }:
|
inputs @ {
|
||||||
|
pkgs,
|
||||||
let
|
lib,
|
||||||
|
options,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
inherit (lib) types mkOption mkIf mkDefault;
|
inherit (lib) types mkOption mkIf mkDefault;
|
||||||
|
|
||||||
cfg = config.snowfallorg;
|
cfg = config.snowfallorg;
|
||||||
|
|
@ -12,14 +16,12 @@ let
|
||||||
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) then
|
if (os-user-home != null)
|
||||||
os-user-home
|
then os-user-home
|
||||||
else if pkgs.stdenv.isDarwin then
|
else if pkgs.stdenv.isDarwin
|
||||||
"/Users/${cfg.user.name}"
|
then "/Users/${cfg.user.name}"
|
||||||
else
|
else "/home/${cfg.user.name}";
|
||||||
"/home/${cfg.user.name}";
|
in {
|
||||||
in
|
|
||||||
{
|
|
||||||
options.snowfallorg = {
|
options.snowfallorg = {
|
||||||
user = {
|
user = {
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,23 @@
|
||||||
args@{ pkgs, lib, options, config, ... }:
|
args @ {
|
||||||
|
pkgs,
|
||||||
let
|
lib,
|
||||||
|
options,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
inherit (lib) types mkOption mkDefault foldl optionalAttrs optional;
|
inherit (lib) types mkOption mkDefault foldl optionalAttrs optional;
|
||||||
|
|
||||||
cfg = config.snowfallorg;
|
cfg = config.snowfallorg;
|
||||||
|
|
||||||
inputs = args.inputs or { };
|
inputs = args.inputs or {};
|
||||||
|
|
||||||
user-names = builtins.attrNames cfg.user;
|
user-names = builtins.attrNames cfg.user;
|
||||||
|
|
||||||
create-system-users = system-users: name:
|
create-system-users = system-users: name: let
|
||||||
let
|
user = cfg.user.${name};
|
||||||
user = cfg.user.${name};
|
in
|
||||||
in
|
system-users
|
||||||
system-users // (optionalAttrs user.create {
|
// (optionalAttrs user.create {
|
||||||
${name} = {
|
${name} = {
|
||||||
isNormalUser = mkDefault true;
|
isNormalUser = mkDefault true;
|
||||||
|
|
||||||
|
|
@ -25,14 +29,12 @@ let
|
||||||
extraGroups = optional user.admin "wheel";
|
extraGroups = optional user.admin "wheel";
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
in {
|
||||||
in
|
|
||||||
{
|
|
||||||
options.snowfallorg = {
|
options.snowfallorg = {
|
||||||
user = mkOption {
|
user = mkOption {
|
||||||
description = "User configuration.";
|
description = "User configuration.";
|
||||||
default = { };
|
default = {};
|
||||||
type = types.attrsOf (types.submodule ({ name, ... }: {
|
type = types.attrsOf (types.submodule ({name, ...}: {
|
||||||
options = {
|
options = {
|
||||||
create = mkOption {
|
create = mkOption {
|
||||||
description = "Whether to create the user automatically.";
|
description = "Whether to create the user automatically.";
|
||||||
|
|
@ -63,29 +65,39 @@ in
|
||||||
# @NOTE(jakehamilton): This has been adapted to support documentation generation without
|
# @NOTE(jakehamilton): 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;
|
{
|
||||||
modulesPath = "${inputs.home-manager or "/"}/modules";
|
osConfig = config;
|
||||||
} // (config.home-manager.extraSpecialArgs or { });
|
modulesPath = "${inputs.home-manager or "/"}/modules";
|
||||||
modules = [
|
}
|
||||||
({ lib, modulesPath, ... }:
|
// (config.home-manager.extraSpecialArgs or {});
|
||||||
if inputs ? home-manager then {
|
modules =
|
||||||
imports = import "${modulesPath}/modules.nix" {
|
[
|
||||||
inherit pkgs lib;
|
({
|
||||||
useNixpkgsModule = !(config.home-manager.useGlobalPkgs or false);
|
lib,
|
||||||
};
|
modulesPath,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
if inputs ? home-manager
|
||||||
|
then {
|
||||||
|
imports = import "${modulesPath}/modules.nix" {
|
||||||
|
inherit pkgs lib;
|
||||||
|
useNixpkgsModule = !(config.home-manager.useGlobalPkgs or false);
|
||||||
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
submoduleSupport.enable = true;
|
submoduleSupport.enable = true;
|
||||||
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
|
submoduleSupport.externalPackageInstall = cfg.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 { })
|
}
|
||||||
] ++ (config.home-manager.sharedModules or [ ]);
|
else {})
|
||||||
|
]
|
||||||
|
++ (config.home-manager.sharedModules or []);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -95,6 +107,6 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
users.users = (foldl (create-system-users) { } (user-names));
|
users.users = foldl create-system-users {} user-names;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
{ core-inputs
|
{
|
||||||
, user-inputs
|
core-inputs,
|
||||||
, snowfall-lib
|
user-inputs,
|
||||||
, snowfall-config
|
snowfall-lib,
|
||||||
}:
|
snowfall-config,
|
||||||
|
}: let
|
||||||
let
|
inherit
|
||||||
inherit (core-inputs.nixpkgs.lib)
|
(core-inputs.nixpkgs.lib)
|
||||||
assertMsg
|
assertMsg
|
||||||
mapAttrsToList
|
mapAttrsToList
|
||||||
mapAttrs
|
mapAttrs
|
||||||
|
|
@ -13,9 +13,9 @@ let
|
||||||
foldl
|
foldl
|
||||||
recursiveUpdate
|
recursiveUpdate
|
||||||
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:
|
||||||
|
|
@ -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:
|
||||||
|
|
@ -66,19 +66,21 @@ in
|
||||||
#@ [Attrs] -> Attrs
|
#@ [Attrs] -> Attrs
|
||||||
merge-shallow-packages = items:
|
merge-shallow-packages = items:
|
||||||
foldl
|
foldl
|
||||||
(result: item:
|
(
|
||||||
result // (mapAttrs
|
result: item:
|
||||||
(name: value:
|
result
|
||||||
if isDerivation value then
|
// (mapAttrs
|
||||||
value
|
(
|
||||||
else if builtins.isAttrs value then
|
name: value:
|
||||||
(result.${name} or { }) // value
|
if isDerivation value
|
||||||
else
|
then value
|
||||||
value
|
else if builtins.isAttrs value
|
||||||
|
then (result.${name} or {}) // value
|
||||||
|
else value
|
||||||
)
|
)
|
||||||
item)
|
item)
|
||||||
)
|
)
|
||||||
{ }
|
{}
|
||||||
items;
|
items;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,22 @@
|
||||||
# @NOTE(jakehamilton): The role of this file is to bootstrap the
|
# NOTE: The role of this file is to bootstrap the
|
||||||
# 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:
|
core-inputs: user-options: let
|
||||||
user-options:
|
raw-snowfall-config = user-options.snowfall or {};
|
||||||
|
snowfall-config =
|
||||||
let
|
raw-snowfall-config
|
||||||
raw-snowfall-config = user-options.snowfall or { };
|
// {
|
||||||
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;
|
inherit (core-inputs.nixpkgs.lib) assertMsg fix filterAttrs mergeAttrs fold recursiveUpdate callPackageWith;
|
||||||
|
|
||||||
|
|
@ -25,13 +24,13 @@ let
|
||||||
# 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`
|
||||||
|
|
@ -39,47 +38,47 @@ 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:
|
get-libs = attrs: let
|
||||||
let
|
# @PERF(jakehamilton): Replace filter+map with a fold.
|
||||||
# @PERF(jakehamilton): Replace filter+map with a fold.
|
attrs-with-libs =
|
||||||
attrs-with-libs = filterAttrs
|
filterAttrs
|
||||||
(name: value: builtins.isAttrs (value.lib or null))
|
(name: value: builtins.isAttrs (value.lib or null))
|
||||||
attrs;
|
attrs;
|
||||||
libs =
|
libs =
|
||||||
builtins.mapAttrs (name: input: input.lib) attrs-with-libs;
|
builtins.mapAttrs (name: input: input.lib) attrs-with-libs;
|
||||||
in
|
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);
|
||||||
|
|
||||||
# @NOTE(jakehamilton): This root is different to accomodate the creation
|
# NOTE: This root is different to accomodate 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 =
|
snowfall-lib-dirs = let
|
||||||
let
|
files = builtins.readDir snowfall-lib-root;
|
||||||
files = builtins.readDir snowfall-lib-root;
|
dirs = filterAttrs (name: kind: kind == "directory") files;
|
||||||
dirs = filterAttrs (name: kind: kind == "directory") files;
|
names = builtins.attrNames dirs;
|
||||||
names = builtins.attrNames dirs;
|
in
|
||||||
in
|
|
||||||
names;
|
names;
|
||||||
|
|
||||||
snowfall-lib = fix (snowfall-lib:
|
snowfall-lib = fix (
|
||||||
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 = builtins.map
|
libs =
|
||||||
|
builtins.map
|
||||||
(dir: import "${snowfall-lib-root}/${dir}" attrs)
|
(dir: import "${snowfall-lib-root}/${dir}" attrs)
|
||||||
snowfall-lib-dirs;
|
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;
|
||||||
|
|
@ -89,24 +88,25 @@ 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:
|
user-lib = fix (
|
||||||
let
|
user-lib: let
|
||||||
attrs = {
|
attrs = {
|
||||||
inherit (user-options) inputs;
|
inherit (user-options) inputs;
|
||||||
snowfall-inputs = core-inputs;
|
snowfall-inputs = core-inputs;
|
||||||
lib = merge-shallow [ base-lib { ${snowfall-config.namespace} = user-lib; } ];
|
lib = merge-shallow [base-lib {${snowfall-config.namespace} = user-lib;}];
|
||||||
};
|
};
|
||||||
libs = builtins.map
|
libs =
|
||||||
(path: callPackageWith attrs path { })
|
builtins.map
|
||||||
|
(path: callPackageWith attrs path {})
|
||||||
user-lib-modules;
|
user-lib-modules;
|
||||||
in
|
in
|
||||||
merge-deep libs
|
merge-deep libs
|
||||||
);
|
);
|
||||||
|
|
||||||
lib = merge-deep [
|
lib = merge-deep [
|
||||||
|
|
@ -117,6 +117,5 @@ 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.");
|
assert (assertMsg user-inputs-has-src "Missing attribute `src` for mkLib."); lib
|
||||||
lib
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
{ core-inputs
|
{
|
||||||
, user-inputs
|
core-inputs,
|
||||||
, snowfall-lib
|
user-inputs,
|
||||||
, snowfall-config
|
snowfall-lib,
|
||||||
}:
|
snowfall-config,
|
||||||
|
}: let
|
||||||
let
|
|
||||||
inherit (core-inputs.nixpkgs.lib) assertMsg foldl filterAttrs const;
|
inherit (core-inputs.nixpkgs.lib) assertMsg foldl filterAttrs const;
|
||||||
in
|
in rec {
|
||||||
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:
|
||||||
|
|
@ -19,7 +17,7 @@ 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:
|
||||||
|
|
@ -31,7 +29,7 @@ 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:
|
||||||
|
|
@ -57,22 +55,22 @@ rec {
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
without-snowfall-options = flake-options:
|
without-snowfall-options = flake-options:
|
||||||
builtins.removeAttrs
|
builtins.removeAttrs
|
||||||
flake-options
|
flake-options
|
||||||
[
|
[
|
||||||
"systems"
|
"systems"
|
||||||
"modules"
|
"modules"
|
||||||
"overlays"
|
"overlays"
|
||||||
"packages"
|
"packages"
|
||||||
"outputs-builder"
|
"outputs-builder"
|
||||||
"outputsBuilder"
|
"outputsBuilder"
|
||||||
"packagesPrefix"
|
"packagesPrefix"
|
||||||
"hosts"
|
"hosts"
|
||||||
"channels-config"
|
"channels-config"
|
||||||
"templates"
|
"templates"
|
||||||
"package-namespace"
|
"package-namespace"
|
||||||
"alias"
|
"alias"
|
||||||
"snowfall"
|
"snowfall"
|
||||||
];
|
];
|
||||||
|
|
||||||
## Transform an attribute set of inputs into an attribute set where the values are the inputs' `lib` attribute. Entries without a `lib` attribute are removed.
|
## Transform an attribute set of inputs into an attribute set where the values are the inputs' `lib` attribute. Entries without a `lib` attribute are removed.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
|
|
@ -84,80 +82,80 @@ rec {
|
||||||
## { x = nixpkgs.lib; }
|
## { x = nixpkgs.lib; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
get-libs = attrs:
|
get-libs = attrs: let
|
||||||
let
|
# @PERF(jakehamilton): Replace filter+map with a fold.
|
||||||
# @PERF(jakehamilton): Replace filter+map with a fold.
|
attrs-with-libs =
|
||||||
attrs-with-libs = filterAttrs
|
filterAttrs
|
||||||
(name: value: builtins.isAttrs (value.lib or null))
|
(name: value: builtins.isAttrs (value.lib or null))
|
||||||
attrs;
|
attrs;
|
||||||
libs =
|
libs =
|
||||||
builtins.mapAttrs (name: input: input.lib) attrs-with-libs;
|
builtins.mapAttrs (name: input: input.lib) attrs-with-libs;
|
||||||
in
|
in
|
||||||
libs;
|
libs;
|
||||||
};
|
};
|
||||||
|
|
||||||
mkFlake = full-flake-options:
|
mkFlake = full-flake-options: let
|
||||||
let
|
package-namespace = full-flake-options.package-namespace or snowfall-config.namespace or "internal";
|
||||||
package-namespace = full-flake-options.package-namespace or snowfall-config.namespace or "internal";
|
custom-flake-options = flake.without-snowfall-options full-flake-options;
|
||||||
custom-flake-options = flake.without-snowfall-options full-flake-options;
|
alias = full-flake-options.alias or {};
|
||||||
alias = full-flake-options.alias or { };
|
homes = snowfall-lib.home.create-homes (full-flake-options.homes or {});
|
||||||
homes = snowfall-lib.home.create-homes (full-flake-options.homes or { });
|
systems = snowfall-lib.system.create-systems {
|
||||||
systems = snowfall-lib.system.create-systems {
|
systems = full-flake-options.systems or {};
|
||||||
systems = (full-flake-options.systems or { });
|
homes = full-flake-options.homes or {};
|
||||||
homes = (full-flake-options.homes or { });
|
};
|
||||||
|
hosts = snowfall-lib.attrs.merge-shallow [(full-flake-options.systems.hosts or {}) systems homes];
|
||||||
|
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 package-namespace;
|
||||||
|
extra-overlays = full-flake-options.extra-exported-overlays 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 package-namespace;
|
||||||
|
overrides = (full-flake-options.packages or {}) // (user-outputs.packages or {});
|
||||||
|
alias = alias.packages or {};
|
||||||
};
|
};
|
||||||
hosts = snowfall-lib.attrs.merge-shallow [ (full-flake-options.systems.hosts or { }) systems homes ];
|
shells = snowfall-lib.shell.create-shells {
|
||||||
templates = snowfall-lib.template.create-templates {
|
inherit channels;
|
||||||
overrides = (full-flake-options.templates or { });
|
overrides = (full-flake-options.shells or {}) // (user-outputs.devShells or {});
|
||||||
alias = alias.templates or { };
|
alias = alias.shells 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 package-namespace;
|
|
||||||
extra-overlays = full-flake-options.extra-exported-overlays or { };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs-builder = channels:
|
outputs = {
|
||||||
let
|
inherit packages;
|
||||||
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 package-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 { };
|
|
||||||
};
|
|
||||||
|
|
||||||
outputs = {
|
devShells = shells;
|
||||||
inherit packages;
|
};
|
||||||
|
in
|
||||||
|
snowfall-lib.attrs.merge-deep [user-outputs outputs];
|
||||||
|
|
||||||
devShells = shells;
|
flake-options =
|
||||||
};
|
custom-flake-options
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -168,29 +166,30 @@ rec {
|
||||||
darwinModules = darwin-modules;
|
darwinModules = darwin-modules;
|
||||||
homeModules = home-modules;
|
homeModules = home-modules;
|
||||||
|
|
||||||
channelsConfig = full-flake-options.channels-config or { };
|
channelsConfig = full-flake-options.channels-config or {};
|
||||||
|
|
||||||
channels.nixpkgs.overlaysBuilder = snowfall-lib.overlay.create-overlays-builder {
|
channels.nixpkgs.overlaysBuilder = snowfall-lib.overlay.create-overlays-builder {
|
||||||
inherit package-namespace;
|
inherit package-namespace;
|
||||||
extra-overlays = full-flake-options.overlays or [ ];
|
extra-overlays = full-flake-options.overlays or [];
|
||||||
};
|
};
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
{ core-inputs
|
{
|
||||||
, user-inputs
|
core-inputs,
|
||||||
, snowfall-lib
|
user-inputs,
|
||||||
, snowfall-config
|
snowfall-lib,
|
||||||
}:
|
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:
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,15 @@
|
||||||
{ core-inputs
|
{
|
||||||
, user-inputs
|
core-inputs,
|
||||||
, snowfall-lib
|
user-inputs,
|
||||||
, snowfall-config
|
snowfall-lib,
|
||||||
}:
|
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:
|
||||||
|
|
@ -75,10 +73,9 @@ in
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> Attrs
|
#@ Path -> Attrs
|
||||||
safe-read-directory = path:
|
safe-read-directory = path:
|
||||||
if pathExists path then
|
if pathExists path
|
||||||
readDir path
|
then readDir path
|
||||||
else
|
else {};
|
||||||
{ };
|
|
||||||
|
|
||||||
## Get directories at a given path.
|
## Get directories at a given path.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
|
|
@ -90,11 +87,10 @@ in
|
||||||
## [ "./something/a-directory" ]
|
## [ "./something/a-directory" ]
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-directories = path:
|
get-directories = path: let
|
||||||
let
|
entries = safe-read-directory path;
|
||||||
entries = safe-read-directory path;
|
filtered-entries = filterAttrs (name: kind: is-directory-kind kind) entries;
|
||||||
filtered-entries = filterAttrs (name: kind: is-directory-kind kind) entries;
|
in
|
||||||
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.
|
||||||
|
|
@ -107,11 +103,10 @@ in
|
||||||
## [ "./something/a-file" ]
|
## [ "./something/a-file" ]
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-files = path:
|
get-files = path: let
|
||||||
let
|
entries = safe-read-directory path;
|
||||||
entries = safe-read-directory path;
|
filtered-entries = filterAttrs (name: kind: is-file-kind kind) entries;
|
||||||
filtered-entries = filterAttrs (name: kind: is-file-kind kind) entries;
|
in
|
||||||
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.
|
||||||
|
|
@ -124,25 +119,23 @@ in
|
||||||
## [ "./something/some-directory/a-file" ]
|
## [ "./something/some-directory/a-file" ]
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-files-recursive = path:
|
get-files-recursive = path: let
|
||||||
let
|
entries = safe-read-directory path;
|
||||||
entries = safe-read-directory path;
|
filtered-entries =
|
||||||
filtered-entries =
|
filterAttrs
|
||||||
filterAttrs
|
(name: kind: (is-file-kind kind) || (is-directory-kind kind))
|
||||||
(name: kind: (is-file-kind kind) || (is-directory-kind kind))
|
entries;
|
||||||
entries;
|
map-file = name: kind: let
|
||||||
map-file = name: kind:
|
path' = "${path}/${name}";
|
||||||
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.
|
||||||
|
|
@ -157,8 +150,8 @@ in
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-nix-files = path:
|
get-nix-files = path:
|
||||||
builtins.filter
|
builtins.filter
|
||||||
(snowfall-lib.path.has-file-extension "nix")
|
(snowfall-lib.path.has-file-extension "nix")
|
||||||
(get-files path);
|
(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:
|
||||||
|
|
@ -172,8 +165,8 @@ in
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-nix-files-recursive = path:
|
get-nix-files-recursive = path:
|
||||||
builtins.filter
|
builtins.filter
|
||||||
(snowfall-lib.path.has-file-extension "nix")
|
(snowfall-lib.path.has-file-extension "nix")
|
||||||
(get-files-recursive path);
|
(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:
|
||||||
|
|
@ -187,8 +180,8 @@ in
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-default-nix-files = path:
|
get-default-nix-files = path:
|
||||||
builtins.filter
|
builtins.filter
|
||||||
(name: builtins.baseNameOf name == "default.nix")
|
(name: builtins.baseNameOf name == "default.nix")
|
||||||
(get-files path);
|
(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:
|
||||||
|
|
@ -202,8 +195,8 @@ in
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-default-nix-files-recursive = path:
|
get-default-nix-files-recursive = path:
|
||||||
builtins.filter
|
builtins.filter
|
||||||
(name: builtins.baseNameOf name == "default.nix")
|
(name: builtins.baseNameOf name == "default.nix")
|
||||||
(get-files-recursive path);
|
(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:
|
||||||
|
|
@ -217,11 +210,12 @@ in
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-non-default-nix-files = path:
|
get-non-default-nix-files = path:
|
||||||
builtins.filter
|
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:
|
||||||
|
|
@ -235,10 +229,11 @@ in
|
||||||
#@ Path -> [Path]
|
#@ Path -> [Path]
|
||||||
get-non-default-nix-files-recursive = path:
|
get-non-default-nix-files-recursive = path:
|
||||||
builtins.filter
|
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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
{ core-inputs
|
{
|
||||||
, user-inputs
|
core-inputs,
|
||||||
, snowfall-lib
|
user-inputs,
|
||||||
, snowfall-config
|
snowfall-lib,
|
||||||
}:
|
snowfall-config,
|
||||||
|
}: let
|
||||||
let
|
inherit
|
||||||
inherit (core-inputs.nixpkgs.lib)
|
(core-inputs.nixpkgs.lib)
|
||||||
assertMsg
|
assertMsg
|
||||||
foldl
|
foldl
|
||||||
head
|
head
|
||||||
|
|
@ -23,29 +23,29 @@ let
|
||||||
mkAliasDefinitions
|
mkAliasDefinitions
|
||||||
mkAliasAndWrapDefinitions
|
mkAliasAndWrapDefinitions
|
||||||
mkOption
|
mkOption
|
||||||
types;
|
types
|
||||||
|
;
|
||||||
|
|
||||||
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(jakehamilton): This prevents an error during evaluation if the input does
|
# @NOTE(jakehamilton): This prevents an error during evaluation if the input does
|
||||||
# not exist.
|
# not exist.
|
||||||
if user-inputs ? home-manager then
|
if user-inputs ? home-manager
|
||||||
|
then
|
||||||
snowfall-lib.internal.system-lib.extend
|
snowfall-lib.internal.system-lib.extend
|
||||||
(final: prev:
|
(final: prev:
|
||||||
# @NOTE(jakehamilton): This order is important, this library's extend and other utilities must write
|
# @NOTE(jakehamilton): 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:
|
||||||
|
|
@ -57,22 +57,18 @@ in
|
||||||
## { user = "myuser"; host = "myhost"; }
|
## { user = "myuser"; host = "myhost"; }
|
||||||
## ```
|
## ```
|
||||||
#@ String -> Attrs
|
#@ String -> Attrs
|
||||||
split-user-and-host = target:
|
split-user-and-host = target: let
|
||||||
let
|
raw-name-parts = builtins.split "@" target;
|
||||||
raw-name-parts = builtins.split "@" target;
|
name-parts = builtins.filter builtins.isString raw-name-parts;
|
||||||
name-parts = builtins.filter builtins.isString raw-name-parts;
|
|
||||||
|
|
||||||
user = builtins.elemAt name-parts 0;
|
|
||||||
host =
|
|
||||||
if builtins.length name-parts > 1 then
|
|
||||||
builtins.elemAt name-parts 1
|
|
||||||
else
|
|
||||||
"";
|
|
||||||
in
|
|
||||||
{
|
|
||||||
inherit user host;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
user = builtins.elemAt name-parts 0;
|
||||||
|
host =
|
||||||
|
if builtins.length name-parts > 1
|
||||||
|
then builtins.elemAt name-parts 1
|
||||||
|
else "";
|
||||||
|
in {
|
||||||
|
inherit user host;
|
||||||
|
};
|
||||||
|
|
||||||
## Create a home.
|
## Create a home.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
|
|
@ -84,32 +80,32 @@ in
|
||||||
## <flake-utils-plus-home-configuration>
|
## <flake-utils-plus-home-configuration>
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-home =
|
create-home = {
|
||||||
{ path
|
path,
|
||||||
, name ? builtins.unsafeDiscardStringContext (snowfall-lib.system.get-inferred-system-name path)
|
name ? builtins.unsafeDiscardStringContext (snowfall-lib.system.get-inferred-system-name path),
|
||||||
, modules ? [ ]
|
modules ? [],
|
||||||
, specialArgs ? { }
|
specialArgs ? {},
|
||||||
, channelName ? "nixpkgs"
|
channelName ? "nixpkgs",
|
||||||
, system ? "x86_64-linux"
|
system ? "x86_64-linux",
|
||||||
}:
|
}: let
|
||||||
let
|
user-metadata = split-user-and-host name;
|
||||||
user-metadata = split-user-and-host name;
|
|
||||||
|
|
||||||
# @NOTE(jakehamilton): home-manager has trouble with `pkgs` recursion if it isn't passed in here.
|
# @NOTE(jakehamilton): 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;
|
lib = home-lib;
|
||||||
in
|
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-inputs ? home-manager) "In order to create home-manager configurations, you must include `home-manager` as a flake input.";
|
||||||
assert assertMsg (user-metadata.host != "") "Snowfall Lib homes must be named with the format: user@system";
|
assert assertMsg (user-metadata.host != "") "Snowfall Lib homes must be named with the format: user@system"; {
|
||||||
{
|
|
||||||
inherit channelName system;
|
inherit channelName system;
|
||||||
|
|
||||||
output = "homeConfigurations";
|
output = "homeConfigurations";
|
||||||
|
|
||||||
modules = [
|
modules =
|
||||||
path
|
[
|
||||||
../../modules/home/user/default.nix
|
path
|
||||||
] ++ modules;
|
../../modules/home/user/default.nix
|
||||||
|
]
|
||||||
|
++ modules;
|
||||||
|
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
inherit name;
|
inherit name;
|
||||||
|
|
@ -125,20 +121,25 @@ in
|
||||||
|
|
||||||
builder = args:
|
builder = args:
|
||||||
user-inputs.home-manager.lib.homeManagerConfiguration
|
user-inputs.home-manager.lib.homeManagerConfiguration
|
||||||
((builtins.removeAttrs args [ "system" "specialArgs" ]) // {
|
((builtins.removeAttrs args ["system" "specialArgs"])
|
||||||
|
// {
|
||||||
inherit pkgs lib;
|
inherit pkgs lib;
|
||||||
|
|
||||||
modules = args.modules ++ [
|
modules =
|
||||||
(module-args: import ./nix-registry-module.nix (module-args // {
|
args.modules
|
||||||
inherit user-inputs core-inputs;
|
++ [
|
||||||
}))
|
(module-args:
|
||||||
({
|
import ./nix-registry-module.nix (module-args
|
||||||
snowfallorg.user = {
|
// {
|
||||||
name = mkDefault user-metadata.user;
|
inherit user-inputs core-inputs;
|
||||||
enable = mkDefault true;
|
}))
|
||||||
};
|
{
|
||||||
})
|
snowfallorg.user = {
|
||||||
];
|
name = mkDefault user-metadata.user;
|
||||||
|
enable = mkDefault true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
extraSpecialArgs = specialArgs // args.specialArgs;
|
extraSpecialArgs = specialArgs // args.specialArgs;
|
||||||
});
|
});
|
||||||
|
|
@ -154,23 +155,22 @@ 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:
|
get-target-homes-metadata = target: let
|
||||||
let
|
homes = snowfall-lib.fs.get-directories target;
|
||||||
homes = snowfall-lib.fs.get-directories target;
|
existing-homes = builtins.filter (home: builtins.pathExists "${home}/default.nix") homes;
|
||||||
existing-homes = builtins.filter (home: builtins.pathExists "${home}/default.nix") homes;
|
create-home-metadata = path: {
|
||||||
create-home-metadata = path: {
|
path = "${path}/default.nix";
|
||||||
path = "${path}/default.nix";
|
# 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.
|
name = builtins.unsafeDiscardStringContext (builtins.baseNameOf path);
|
||||||
name = builtins.unsafeDiscardStringContext (builtins.baseNameOf path);
|
# 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);
|
||||||
system = builtins.unsafeDiscardStringContext (builtins.baseNameOf target);
|
};
|
||||||
};
|
home-configurations = builtins.map create-home-metadata existing-homes;
|
||||||
home-configurations = builtins.map create-home-metadata existing-homes;
|
in
|
||||||
in
|
|
||||||
home-configurations;
|
home-configurations;
|
||||||
|
|
||||||
## Create all available homes.
|
## Create all available homes.
|
||||||
|
|
@ -183,34 +183,36 @@ 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:
|
create-homes = homes: let
|
||||||
let
|
targets = snowfall-lib.fs.get-directories user-homes-root;
|
||||||
targets = snowfall-lib.fs.get-directories user-homes-root;
|
target-homes-metadata = concatMap get-target-homes-metadata targets;
|
||||||
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 = mapAttrsToList
|
user-home-modules-list =
|
||||||
(module-path: module: args@{ pkgs, ... }: (module args) // {
|
mapAttrsToList
|
||||||
|
(module-path: module: args @ {pkgs, ...}:
|
||||||
|
(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:
|
create-home' = home-metadata: let
|
||||||
let
|
inherit (home-metadata) name;
|
||||||
inherit (home-metadata) name;
|
overrides = homes.users.${name} or {};
|
||||||
overrides = homes.users.${name} or { };
|
in {
|
||||||
in
|
"${name}" = create-home (overrides
|
||||||
{
|
// home-metadata
|
||||||
"${name}" = create-home (overrides // home-metadata // {
|
// {
|
||||||
modules = user-home-modules-list ++ (homes.users.${name}.modules or [ ]) ++ (homes.modules or [ ]);
|
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 (homes: home-metadata: homes // (create-home' home-metadata)) {} target-homes-metadata;
|
||||||
in
|
in
|
||||||
created-homes;
|
created-homes;
|
||||||
|
|
||||||
## Create system modules for home-manager integration.
|
## Create system modules for home-manager integration.
|
||||||
|
|
@ -223,84 +225,88 @@ in
|
||||||
## [Module]
|
## [Module]
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> [Module]
|
#@ Attrs -> [Module]
|
||||||
create-home-system-modules = users:
|
create-home-system-modules = users: let
|
||||||
let
|
created-users = create-homes users;
|
||||||
created-users = create-homes users;
|
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";
|
};
|
||||||
};
|
|
||||||
|
|
||||||
shared-modules = mapAttrsToList
|
shared-modules =
|
||||||
(module-path: module: {
|
mapAttrsToList
|
||||||
_file = "${user-modules-root}/home/${module-path}/default.nix";
|
(module-path: module: {
|
||||||
|
_file = "${user-modules-root}/home/${module-path}/default.nix";
|
||||||
config = {
|
|
||||||
home-manager.sharedModules = [ module ];
|
|
||||||
};
|
|
||||||
})
|
|
||||||
user-home-modules;
|
|
||||||
|
|
||||||
snowfall-user-home-module = {
|
|
||||||
_file = "virtual:snowfallorg/modules/home/user/default.nix";
|
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
home-manager.sharedModules = [
|
home-manager.sharedModules = [module];
|
||||||
../../modules/home/user/default.nix
|
};
|
||||||
];
|
})
|
||||||
|
user-home-modules;
|
||||||
|
|
||||||
|
snowfall-user-home-module = {
|
||||||
|
_file = "virtual:snowfallorg/modules/home/user/default.nix";
|
||||||
|
|
||||||
|
config = {
|
||||||
|
home-manager.sharedModules = [
|
||||||
|
../../modules/home/user/default.nix
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
extra-special-args-module = args @ {
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
system ? pkgs.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;
|
||||||
|
|
||||||
|
lib = home-lib;
|
||||||
|
|
||||||
|
inputs = snowfall-lib.flake.without-src user-inputs;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
extra-special-args-module =
|
system-modules =
|
||||||
args@{ config
|
builtins.map
|
||||||
, pkgs
|
(
|
||||||
, system ? pkgs.system
|
name: let
|
||||||
, target ? system
|
created-user = created-users.${name};
|
||||||
, format ? "home"
|
user-module = head created-user.modules;
|
||||||
, host ? ""
|
other-modules = users.users.${name}.modules or [];
|
||||||
, virtual ? (snowfall-lib.system.is-virtual target)
|
user-name = created-user.specialArgs.user;
|
||||||
, systems ? { }
|
in
|
||||||
, ...
|
args @ {
|
||||||
}:
|
config,
|
||||||
{
|
options,
|
||||||
_file = "virtual:snowfallorg/home/extra-special-args";
|
pkgs,
|
||||||
|
host ? "",
|
||||||
config = {
|
...
|
||||||
home-manager.extraSpecialArgs = {
|
}: let
|
||||||
inherit system target format virtual systems host;
|
|
||||||
|
|
||||||
lib = home-lib;
|
|
||||||
|
|
||||||
inputs = snowfall-lib.flake.without-src user-inputs;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
system-modules = builtins.map
|
|
||||||
(name:
|
|
||||||
let
|
|
||||||
created-user = created-users.${name};
|
|
||||||
user-module = head created-user.modules;
|
|
||||||
other-modules = users.users.${name}.modules or [ ];
|
|
||||||
user-name = created-user.specialArgs.user;
|
|
||||||
in
|
|
||||||
args@{ config
|
|
||||||
, options
|
|
||||||
, pkgs
|
|
||||||
, host ? ""
|
|
||||||
, ...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
host-matches = created-user.specialArgs.host == host;
|
host-matches = created-user.specialArgs.host == host;
|
||||||
|
|
||||||
# @NOTE(jakehamilton): To conform to the config structure of home-manager, we have to
|
# @NOTE(jakehamilton): 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 = user-option:
|
||||||
if (user-option ? "_type") && user-option._type == "merge" then
|
if (user-option ? "_type") && user-option._type == "merge"
|
||||||
user-option // {
|
then
|
||||||
contents = builtins.map
|
user-option
|
||||||
(merge-entry:
|
// {
|
||||||
merge-entry.${user-name}.home.config or { }
|
contents =
|
||||||
|
builtins.map
|
||||||
|
(
|
||||||
|
merge-entry:
|
||||||
|
merge-entry.${user-name}.home.config or {}
|
||||||
)
|
)
|
||||||
user-option.contents;
|
user-option.contents;
|
||||||
}
|
}
|
||||||
|
|
@ -314,11 +320,10 @@ in
|
||||||
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.user;
|
home-config = mkAliasAndWrapDefinitions wrap-user-options options.snowfallorg.user;
|
||||||
in
|
in {
|
||||||
{
|
|
||||||
_file = "virtual:snowfallorg/home/user/${name}";
|
_file = "virtual:snowfallorg/home/user/${name}";
|
||||||
|
|
||||||
config = mkIf host-matches {
|
config = mkIf host-matches {
|
||||||
|
|
@ -331,8 +336,8 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
home-manager = {
|
home-manager = {
|
||||||
users.${user-name} = mkIf config.snowfallorg.user.${user-name}.home.enable ({ pkgs, ... }: {
|
users.${user-name} = mkIf config.snowfallorg.user.${user-name}.home.enable ({pkgs, ...}: {
|
||||||
imports = (home-config.imports or [ ]) ++ other-modules ++ [user-module];
|
imports = (home-config.imports or []) ++ other-modules ++ [user-module];
|
||||||
config = home-config;
|
config = home-config;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -342,9 +347,9 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
(builtins.attrNames created-users);
|
(builtins.attrNames created-users);
|
||||||
in
|
in
|
||||||
[
|
[
|
||||||
extra-special-args-module
|
extra-special-args-module
|
||||||
snowfall-user-home-module
|
snowfall-user-home-module
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
# This code is adapted from flake-utils-plus:
|
# This code is adapted from flake-utils-plus:
|
||||||
# https://github.com/gytis-ivaskevicius/flake-utils-plus/blob/2bf0f91643c2e5ae38c1b26893ac2927ac9bd82a/lib/options.nix
|
# https://github.com/gytis-ivaskevicius/flake-utils-plus/blob/2bf0f91643c2e5ae38c1b26893ac2927ac9bd82a/lib/options.nix
|
||||||
{ lib, config, user-inputs, core-inputs, ... }:
|
|
||||||
|
|
||||||
{
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
user-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.
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
{ core-inputs
|
{
|
||||||
, user-inputs
|
core-inputs,
|
||||||
, snowfall-lib
|
user-inputs,
|
||||||
, snowfall-config
|
snowfall-lib,
|
||||||
}:
|
snowfall-config,
|
||||||
|
}: let
|
||||||
let
|
|
||||||
inherit (core-inputs.nixpkgs.lib) assertMsg fix fold filterAttrs callPackageWith;
|
inherit (core-inputs.nixpkgs.lib) assertMsg fix fold filterAttrs callPackageWith;
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -17,35 +16,35 @@ 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 = snowfall-lib.fs.get-file "lib";
|
user-lib-root = snowfall-lib.fs.get-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:
|
user-lib = fix (
|
||||||
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;
|
||||||
lib = snowfall-lib.attrs.merge-shallow [
|
lib = snowfall-lib.attrs.merge-shallow [
|
||||||
base-lib
|
base-lib
|
||||||
{ internal = user-lib; }
|
{internal = user-lib;}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
libs = builtins.map
|
libs =
|
||||||
(path: callPackageWith attrs path { })
|
builtins.map
|
||||||
|
(path: callPackageWith attrs path {})
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
{ core-inputs
|
{
|
||||||
, user-inputs
|
core-inputs,
|
||||||
, snowfall-lib
|
user-inputs,
|
||||||
, snowfall-config
|
snowfall-lib,
|
||||||
}:
|
snowfall-config,
|
||||||
|
}: let
|
||||||
let
|
|
||||||
inherit (builtins) baseNameOf;
|
inherit (builtins) baseNameOf;
|
||||||
inherit (core-inputs.nixpkgs.lib) assertMsg foldl mapAttrs hasPrefix;
|
inherit (core-inputs.nixpkgs.lib) assertMsg foldl mapAttrs hasPrefix;
|
||||||
|
|
||||||
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:
|
||||||
|
|
@ -22,65 +20,61 @@ in
|
||||||
## { another-module = ...; my-module = ...; default = ...; }
|
## { another-module = ...; my-module = ...; default = ...; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-modules =
|
create-modules = {
|
||||||
{ src ? "${user-modules-root}/nixos"
|
src ? "${user-modules-root}/nixos",
|
||||||
, overrides ? { }
|
overrides ? {},
|
||||||
, alias ? { }
|
alias ? {},
|
||||||
}:
|
}: let
|
||||||
let
|
user-modules = snowfall-lib.fs.get-default-nix-files-recursive src;
|
||||||
user-modules = snowfall-lib.fs.get-default-nix-files-recursive src;
|
create-module-metadata = module: {
|
||||||
create-module-metadata = module: {
|
name = let
|
||||||
name =
|
path-name = builtins.replaceStrings [src "/default.nix"] ["" ""] (builtins.unsafeDiscardStringContext module);
|
||||||
let
|
in
|
||||||
path-name = builtins.replaceStrings [ src "/default.nix" ] [ "" "" ] (builtins.unsafeDiscardStringContext module);
|
if hasPrefix "/" path-name
|
||||||
|
then builtins.substring 1 ((builtins.stringLength path-name) - 1) path-name
|
||||||
|
else path-name;
|
||||||
|
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.system;
|
||||||
|
target = args.target or system;
|
||||||
|
|
||||||
|
format = let
|
||||||
|
virtual-system-type = snowfall-lib.system.get-virtual-system-type target;
|
||||||
in
|
in
|
||||||
if hasPrefix "/" path-name then
|
if virtual-system-type != ""
|
||||||
builtins.substring 1 ((builtins.stringLength path-name) - 1) path-name
|
then virtual-system-type
|
||||||
else
|
else if snowfall-lib.system.is-darwin target
|
||||||
path-name;
|
then "darwin"
|
||||||
path = module;
|
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;
|
||||||
|
pkgs = user-inputs.self.pkgs.${system}.nixpkgs;
|
||||||
|
|
||||||
|
inputs = snowfall-lib.flake.without-src user-inputs;
|
||||||
|
};
|
||||||
|
user-module = import metadata.path modified-args;
|
||||||
|
in
|
||||||
|
user-module // {_file = metadata.path;};
|
||||||
};
|
};
|
||||||
modules-metadata = builtins.map create-module-metadata user-modules;
|
modules-without-aliases = foldl merge-modules {} modules-metadata;
|
||||||
merge-modules = modules: metadata:
|
aliased-modules = mapAttrs (name: value: modules-without-aliases.${value}) alias;
|
||||||
modules // {
|
modules = modules-without-aliases // aliased-modules // overrides;
|
||||||
# @NOTE(jakehamilton): home-manager *requires* modules to specify named arguments or it will not
|
in
|
||||||
# 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.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;
|
|
||||||
pkgs = user-inputs.self.pkgs.${system}.nixpkgs;
|
|
||||||
|
|
||||||
inputs = snowfall-lib.flake.without-src user-inputs;
|
|
||||||
};
|
|
||||||
user-module = import metadata.path modified-args;
|
|
||||||
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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
{ core-inputs
|
{
|
||||||
, user-inputs
|
core-inputs,
|
||||||
, snowfall-lib
|
user-inputs,
|
||||||
, snowfall-config
|
snowfall-lib,
|
||||||
}:
|
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:
|
||||||
|
|
@ -22,29 +20,26 @@ in
|
||||||
## (channels: [ ... ])
|
## (channels: [ ... ])
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs -> [(a -> b -> c)]
|
#@ Attrs -> Attrs -> [(a -> b -> c)]
|
||||||
create-overlays-builder =
|
create-overlays-builder = {
|
||||||
{ src ? user-overlays-root
|
src ? user-overlays-root,
|
||||||
, package-namespace ? "internal"
|
package-namespace ? "internal",
|
||||||
, extra-overlays ? [ ]
|
extra-overlays ? [],
|
||||||
}: channels:
|
}: channels: let
|
||||||
let
|
user-overlays = snowfall-lib.fs.get-default-nix-files-recursive src;
|
||||||
user-overlays = snowfall-lib.fs.get-default-nix-files-recursive src;
|
create-overlay = overlay: import overlay (user-inputs // {inherit channels;});
|
||||||
create-overlay = overlay: import overlay (user-inputs // { inherit channels; });
|
user-packages-overlay = final: prev: let
|
||||||
user-packages-overlay = final: prev:
|
user-packages = snowfall-lib.package.create-packages {
|
||||||
let
|
pkgs = final;
|
||||||
user-packages = snowfall-lib.package.create-packages {
|
channels = channels;
|
||||||
pkgs = final;
|
};
|
||||||
channels = channels;
|
in {
|
||||||
};
|
${package-namespace} =
|
||||||
in
|
(prev.${package-namespace} or {})
|
||||||
{
|
// user-packages;
|
||||||
${package-namespace} =
|
};
|
||||||
(prev.${package-namespace} or { })
|
overlays =
|
||||||
// user-packages;
|
[user-packages-overlay] ++ extra-overlays ++ (builtins.map create-overlay user-overlays);
|
||||||
};
|
in
|
||||||
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).
|
||||||
|
|
@ -58,133 +53,126 @@ 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
|
src ? user-overlays-root,
|
||||||
, packages-src ? user-packages-root
|
packages-src ? user-packages-root,
|
||||||
, package-namespace ? null
|
package-namespace ? null,
|
||||||
, extra-overlays ? { }
|
extra-overlays ? {},
|
||||||
}:
|
}: let
|
||||||
let
|
fake-pkgs = {
|
||||||
fake-pkgs = {
|
callPackage = x: x;
|
||||||
callPackage = x: x;
|
isFakePkgs = true;
|
||||||
isFakePkgs = true;
|
lib = {};
|
||||||
lib = { };
|
system = "fake-system";
|
||||||
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};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
if package-namespace == null
|
||||||
|
then user-packages
|
||||||
|
else {
|
||||||
|
${package-namespace} =
|
||||||
|
(prev.${package-namespace} or {})
|
||||||
|
// user-packages;
|
||||||
};
|
};
|
||||||
|
|
||||||
user-overlays = snowfall-lib.fs.get-default-nix-files-recursive src;
|
create-overlay = (
|
||||||
|
overlays: file: let
|
||||||
channel-systems = user-inputs.self.pkgs;
|
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory file);
|
||||||
|
overlay = final: prev: let
|
||||||
user-packages-overlay = final: prev:
|
channels = channel-systems.${prev.system};
|
||||||
let
|
user-overlay = import file (user-inputs // {inherit channels;});
|
||||||
user-packages = snowfall-lib.package.create-packages {
|
packages = user-packages-overlay final prev;
|
||||||
pkgs = final;
|
prev-with-packages =
|
||||||
channels = channel-systems.${prev.system};
|
if package-namespace == null
|
||||||
};
|
then prev // packages
|
||||||
in
|
|
||||||
if package-namespace == null then
|
|
||||||
user-packages
|
|
||||||
else
|
|
||||||
{
|
|
||||||
${package-namespace} =
|
|
||||||
(prev.${package-namespace} or { })
|
|
||||||
// user-packages;
|
|
||||||
};
|
|
||||||
|
|
||||||
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 (user-inputs // { inherit channels; });
|
|
||||||
packages = user-packages-overlay final prev;
|
|
||||||
prev-with-packages =
|
|
||||||
if package-namespace == null then
|
|
||||||
prev // packages
|
|
||||||
else
|
|
||||||
prev // {
|
|
||||||
${package-namespace} =
|
|
||||||
(prev.${package-namespace} or { })
|
|
||||||
// packages.${package-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
|
else
|
||||||
outputs;
|
prev
|
||||||
fake-overlay-result = overlay fake-pkgs fake-pkgs;
|
// {
|
||||||
|
${package-namespace} =
|
||||||
|
(prev.${package-namespace} or {})
|
||||||
|
// packages.${package-namespace};
|
||||||
|
};
|
||||||
|
user-overlay-packages =
|
||||||
|
user-overlay
|
||||||
|
final
|
||||||
|
prev-with-packages;
|
||||||
|
outputs =
|
||||||
|
user-overlay-packages;
|
||||||
in
|
in
|
||||||
if fake-overlay-result.__dontExport or false == true then
|
if user-overlay-packages.__dontExport or false == true
|
||||||
overlays
|
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
|
foldl
|
||||||
create-overlay
|
create-overlay
|
||||||
{ }
|
{}
|
||||||
user-overlays;
|
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:
|
create-package-overlay = package-overlays: file: let
|
||||||
let
|
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory file);
|
||||||
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory file);
|
overlay = final: prev: let
|
||||||
overlay = final: prev:
|
channels = channel-systems.${prev.system};
|
||||||
let
|
packages = snowfall-lib.package.create-packages {
|
||||||
channels = channel-systems.${prev.system};
|
channels = channel-systems.${prev.system};
|
||||||
packages = snowfall-lib.package.create-packages {
|
};
|
||||||
channels = channel-systems.${prev.system};
|
in
|
||||||
};
|
if package-namespace == null
|
||||||
in
|
then {${name} = packages.${name};}
|
||||||
if package-namespace == null then
|
else {
|
||||||
{ ${name} = packages.${name}; }
|
${package-namespace} =
|
||||||
else
|
(prev.${package-namespace} or {})
|
||||||
{
|
// {${name} = packages.${name};};
|
||||||
${package-namespace} =
|
|
||||||
(prev.${package-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/${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
|
package-overlays
|
||||||
// overlays
|
// overlays
|
||||||
// { default = default-overlay; }
|
// {default = default-overlay;}
|
||||||
// extra-overlays;
|
// extra-overlays;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
{ core-inputs
|
{
|
||||||
, user-inputs
|
core-inputs,
|
||||||
, snowfall-lib
|
user-inputs,
|
||||||
, snowfall-config
|
snowfall-lib,
|
||||||
}:
|
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:
|
||||||
|
|
@ -22,51 +20,54 @@ in
|
||||||
## { another-package = ...; my-package = ...; default = ...; }
|
## { another-package = ...; my-package = ...; default = ...; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-packages =
|
create-packages = {
|
||||||
{ channels
|
channels,
|
||||||
, src ? user-packages-root
|
src ? user-packages-root,
|
||||||
, pkgs ? channels.nixpkgs
|
pkgs ? channels.nixpkgs,
|
||||||
, overrides ? { }
|
overrides ? {},
|
||||||
, alias ? { }
|
alias ? {},
|
||||||
, package-namespace ? "internal"
|
package-namespace ? "internal",
|
||||||
}:
|
}: let
|
||||||
let
|
user-packages = snowfall-lib.fs.get-default-nix-files-recursive src;
|
||||||
user-packages = snowfall-lib.fs.get-default-nix-files-recursive src;
|
create-package-metadata = package: let
|
||||||
create-package-metadata = package:
|
namespaced-packages = {
|
||||||
let
|
${package-namespace} = packages-without-aliases;
|
||||||
namespaced-packages = {
|
};
|
||||||
${package-namespace} = packages-without-aliases;
|
extra-inputs =
|
||||||
};
|
pkgs
|
||||||
extra-inputs = pkgs // namespaced-packages // {
|
// namespaced-packages
|
||||||
inherit channels;
|
// {
|
||||||
lib = snowfall-lib.internal.system-lib;
|
inherit channels;
|
||||||
pkgs = pkgs // namespaced-packages;
|
lib = snowfall-lib.internal.system-lib;
|
||||||
inputs = snowfall-lib.flake.without-snowfall-inputs user-inputs;
|
pkgs = pkgs // namespaced-packages;
|
||||||
};
|
inputs = snowfall-lib.flake.without-snowfall-inputs user-inputs;
|
||||||
in
|
};
|
||||||
{
|
in {
|
||||||
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory package);
|
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory package);
|
||||||
drv =
|
drv = let
|
||||||
let
|
pkg = callPackageWith extra-inputs package {};
|
||||||
pkg = callPackageWith extra-inputs package { };
|
in
|
||||||
in
|
pkg
|
||||||
pkg // {
|
// {
|
||||||
meta = (pkg.meta or { }) // {
|
meta =
|
||||||
snowfall = {
|
(pkg.meta or {})
|
||||||
path = package;
|
// {
|
||||||
};
|
snowfall = {
|
||||||
|
path = package;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
packages-metadata = builtins.map create-package-metadata user-packages;
|
};
|
||||||
merge-packages = packages: metadata:
|
packages-metadata = builtins.map create-package-metadata user-packages;
|
||||||
packages // {
|
merge-packages = packages: metadata:
|
||||||
${metadata.name} = metadata.drv;
|
packages
|
||||||
};
|
// {
|
||||||
packages-without-aliases = foldl merge-packages { } packages-metadata;
|
${metadata.name} = metadata.drv;
|
||||||
aliased-packages = mapAttrs (name: value: packages-without-aliases.${value}) alias;
|
};
|
||||||
packages = packages-without-aliases // aliased-packages // overrides;
|
packages-without-aliases = foldl merge-packages {} packages-metadata;
|
||||||
in
|
aliased-packages = mapAttrs (name: value: packages-without-aliases.${value}) alias;
|
||||||
|
packages = packages-without-aliases // aliased-packages // overrides;
|
||||||
|
in
|
||||||
filterPackages pkgs.system packages;
|
filterPackages pkgs.system packages;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
{ core-inputs
|
{
|
||||||
, user-inputs
|
core-inputs,
|
||||||
, snowfall-lib
|
user-inputs,
|
||||||
, snowfall-config
|
snowfall-lib,
|
||||||
}:
|
snowfall-config,
|
||||||
|
}: let
|
||||||
let
|
|
||||||
inherit (builtins) toString baseNameOf dirOf concatStringsSep;
|
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:
|
||||||
|
|
@ -22,12 +20,10 @@ in
|
||||||
## [ "my-file" "md" ]
|
## [ "my-file" "md" ]
|
||||||
## ```
|
## ```
|
||||||
#@ String -> [String]
|
#@ String -> [String]
|
||||||
split-file-extension = file:
|
split-file-extension = file: let
|
||||||
let
|
match = builtins.match file-name-regex file;
|
||||||
match = builtins.match file-name-regex file;
|
in
|
||||||
in
|
assert assertMsg (match != null) "lib.snowfall.split-file-extension: File must have an extension to split."; match;
|
||||||
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:
|
||||||
|
|
@ -39,10 +35,9 @@ in
|
||||||
## true
|
## true
|
||||||
## ```
|
## ```
|
||||||
#@ String -> Bool
|
#@ String -> Bool
|
||||||
has-any-file-extension = file:
|
has-any-file-extension = file: let
|
||||||
let
|
match = builtins.match file-name-regex (toString file);
|
||||||
match = builtins.match file-name-regex (toString file);
|
in
|
||||||
in
|
|
||||||
match != null;
|
match != null;
|
||||||
|
|
||||||
## Get the file extension of a file name.
|
## Get the file extension of a file name.
|
||||||
|
|
@ -56,13 +51,12 @@ in
|
||||||
## ```
|
## ```
|
||||||
#@ String -> String
|
#@ String -> String
|
||||||
get-file-extension = file:
|
get-file-extension = file:
|
||||||
if has-any-file-extension file then
|
if has-any-file-extension file
|
||||||
let
|
then let
|
||||||
match = builtins.match file-name-regex (toString file);
|
match = builtins.match file-name-regex (toString file);
|
||||||
in
|
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:
|
||||||
|
|
@ -75,10 +69,9 @@ in
|
||||||
## ```
|
## ```
|
||||||
#@ String -> String -> Bool
|
#@ String -> String -> Bool
|
||||||
has-file-extension = extension: file:
|
has-file-extension = extension: file:
|
||||||
if has-any-file-extension file then
|
if has-any-file-extension file
|
||||||
extension == get-file-extension file
|
then extension == get-file-extension file
|
||||||
else
|
else false;
|
||||||
false;
|
|
||||||
|
|
||||||
## Get the parent directory for a given path.
|
## Get the parent directory for a given path.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
|
|
@ -102,13 +95,11 @@ in
|
||||||
## "my-file"
|
## "my-file"
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> String
|
#@ Path -> String
|
||||||
get-file-name-without-extension = path:
|
get-file-name-without-extension = path: let
|
||||||
let
|
file-name = baseNameOf path;
|
||||||
file-name = baseNameOf path;
|
in
|
||||||
in
|
if has-any-file-extension file-name
|
||||||
if has-any-file-extension file-name then
|
then concatStringsSep "" (init (split-file-extension file-name))
|
||||||
concatStringsSep "" (init (split-file-extension file-name))
|
else file-name;
|
||||||
else
|
|
||||||
file-name;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
{ core-inputs
|
{
|
||||||
, user-inputs
|
core-inputs,
|
||||||
, snowfall-lib
|
user-inputs,
|
||||||
, snowfall-config
|
snowfall-lib,
|
||||||
}:
|
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:
|
||||||
|
|
@ -22,36 +20,36 @@ in
|
||||||
## { another-shell = ...; my-shell = ...; default = ...; }
|
## { another-shell = ...; my-shell = ...; default = ...; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-shells =
|
create-shells = {
|
||||||
{ channels
|
channels,
|
||||||
, src ? user-shells-root
|
src ? user-shells-root,
|
||||||
, pkgs ? channels.nixpkgs
|
pkgs ? channels.nixpkgs,
|
||||||
, overrides ? { }
|
overrides ? {},
|
||||||
, alias ? { }
|
alias ? {},
|
||||||
}:
|
}: let
|
||||||
let
|
user-shells = snowfall-lib.fs.get-default-nix-files-recursive src;
|
||||||
user-shells = snowfall-lib.fs.get-default-nix-files-recursive src;
|
create-shell-metadata = shell: let
|
||||||
create-shell-metadata = shell:
|
extra-inputs =
|
||||||
let
|
pkgs
|
||||||
extra-inputs = pkgs // {
|
// {
|
||||||
inherit channels;
|
inherit channels;
|
||||||
lib = snowfall-lib.internal.system-lib;
|
lib = snowfall-lib.internal.system-lib;
|
||||||
inputs = snowfall-lib.flake.without-src user-inputs;
|
inputs = snowfall-lib.flake.without-src user-inputs;
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory shell);
|
|
||||||
drv = callPackageWith extra-inputs shell { };
|
|
||||||
};
|
};
|
||||||
shells-metadata = builtins.map create-shell-metadata user-shells;
|
in {
|
||||||
merge-shells = shells: metadata:
|
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory shell);
|
||||||
shells // {
|
drv = callPackageWith extra-inputs shell {};
|
||||||
${metadata.name} = metadata.drv;
|
};
|
||||||
};
|
shells-metadata = builtins.map create-shell-metadata user-shells;
|
||||||
shells-without-aliases = foldl merge-shells { } shells-metadata;
|
merge-shells = shells: metadata:
|
||||||
aliased-shells = mapAttrs (name: value: shells-without-aliases.${value}) alias;
|
shells
|
||||||
shells = shells-without-aliases // aliased-shells // overrides;
|
// {
|
||||||
in
|
${metadata.name} = metadata.drv;
|
||||||
|
};
|
||||||
|
shells-without-aliases = foldl merge-shells {} shells-metadata;
|
||||||
|
aliased-shells = mapAttrs (name: value: shells-without-aliases.${value}) alias;
|
||||||
|
shells = shells-without-aliases // aliased-shells // overrides;
|
||||||
|
in
|
||||||
filterPackages pkgs.system shells;
|
filterPackages pkgs.system shells;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
{ core-inputs
|
{
|
||||||
, user-inputs
|
core-inputs,
|
||||||
, snowfall-lib
|
user-inputs,
|
||||||
, snowfall-config
|
snowfall-lib,
|
||||||
}:
|
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;
|
||||||
|
|
||||||
|
|
@ -12,8 +11,7 @@ let
|
||||||
|
|
||||||
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:
|
||||||
|
|
@ -26,10 +24,9 @@ in
|
||||||
## ```
|
## ```
|
||||||
#@ Path -> String
|
#@ Path -> String
|
||||||
get-inferred-system-name = path:
|
get-inferred-system-name = path:
|
||||||
if snowfall-lib.path.has-file-extension "nix" path then
|
if snowfall-lib.path.has-file-extension "nix" path
|
||||||
snowfall-lib.path.get-parent-directory path
|
then snowfall-lib.path.get-parent-directory path
|
||||||
else
|
else baseNameOf path;
|
||||||
baseNameOf path;
|
|
||||||
|
|
||||||
## Check whether a named system is macOS.
|
## Check whether a named system is macOS.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
|
|
@ -80,14 +77,14 @@ in
|
||||||
#@ String -> String
|
#@ String -> String
|
||||||
get-virtual-system-type = target:
|
get-virtual-system-type = target:
|
||||||
foldl
|
foldl
|
||||||
(result: virtual-system:
|
(
|
||||||
if result == "" && hasInfix virtual-system target then
|
result: virtual-system:
|
||||||
virtual-system
|
if result == "" && hasInfix virtual-system target
|
||||||
else
|
then virtual-system
|
||||||
result
|
else result
|
||||||
)
|
)
|
||||||
""
|
""
|
||||||
virtual-systems;
|
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:
|
||||||
|
|
@ -99,23 +96,22 @@ 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:
|
get-target-systems-metadata = target: let
|
||||||
let
|
systems = snowfall-lib.fs.get-directories target;
|
||||||
systems = snowfall-lib.fs.get-directories target;
|
existing-systems = builtins.filter (system: builtins.pathExists "${system}/default.nix") systems;
|
||||||
existing-systems = builtins.filter (system: builtins.pathExists "${system}/default.nix") systems;
|
create-system-metadata = path: {
|
||||||
create-system-metadata = path: {
|
path = "${path}/default.nix";
|
||||||
path = "${path}/default.nix";
|
# 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.
|
name = builtins.unsafeDiscardStringContext (builtins.baseNameOf path);
|
||||||
name = builtins.unsafeDiscardStringContext (builtins.baseNameOf path);
|
# 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.
|
target = builtins.unsafeDiscardStringContext (builtins.baseNameOf target);
|
||||||
target = builtins.unsafeDiscardStringContext (builtins.baseNameOf target);
|
};
|
||||||
};
|
system-configurations = builtins.map create-system-metadata existing-systems;
|
||||||
system-configurations = builtins.map create-system-metadata existing-systems;
|
in
|
||||||
in
|
|
||||||
system-configurations;
|
system-configurations;
|
||||||
|
|
||||||
## Get the system builder for a given target.
|
## Get the system builder for a given target.
|
||||||
|
|
@ -128,49 +124,62 @@ in
|
||||||
## (args: <system>)
|
## (args: <system>)
|
||||||
## ```
|
## ```
|
||||||
#@ String -> Function
|
#@ String -> Function
|
||||||
get-system-builder = target:
|
get-system-builder = target: let
|
||||||
let
|
virtual-system-type = get-virtual-system-type target;
|
||||||
virtual-system-type = get-virtual-system-type target;
|
virtual-system-builder = args:
|
||||||
virtual-system-builder = args:
|
assert assertMsg (user-inputs ? nixos-generators) "In order to create virtual systems, you must include `nixos-generators` as a flake input.";
|
||||||
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
|
user-inputs.nixos-generators.nixosGenerate
|
||||||
(args // {
|
(args
|
||||||
|
// {
|
||||||
format = virtual-system-type;
|
format = virtual-system-type;
|
||||||
specialArgs = args.specialArgs // {
|
specialArgs =
|
||||||
format = virtual-system-type;
|
args.specialArgs
|
||||||
};
|
// {
|
||||||
modules = args.modules ++ [
|
format = virtual-system-type;
|
||||||
../../modules/nixos/user/default.nix
|
};
|
||||||
];
|
modules =
|
||||||
|
args.modules
|
||||||
|
++ [
|
||||||
|
../../modules/nixos/user/default.nix
|
||||||
|
];
|
||||||
});
|
});
|
||||||
darwin-system-builder = args:
|
darwin-system-builder = args:
|
||||||
assert assertMsg (user-inputs ? darwin) "In order to create virtual systems, you must include `darwin` as a flake input.";
|
assert assertMsg (user-inputs ? darwin) "In order to create virtual systems, you must include `darwin` as a flake input.";
|
||||||
user-inputs.darwin.lib.darwinSystem
|
user-inputs.darwin.lib.darwinSystem
|
||||||
((builtins.removeAttrs args [ "system" "modules" ]) // {
|
((builtins.removeAttrs args ["system" "modules"])
|
||||||
specialArgs = args.specialArgs // {
|
// {
|
||||||
format = "darwin";
|
specialArgs =
|
||||||
};
|
args.specialArgs
|
||||||
modules = args.modules ++ [
|
// {
|
||||||
../../modules/darwin/user/default.nix
|
format = "darwin";
|
||||||
];
|
};
|
||||||
|
modules =
|
||||||
|
args.modules
|
||||||
|
++ [
|
||||||
|
../../modules/darwin/user/default.nix
|
||||||
|
];
|
||||||
});
|
});
|
||||||
linux-system-builder = args:
|
linux-system-builder = args:
|
||||||
core-inputs.nixpkgs.lib.nixosSystem
|
core-inputs.nixpkgs.lib.nixosSystem
|
||||||
(args // {
|
(args
|
||||||
specialArgs = args.specialArgs // {
|
// {
|
||||||
|
specialArgs =
|
||||||
|
args.specialArgs
|
||||||
|
// {
|
||||||
format = "linux";
|
format = "linux";
|
||||||
};
|
};
|
||||||
modules = args.modules ++ [
|
modules =
|
||||||
|
args.modules
|
||||||
|
++ [
|
||||||
../../modules/nixos/user/default.nix
|
../../modules/nixos/user/default.nix
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
in
|
in
|
||||||
if virtual-system-type != "" then
|
if virtual-system-type != ""
|
||||||
virtual-system-builder
|
then virtual-system-builder
|
||||||
else if is-darwin target then
|
else if is-darwin target
|
||||||
darwin-system-builder
|
then darwin-system-builder
|
||||||
else
|
else linux-system-builder;
|
||||||
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:
|
||||||
|
|
@ -182,16 +191,14 @@ in
|
||||||
## "darwinConfigurations"
|
## "darwinConfigurations"
|
||||||
## ```
|
## ```
|
||||||
#@ String -> String
|
#@ String -> String
|
||||||
get-system-output = target:
|
get-system-output = target: let
|
||||||
let
|
virtual-system-type = get-virtual-system-type target;
|
||||||
virtual-system-type = get-virtual-system-type target;
|
in
|
||||||
in
|
if virtual-system-type != ""
|
||||||
if virtual-system-type != "" then
|
then "${virtual-system-type}Configurations"
|
||||||
"${virtual-system-type}Configurations"
|
else if is-darwin target
|
||||||
else if is-darwin target then
|
then "darwinConfigurations"
|
||||||
"darwinConfigurations"
|
else "nixosConfigurations";
|
||||||
else
|
|
||||||
"nixosConfigurations";
|
|
||||||
|
|
||||||
## Get the resolved (non-virtual) system target.
|
## Get the resolved (non-virtual) system target.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
|
|
@ -203,14 +210,12 @@ in
|
||||||
## "x86_64-linux"
|
## "x86_64-linux"
|
||||||
## ```
|
## ```
|
||||||
#@ String -> String
|
#@ String -> String
|
||||||
get-resolved-system-target = target:
|
get-resolved-system-target = target: let
|
||||||
let
|
virtual-system-type = get-virtual-system-type target;
|
||||||
virtual-system-type = get-virtual-system-type target;
|
in
|
||||||
in
|
if virtual-system-type != ""
|
||||||
if virtual-system-type != "" then
|
then builtins.replaceStrings [virtual-system-type] ["linux"] target
|
||||||
builtins.replaceStrings [ virtual-system-type ] [ "linux" ] target
|
else target;
|
||||||
else
|
|
||||||
target;
|
|
||||||
|
|
||||||
## Create a system.
|
## Create a system.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
|
|
@ -222,42 +227,41 @@ in
|
||||||
## <flake-utils-plus-system-configuration>
|
## <flake-utils-plus-system-configuration>
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-system =
|
create-system = {
|
||||||
{ target ? "x86_64-linux"
|
target ? "x86_64-linux",
|
||||||
, system ? get-resolved-system-target target
|
system ? get-resolved-system-target target,
|
||||||
, path
|
path,
|
||||||
, name ? builtins.unsafeDiscardStringContext (get-inferred-system-name path)
|
name ? builtins.unsafeDiscardStringContext (get-inferred-system-name path),
|
||||||
, modules ? [ ]
|
modules ? [],
|
||||||
, specialArgs ? { }
|
specialArgs ? {},
|
||||||
, channelName ? "nixpkgs"
|
channelName ? "nixpkgs",
|
||||||
, builder ? get-system-builder target
|
builder ? get-system-builder target,
|
||||||
, output ? get-system-output target
|
output ? get-system-output target,
|
||||||
, systems ? { }
|
systems ? {},
|
||||||
, homes ? { }
|
homes ? {},
|
||||||
}:
|
}: let
|
||||||
let
|
lib = snowfall-lib.internal.system-lib;
|
||||||
lib = snowfall-lib.internal.system-lib;
|
home-system-modules = snowfall-lib.home.create-home-system-modules homes;
|
||||||
home-system-modules = snowfall-lib.home.create-home-system-modules homes;
|
home-manager-module =
|
||||||
home-manager-module =
|
if is-darwin system
|
||||||
if is-darwin system then
|
then user-inputs.home-manager.darwinModules.home-manager
|
||||||
user-inputs.home-manager.darwinModules.home-manager
|
else user-inputs.home-manager.nixosModules.home-manager;
|
||||||
else
|
home-manager-modules = [home-manager-module] ++ home-system-modules;
|
||||||
user-inputs.home-manager.nixosModules.home-manager;
|
in {
|
||||||
home-manager-modules = [ home-manager-module ] ++ home-system-modules;
|
inherit channelName system builder output;
|
||||||
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 system systems lib;
|
inherit target 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;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
## Create all available systems.
|
## Create all available systems.
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
|
|
@ -269,50 +273,52 @@ in
|
||||||
## { my-host = <flake-utils-plus-system-configuration>; }
|
## { my-host = <flake-utils-plus-system-configuration>; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-systems = { systems ? { }, homes ? { } }:
|
create-systems = {
|
||||||
let
|
systems ? {},
|
||||||
targets = snowfall-lib.fs.get-directories user-systems-root;
|
homes ? {},
|
||||||
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:
|
create-system' = created-systems: system-metadata: let
|
||||||
let
|
overrides = systems.hosts.${system-metadata.name} or {};
|
||||||
overrides = systems.hosts.${system-metadata.name} or { };
|
user-modules =
|
||||||
user-modules =
|
if is-darwin system-metadata.target
|
||||||
if is-darwin system-metadata.target then
|
then user-darwin-modules
|
||||||
user-darwin-modules
|
else user-nixos-modules;
|
||||||
else
|
user-modules-list = builtins.attrValues user-modules;
|
||||||
user-nixos-modules;
|
system-modules =
|
||||||
user-modules-list = builtins.attrValues user-modules;
|
if is-darwin system-metadata.target
|
||||||
system-modules =
|
then darwin-modules
|
||||||
if is-darwin system-metadata.target then
|
else nixos-modules;
|
||||||
darwin-modules
|
in {
|
||||||
else
|
${system-metadata.name} = create-system (overrides
|
||||||
nixos-modules;
|
// system-metadata
|
||||||
in
|
// {
|
||||||
{
|
systems = created-systems;
|
||||||
${system-metadata.name} = create-system (overrides // system-metadata // {
|
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:
|
||||||
created-systems = fix (created-systems:
|
|
||||||
foldl
|
foldl
|
||||||
(systems: system-metadata:
|
(
|
||||||
|
systems: system-metadata:
|
||||||
systems // (create-system' created-systems system-metadata)
|
systems // (create-system' created-systems system-metadata)
|
||||||
)
|
)
|
||||||
{ }
|
{}
|
||||||
target-systems-metadata
|
target-systems-metadata
|
||||||
);
|
);
|
||||||
in
|
in
|
||||||
created-systems;
|
created-systems;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
{ core-inputs
|
{
|
||||||
, user-inputs
|
core-inputs,
|
||||||
, snowfall-lib
|
user-inputs,
|
||||||
, snowfall-config
|
snowfall-lib,
|
||||||
}:
|
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.
|
||||||
##
|
##
|
||||||
|
|
@ -24,28 +22,30 @@ in
|
||||||
## { another-template = ...; my-template = ...; default = ...; }
|
## { another-template = ...; my-template = ...; default = ...; }
|
||||||
## ```
|
## ```
|
||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
create-templates =
|
create-templates = {
|
||||||
{ src ? user-templates-root
|
src ? user-templates-root,
|
||||||
, overrides ? { }
|
overrides ? {},
|
||||||
, alias ? { }
|
alias ? {},
|
||||||
}:
|
}: let
|
||||||
let
|
user-templates = snowfall-lib.fs.get-directories src;
|
||||||
user-templates = snowfall-lib.fs.get-directories src;
|
create-template-metadata = template: {
|
||||||
create-template-metadata = template: {
|
name = builtins.unsafeDiscardStringContext (baseNameOf template);
|
||||||
name = builtins.unsafeDiscardStringContext (baseNameOf template);
|
path = template;
|
||||||
path = template;
|
};
|
||||||
};
|
templates-metadata = builtins.map create-template-metadata user-templates;
|
||||||
templates-metadata = builtins.map create-template-metadata user-templates;
|
merge-templates = templates: metadata:
|
||||||
merge-templates = templates: metadata:
|
templates
|
||||||
templates // {
|
// {
|
||||||
${metadata.name} = (overrides.${metadata.name} or { }) // {
|
${metadata.name} =
|
||||||
|
(overrides.${metadata.name} or {})
|
||||||
|
// {
|
||||||
inherit (metadata) path;
|
inherit (metadata) path;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
templates-without-aliases = foldl merge-templates { } templates-metadata;
|
templates-without-aliases = foldl merge-templates {} templates-metadata;
|
||||||
aliased-templates = mapAttrs (name: value: templates-without-aliases.${value}) alias;
|
aliased-templates = mapAttrs (name: value: templates-without-aliases.${value}) alias;
|
||||||
templates = templates-without-aliases // aliased-templates // overrides;
|
templates = templates-without-aliases // aliased-templates // overrides;
|
||||||
in
|
in
|
||||||
templates;
|
templates;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue