Squash some bugs that kept nix from building

master
Oystein Kristoffer Tveit 2021-12-15 03:24:21 +01:00
parent fed4c28152
commit bc1cfdfeaf
4 changed files with 84 additions and 94 deletions

View File

@ -47,10 +47,13 @@ in
stateVersion = "21.05";
username = "h7x4";
homeDirectory = "/home/h7x4";
# enableNixpkgsReleaseCheck = true;
};
news.display = "silent";
fonts.fontconfig.enable = true;
programs = {
home-manager.enable = true;
@ -58,37 +61,30 @@ in
bottom.enable = true;
exa.enable = true;
feh.enable = true;
fzf = {
enable = true;
defaultCommand = "fd --type f";
};
gpg.enable = true;
irssi.enable = true;
kakoune.enable = true;
lazygit.enable = true;
mpv.enable = true;
ssh.enable = true;
man = {
enable = true;
generateCaches = true;
};
mpv.enable = true;
obs-studio.enable = true;
ssh.enable = true;
skim = {
enable = true;
defaultCommand ="fd --type f";
};
texlive = {
enable = true;
# packageSet = pkgs.texlive.combined.scheme-medium;
};
# xmobar.enable = true;
zoxide.enable = true;
};
@ -129,6 +125,8 @@ in
};
};
xdg.enable = true;
xsession = {
pointerCursor = {
package = pkgs.capitaine-cursors;

View File

@ -11,7 +11,7 @@ in super.lib.strings // rec {
concatStringsSep splitter (map f (splitString splitter string));
# (String -> String) -> String -> String
mapLines = splitMap "\n"
mapLines = splitMap "\n";
# String -> Int -> String
repeatString = string: times: concatStringsSep "" (repeat string times);

View File

@ -1,5 +1,10 @@
{ lib, ... }:
{ ... }:
let
# TODO: Fix overlay in home.nix
pkgs = import <nixos> { overlays = [(import ../../../overlays/lib)]; };
lib = pkgs.lib;
users = import ./users.nix;
inherit (users.pvv) normalUser adminUser;
@ -33,68 +38,60 @@ let
[ "innovation" "pvv-minecraft" ]
];
# Either( String [String] AttrSet{String} ) -> AttrSet{String}
normalizeValueType = let
inherit (lib.strings) isString concatStringsSep;
inherit (lib.strings) isString;
inherit (lib.lists) isList;
inherit (lib.attrsets) filterAttrs;
in
machine:
if (isString machine) then (normalizeValueType [machine])
else if (isList machine) then (normalizeValueType { names = machine; })
else ({ name = concatStringsSep " " machine.names; } // (removeAttrs machine ["names"]));
if (isString machine) then { names = [machine]; }
else if (isList machine) then { names = machine; }
else machine;
# TODO: Merge the following two functions. They have too much code in common.
convertNormalMachines = let
inherit (lib.trivial) pipe;
inherit (lib.attrsets) listToAttrs;
# [String] -> AttrSet
machineWithNames = let
inherit (lib.lists) head;
inherit (lib.strings) split;
in
names: { hostname = "${head names}.pvv.org"; };
convertNormalMachine = normalizedMachine:
rec {
inherit (normalizedMachine) name;
value = ({
hostname = "${head (split " " name)}.pvv.org";
user = normalUser;
} // removeAttrs normalizedMachine ["name"]);
};
# AttrSet -> AttrSet -> AttrSet
convertMachineWithDefaults = defaults: normalizedMachine: let
inherit (lib.attrsets) nameValuePair;
inherit (lib.strings) concatStringsSep;
inherit (normalizedMachine) names;
pipeline = [
(ms: map normalizeValueType ms)
(ms: map convertNormalMachine ms)
listToAttrs
];
in machines: pipe machines pipeline;
name = concatStringsSep " " names;
value =
(machineWithNames names)
// defaults
// removeAttrs normalizedMachine ["names"];
in
nameValuePair name value;
convertAdminMachines = let
inherit (lib.trivial) pipe;
# AttrSet -> AttrSet
convertNormalMachine = convertMachineWithDefaults { user = normalUser; };
# AttrSet -> AttrSet
convertAdminMachine =
convertMachineWithDefaults { user = adminUser; proxyJump = "hildring"; };
# [ Either(String [String] AttrSet{String}) ] -> (AttrSet -> AttrSet) -> AttrSet
convertMachinesWith = convertMachineFunction: let
inherit (lib.attrsets) listToAttrs;
inherit (lib.lists) head;
inherit (lib.strings) split;
convertAdminMachine = normalizedMachine:
rec {
inherit (normalizedMachine) name;
value = ({
hostname = "${head (split " " name)}.pvv.org";
user = adminUser;
proxyJump = "hildring";
} // removeAttrs normalizedMachine ["name"]);
};
inherit (lib.trivial) pipe;
pipeline = [
(ms: map normalizeValueType ms)
(ms: map convertAdminMachine ms)
(map normalizeValueType)
(map convertMachineFunction)
listToAttrs
];
in machines: pipe machines pipeline;
in
machines: pipe machines pipeline;
in
{
programs.ssh.matchBlocks = let
concatSets = lib.lists.foldl (s1: s2: s1 // s2) {};
in concatSets [
(convertNormalMachines normalMachines)
(convertAdminMachines rootMachines)
programs.ssh.matchBlocks = lib.attrsets.concatAttrs [
(convertMachinesWith convertNormalMachine normalMachines)
(convertMachinesWith convertAdminMachine rootMachines)
];
}

View File

@ -20,22 +20,17 @@ let
functors = let
inherit (lib.strings) concatStringsSep;
inherit (lib.termColors.front) blue;
genWrapper = type: value: { inherit type; inherit value; };
in {
shellPipe = {
wrap = s: {
type = "shellPipe";
value = s;
};
wrap = genWrapper "shellPipe";
apply = f: concatStringsSep " | " f.value;
stringify = f: concatStringsSep (blue "\n| ") f.value;
};
join = {
wrap = s: {
type = "join";
value = s;
};
wrap = genWrapper "join";
apply = f: concatStringsSep " " f.value;
stringify = f: concatStringsSep " \\\n " f.value;
stringify = f: concatStringsSep " \\\n " f.value;
};
};
@ -104,7 +99,7 @@ in rec {
"Reminders" = {
regex-escapechars = "echo \"[\\^$.|?*+()\"";
aliases = "${coreutils}/bin/cat $HOME/${home.file.aliases.target}";
aliases = "${coreutils}/bin/cat $HOME/${config.xdg.dataFile.aliases.target}";
};
# ░█▀█░▀█▀░█░█
@ -257,27 +252,28 @@ in rec {
allCdNameValuePairs = flatten (map nthCdsAsNameValuePairs (range 1 9));
in
listToAttrs allCdNameValuePairs;
"Package Managers" = let
inherit (lib.attrsets) nameValuePair listToAttrs;
packageManagers = [
"apt"
"dpkg"
"flatpak"
"pacman"
"pamac"
"paru"
"rpm"
"snap"
"xbps"
"yay"
"yum"
];
command = "${coreutils}/bin/cat $HOME/${config.xdg.dataFile.packageManagerLecture.target}";
nameValuePairs = map (pm: nameValuePair pm command) packageManagers;
in listToAttrs nameValuePairs;
};
"Package Managers" = let
inherit (lib.attrsets) nameValuePair listToAttrs;
packageManagers = [
"apt"
"dpkg"
"flatpak"
"pacman"
"pamac"
"paru"
"rpm"
"snap"
"xbps"
"yay"
"yum"
];
command = "${coreutils}/bin/cat $HOME/${config.home.file.packageManagerLecture.target}";
nameValuePairs = map (pm: nameValuePair pm command) packageManagers;
in listToAttrs nameValuePairs;
};
# TODO: flatten functions
@ -332,9 +328,8 @@ in rec {
allAttrValuesAreStrings _module.args.shellOptions.aliases;
};
home.file = {
xdg.dataFile = {
aliases = {
target = ".local/share/aliases";
text = let
inherit (lib.strings) unlines wrap' replaceStrings' stringLength repeatString;
inherit (lib.attrsets) attrValues mapAttrs isAttrs;
@ -360,7 +355,7 @@ in rec {
applyFunctor = attrset: let
applied = functors.${attrset.type}.stringify attrset;
indent' = "${indent} ${repeatString " " (stringLength n)}";
indent' = indent + (repeatString " " ((stringLength " ->") + (stringLength n)));
in replaceStrings' ["\n"] ("\n" + indent') applied;
recurse = stringifyCategory (level + 1) n v;
@ -370,15 +365,15 @@ in rec {
recurse) category)));
in
(stringifyCategory 0 "Aliases" _module.args.shellOptions.aliases) + "\n";
};
packageManagerLecture = {
target = ".local/share/package-manager.lecture";
};
packageManagerLecture = {
target = "package-manager.lecture";
text = let
inherit (lib.strings) unlines;
inherit (lib.termColors.front) red blue;
in unlines [
((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."))
""
];
};