lib: move lib extensions into its own module argument
This commit is contained in:
parent
9bc5d2e85d
commit
b3aa6cad81
39
flake.nix
39
flake.nix
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "nixpkgs/nixos-22.05";
|
nixpkgs.url = "nixpkgs/nixos-22.05";
|
||||||
unstable-nixpkgs.url = "nixpkgs/nixos-unstable";
|
nixpkgs-unstable.url = "nixpkgs/nixos-unstable";
|
||||||
|
|
||||||
home-manager = {
|
home-manager = {
|
||||||
url = "github:nix-community/home-manager/release-22.05";
|
url = "github:nix-community/home-manager/release-22.05";
|
||||||
|
@ -46,18 +46,17 @@
|
||||||
outputs = inputs@{
|
outputs = inputs@{
|
||||||
self,
|
self,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
unstable-nixpkgs,
|
nixpkgs-unstable,
|
||||||
home-manager,
|
home-manager,
|
||||||
vscode-server,
|
vscode-server,
|
||||||
secrets,
|
secrets,
|
||||||
fonts,
|
fonts,
|
||||||
dotfiles,
|
dotfiles,
|
||||||
website,
|
website
|
||||||
...
|
|
||||||
}: let
|
}: let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
|
|
||||||
pkgs = import nixpkgs {
|
pkgs-config = {
|
||||||
inherit system;
|
inherit system;
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
@ -65,26 +64,13 @@
|
||||||
android_sdk.accept_license = true;
|
android_sdk.accept_license = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
overlays = [ self.overlays.lib ];
|
# overlays = [ self.overlays.lib ];
|
||||||
};
|
|
||||||
|
|
||||||
unstable-pkgs = import unstable-nixpkgs {
|
|
||||||
inherit system;
|
|
||||||
|
|
||||||
config = {
|
|
||||||
allowUnfree = true;
|
|
||||||
android_sdk.accept_license = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
overlays = [ self.overlays.lib ];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pkgs = import nixpkgs pkgs-config;
|
||||||
|
unstable-pkgs = import nixpkgs-unstable pkgs-config;
|
||||||
in {
|
in {
|
||||||
overlays = {
|
extendedLib = import ./lib { stdlib = pkgs.lib; };
|
||||||
lib = import ./overlays/lib;
|
|
||||||
};
|
|
||||||
|
|
||||||
lib = (pkgs.extend self.overlays.lib).lib;
|
|
||||||
|
|
||||||
homeConfigurations = {
|
homeConfigurations = {
|
||||||
h7x4 = home-manager.lib.homeManagerConfiguration {
|
h7x4 = home-manager.lib.homeManagerConfiguration {
|
||||||
|
@ -130,6 +116,7 @@
|
||||||
config._module.args = {
|
config._module.args = {
|
||||||
inherit inputs;
|
inherit inputs;
|
||||||
inherit unstable-pkgs;
|
inherit unstable-pkgs;
|
||||||
|
inherit (self) extendedLib;
|
||||||
secrets = secrets.outputs.settings;
|
secrets = secrets.outputs.settings;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -138,12 +125,18 @@
|
||||||
{
|
{
|
||||||
home-manager = {
|
home-manager = {
|
||||||
useGlobalPkgs = true;
|
useGlobalPkgs = true;
|
||||||
extraSpecialArgs = { inherit inputs; secrets = secrets.outputs.settings; };
|
extraSpecialArgs = {
|
||||||
|
inherit inputs;
|
||||||
|
inherit (self) extendedLib;
|
||||||
|
secrets = secrets.outputs.settings;
|
||||||
|
};
|
||||||
|
|
||||||
users.h7x4 = import ./home/home.nix {
|
users.h7x4 = import ./home/home.nix {
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
inherit inputs;
|
inherit inputs;
|
||||||
|
inherit (pkgs) lib;
|
||||||
inherit (config) machineVars colors;
|
inherit (config) machineVars colors;
|
||||||
|
inherit (self) extendedLib;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
{ pkgs, secrets, ... }:
|
{ pkgs, lib, extendedLib, secrets, ... }:
|
||||||
let
|
let
|
||||||
inherit (pkgs) lib;
|
|
||||||
inherit (secrets.ssh.users.pvv) normalUser adminUser;
|
inherit (secrets.ssh.users.pvv) normalUser adminUser;
|
||||||
|
|
||||||
# http://www.pvv.ntnu.no/pvv/Maskiner
|
# http://www.pvv.ntnu.no/pvv/Maskiner
|
||||||
|
@ -82,10 +81,9 @@ let
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
machines: pipe machines pipeline;
|
machines: pipe machines pipeline;
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
programs.ssh.matchBlocks = lib.attrsets.concatAttrs [
|
programs.ssh.matchBlocks = extendedLib.attrsets.concatAttrs [
|
||||||
(convertMachinesWith convertNormalMachine normalMachines)
|
(convertMachinesWith convertNormalMachine normalMachines)
|
||||||
(convertMachinesWith convertAdminMachine rootMachines)
|
(convertMachinesWith convertAdminMachine rootMachines)
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
{ pkgs, inputs, machineVars, colors, ... } @ args: let
|
{ pkgs, lib, extendedLib, inputs, machineVars, colors, ... } @ args: let
|
||||||
inherit (pkgs) lib;
|
inherit (lib) mkForce mkIf optionals;
|
||||||
inherit (pkgs.lib) mkForce mkIf optionals;
|
|
||||||
graphics = !machineVars.headless;
|
graphics = !machineVars.headless;
|
||||||
in {
|
in {
|
||||||
inherit machineVars;
|
inherit machineVars;
|
||||||
|
@ -54,7 +53,7 @@ in {
|
||||||
homeDirectory = "/home/h7x4";
|
homeDirectory = "/home/h7x4";
|
||||||
file = {
|
file = {
|
||||||
".ghci".text = ''
|
".ghci".text = ''
|
||||||
:set prompt "${lib.termColors.front.magenta "[GHCi]λ"} ".
|
:set prompt "${extendedLib.termColors.front.magenta "[GHCi]λ"} ".
|
||||||
'';
|
'';
|
||||||
|
|
||||||
".pyrc".text = ''
|
".pyrc".text = ''
|
||||||
|
@ -63,7 +62,7 @@ in {
|
||||||
|
|
||||||
# You also need \x01 and \x02 to separate escape sequence, due to:
|
# You also need \x01 and \x02 to separate escape sequence, due to:
|
||||||
# https://stackoverflow.com/a/9468954/1147688
|
# https://stackoverflow.com/a/9468954/1147688
|
||||||
sys.ps1='\x01\x1b${lib.termColors.front.blue "[Python]> "}\x02>>>\x01\x1b[0m\x02 ' # bright yellow
|
sys.ps1='\x01\x1b${extendedLib.termColors.front.blue "[Python]> "}\x02>>>\x01\x1b[0m\x02 ' # bright yellow
|
||||||
sys.ps2='\x01\x1b[1;49;31m\x02...\x01\x1b[0m\x02 ' # bright red
|
sys.ps2='\x01\x1b[1;49;31m\x02...\x01\x1b[0m\x02 ' # bright red
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
{ pkgs, config, ... }: let
|
{ pkgs, lib, extendedLib, config, ... }: let
|
||||||
|
|
||||||
# FIXME: lib should be imported directly as a module argument.
|
|
||||||
inherit (pkgs) lib;
|
|
||||||
|
|
||||||
sedColor =
|
sedColor =
|
||||||
color:
|
color:
|
||||||
|
@ -16,7 +13,7 @@
|
||||||
# Context Functors
|
# Context Functors
|
||||||
functors = let
|
functors = let
|
||||||
inherit (lib.strings) concatStringsSep;
|
inherit (lib.strings) concatStringsSep;
|
||||||
inherit (lib.termColors.front) blue;
|
inherit (extendedLib.termColors.front) blue;
|
||||||
genWrapper = type: value: { inherit type; inherit value; };
|
genWrapper = type: value: { inherit type; inherit value; };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
@ -228,7 +225,7 @@ in rec {
|
||||||
watch = "${procps}/bin/watch ";
|
watch = "${procps}/bin/watch ";
|
||||||
|
|
||||||
concatPdfs = shellThen [
|
concatPdfs = shellThen [
|
||||||
"echo \"${lib.termColors.front.red "Concatenating all pdfs in current directory to 'out.pdf'"}\""
|
"echo \"${extendedLib.termColors.front.red "Concatenating all pdfs in current directory to 'out.pdf'"}\""
|
||||||
"${poppler_utils}/bin/pdfunite *.pdf out.pdf"
|
"${poppler_utils}/bin/pdfunite *.pdf out.pdf"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -247,14 +244,14 @@ in rec {
|
||||||
|
|
||||||
"Misc" = {
|
"Misc" = {
|
||||||
youtube-dl-list = shellJoin [
|
youtube-dl-list = shellJoin [
|
||||||
"${youtube-dl}/bin/youtube-dl"
|
"${yt-dlp}/bin/yt-dlp"
|
||||||
"-f \"bestvideo[ext=mp4]+bestaudio[e=m4a]/bestvideo+bestaudio\""
|
"-f \"bestvideo[ext=mp4]+bestaudio[e=m4a]/bestvideo+bestaudio\""
|
||||||
"-o \"%(playlist_index)s-%(title)s.%(ext)s\""
|
"-o \"%(playlist_index)s-%(title)s.%(ext)s\""
|
||||||
];
|
];
|
||||||
|
|
||||||
music-dl = "${youtube-dl}/bin/youtube-dl --extract-audio -f \"bestaudio[ext=m4a]/best\"";
|
music-dl = "${yt-dlp}/bin/yt-dlp --extract-audio -f \"bestaudio[ext=m4a]/best\"";
|
||||||
music-dl-list = shellJoin [
|
music-dl-list = shellJoin [
|
||||||
"${youtube-dl}/bin/youtube-dl"
|
"${yt-dlp}/bin/yt-dlp"
|
||||||
"--extract-audio"
|
"--extract-audio"
|
||||||
"-f \"bestaudio[ext=m4a]/best\""
|
"-f \"bestaudio[ext=m4a]/best\""
|
||||||
"-o \"%(playlist_index)s-%(title)s.%(ext)s\""
|
"-o \"%(playlist_index)s-%(title)s.%(ext)s\""
|
||||||
|
@ -273,8 +270,12 @@ in rec {
|
||||||
|
|
||||||
"Generated" = {
|
"Generated" = {
|
||||||
"cds" = let
|
"cds" = let
|
||||||
inherit (lib.strings) concatStringsSep repeatString;
|
inherit (lib.strings) concatStringsSep;
|
||||||
inherit (lib.lists) range flatten repeat;
|
inherit (extendedLib.strings) repeatString;
|
||||||
|
|
||||||
|
inherit (lib.lists) range flatten;
|
||||||
|
inherit (extendedLib.lists) repeat;
|
||||||
|
|
||||||
inherit (lib.attrsets) nameValuePair listToAttrs;
|
inherit (lib.attrsets) nameValuePair listToAttrs;
|
||||||
|
|
||||||
nthCds = n: [
|
nthCds = n: [
|
||||||
|
@ -336,7 +337,8 @@ in rec {
|
||||||
};
|
};
|
||||||
|
|
||||||
flattened.aliases = let
|
flattened.aliases = let
|
||||||
inherit (lib.attrsets) mapAttrs attrValues filterAttrs isAttrs concatAttrs;
|
inherit (lib.attrsets) mapAttrs attrValues filterAttrs isAttrs;
|
||||||
|
inherit (extendedLib.attrsets) concatAttrs;
|
||||||
inherit (lib.strings) isString concatStringsSep;
|
inherit (lib.strings) isString concatStringsSep;
|
||||||
|
|
||||||
applyFunctor = attrset: functors.${attrset.type}.apply attrset;
|
applyFunctor = attrset: functors.${attrset.type}.apply attrset;
|
||||||
|
@ -369,11 +371,12 @@ in rec {
|
||||||
xdg.dataFile = {
|
xdg.dataFile = {
|
||||||
aliases = {
|
aliases = {
|
||||||
text = let
|
text = let
|
||||||
inherit (lib.strings) unlines wrap' replaceStrings' stringLength repeatString;
|
inherit (lib.strings) stringLength;
|
||||||
|
inherit (extendedLib.strings) unlines wrap' replaceStrings' repeatString;
|
||||||
inherit (lib.attrsets) attrValues mapAttrs isAttrs;
|
inherit (lib.attrsets) attrValues mapAttrs isAttrs;
|
||||||
inherit (lib.lists) remove;
|
inherit (lib.lists) remove;
|
||||||
inherit (lib.trivial) mapNullable;
|
inherit (lib.trivial) mapNullable;
|
||||||
inherit (lib.termColors.front) red green blue;
|
inherit (extendedLib.termColors.front) red green blue;
|
||||||
|
|
||||||
# int -> String -> AttrSet -> String
|
# int -> String -> AttrSet -> String
|
||||||
stringifyCategory = level: name: category:
|
stringifyCategory = level: name: category:
|
||||||
|
@ -409,8 +412,8 @@ in rec {
|
||||||
packageManagerLecture = {
|
packageManagerLecture = {
|
||||||
target = "package-manager.lecture";
|
target = "package-manager.lecture";
|
||||||
text = let
|
text = let
|
||||||
inherit (lib.strings) unlines;
|
inherit (extendedLib.strings) unlines;
|
||||||
inherit (lib.termColors.front) red blue;
|
inherit (extendedLib.termColors.front) red blue;
|
||||||
in unlines [
|
in unlines [
|
||||||
((red "This package manager is not installed on ") + (blue "NixOS") + (red "."))
|
((red "This package manager is not installed on ") + (blue "NixOS") + (red "."))
|
||||||
((red "Either use ") + ("\"nix-env -i\"") + (red " or install it through a configuration file."))
|
((red "Either use ") + ("\"nix-env -i\"") + (red " or install it through a configuration file."))
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
{ pkgs, unstable-pkgs, config, inputs, secrets, ... }:
|
{ pkgs, unstable-pkgs, lib, extendedLib, config, inputs, secrets, ... }:
|
||||||
let
|
let
|
||||||
inherit (pkgs) lib;
|
|
||||||
# inherit (specialArgs) machineVars;
|
# inherit (specialArgs) machineVars;
|
||||||
inherit (config) machineVars;
|
inherit (config) machineVars;
|
||||||
# has_graphics = !config.machineVars.headless;
|
# has_graphics = !config.machineVars.headless;
|
||||||
|
@ -130,7 +129,7 @@ in {
|
||||||
# TODO: move this out of etc, and reference it directly in sudo config.
|
# TODO: move this out of etc, and reference it directly in sudo config.
|
||||||
sudoLecture = {
|
sudoLecture = {
|
||||||
target = "sudo.lecture";
|
target = "sudo.lecture";
|
||||||
text = lib.termColors.front.red "Be careful or something, idk...\n";
|
text = extendedLib.termColors.front.red "Be careful or something, idk...\n";
|
||||||
};
|
};
|
||||||
|
|
||||||
"resolv.conf".source = let
|
"resolv.conf".source = let
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
final: prev:
|
{ stdlib }:
|
||||||
let
|
let
|
||||||
inherit (prev.lib.attrsets) mapAttrs isAttrs filterAttrs listToAttrs nameValuePair attrNames mapAttrsToList;
|
inherit (stdlib.attrsets) mapAttrs isAttrs filterAttrs listToAttrs nameValuePair attrNames mapAttrsToList;
|
||||||
inherit (prev.lib.lists) foldr imap0 imap1;
|
inherit (stdlib.lists) foldr imap0 imap1;
|
||||||
in prev.lib.attrsets // rec {
|
in rec {
|
||||||
# a -> [String] -> AttrSet{a}
|
# a -> [String] -> AttrSet{a}
|
||||||
mapToAttrsWithConst = constant: items:
|
mapToAttrsWithConst = constant: items:
|
||||||
listToAttrs (map (name: nameValuePair name constant) items);
|
listToAttrs (map (name: nameValuePair name constant) items);
|
|
@ -0,0 +1,8 @@
|
||||||
|
{ stdlib }:
|
||||||
|
rec {
|
||||||
|
attrsets = import ./attrsets.nix { inherit stdlib; };
|
||||||
|
lists = import ./lists.nix { inherit stdlib; };
|
||||||
|
strings = import ./strings.nix { inherit stdlib lists; };
|
||||||
|
termColors = import ./termColors.nix { inherit stdlib strings; };
|
||||||
|
trivial = import ./trivial.nix { inherit stdlib; };
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
final: prev:
|
{ stdlib }:
|
||||||
let
|
let
|
||||||
inherit (prev.lib.trivial) const;
|
inherit (stdlib.trivial) const;
|
||||||
inherit (prev.lib.lists) range any all;
|
inherit (stdlib.lists) range any all;
|
||||||
in prev.lib.lists // {
|
in {
|
||||||
# a -> Int -> [a]
|
# a -> Int -> [a]
|
||||||
repeat = item: times: map (const item) (range 1 times);
|
repeat = item: times: map (const item) (range 1 times);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
final: prev:
|
{ stdlib, lists }:
|
||||||
let
|
let
|
||||||
inherit (final.lib.lists) repeat length;
|
inherit (stdlib.lists) length;
|
||||||
inherit (prev.lib.strings) concatStringsSep replaceStrings splitString;
|
inherit (lists) repeat;
|
||||||
# inherit (final.lib.strings) wrap;
|
inherit (stdlib.strings) concatStringsSep replaceStrings splitString;
|
||||||
in prev.lib.strings // rec {
|
in rec {
|
||||||
# String -> [String]
|
# String -> [String]
|
||||||
lines = splitString "\n";
|
lines = splitString "\n";
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
final: prev:
|
{ stdlib, strings }:
|
||||||
let
|
let
|
||||||
inherit (final.lib.strings) wrap;
|
inherit (strings) wrap;
|
||||||
inherit (prev.lib.attrsets) mapAttrs' nameValuePair;
|
inherit (stdlib.attrsets) mapAttrs' nameValuePair;
|
||||||
# inherit (final.lib.myStuff.termColors) escapeCharacter escapeColor resetCharacter wrapWithColor' colorMappings;
|
|
||||||
in rec {
|
in rec {
|
||||||
# String
|
# String
|
||||||
escapeCharacter = "";
|
escapeCharacter = "";
|
|
@ -1,6 +1,5 @@
|
||||||
final: prev:
|
{ stdlib }:
|
||||||
let
|
{
|
||||||
in prev.lib.trivial // {
|
|
||||||
# a -> b -> Either (a b)
|
# a -> b -> Either (a b)
|
||||||
withDefault = default: value:
|
withDefault = default: value:
|
||||||
if (value == null) then default else value;
|
if (value == null) then default else value;
|
|
@ -1,6 +1,5 @@
|
||||||
{ pkgs, config, ... }:
|
{ lib, config, ... }:
|
||||||
let
|
let
|
||||||
inherit (pkgs) lib;
|
|
||||||
inherit (lib) types mkEnableOption mkOption mkIf;
|
inherit (lib) types mkEnableOption mkOption mkIf;
|
||||||
cfg = config.machineVars;
|
cfg = config.machineVars;
|
||||||
in {
|
in {
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
final: prev:
|
|
||||||
{
|
|
||||||
lib = prev.lib // {
|
|
||||||
attrsets = (import ./attrsets.nix) final prev;
|
|
||||||
lists = (import ./lists.nix) final prev;
|
|
||||||
strings = (import ./strings.nix) final prev;
|
|
||||||
termColors = (import ./termColors.nix) final prev;
|
|
||||||
trivial = (import ./trivial.nix) final prev;
|
|
||||||
};
|
|
||||||
}
|
|
Loading…
Reference in New Issue