Refactor: move out the overlay and lib

This commit is contained in:
Alexander Bantyev 2021-12-23 21:23:03 +03:00
parent 4727076483
commit 1adb2c16dd
Signed by: balsoft
GPG Key ID: E081FF12ADCB4AD5
15 changed files with 223 additions and 209 deletions

View File

@ -64,7 +64,7 @@
flake = false;
};
mtxclient ={
mtxclient = {
url = "github:nheko-reborn/mtxclient";
flake = false;
};
@ -90,17 +90,24 @@
findModules = dir:
builtins.concatLists (builtins.attrValues (builtins.mapAttrs
(name: type:
if type == "regular" then
[{
if type == "regular" then [{
name = builtins.elemAt (builtins.match "(.*)\\.nix" name) 0;
value = dir + "/${name}";
}]
else if (builtins.readDir (dir + "/${name}"))
}] else if (builtins.readDir (dir + "/${name}"))
? "default.nix" then [{
inherit name;
value = dir + "/${name}";
}] else
findModules (dir + "/${name}")) (builtins.readDir dir)));
pkgsFor = system:
import inputs.nixpkgs {
overlays = [ (import inputs.emacs-overlay) self.overlay ];
localSystem = { inherit system; };
config = {
allowUnfree = true;
android_sdk.accept_license = true;
};
};
in {
nixosModules = builtins.listToAttrs (findModules ./modules);
@ -111,20 +118,30 @@
nixosConfigurations = with nixpkgs.lib;
let
hosts = builtins.attrNames (builtins.readDir ./machines);
mkHost = name:
nixosSystem {
let
system = builtins.readFile (./machines + "/${name}/system");
modules =
[ (import (./machines + "/${name}")) { device = name; } ];
pkgs = pkgsFor system;
in nixosSystem {
inherit system;
modules = [
(import (./machines + "/${name}"))
{ nixpkgs.pkgs = pkgs; }
{ device = name; }
];
specialArgs = { inherit inputs; };
};
in genAttrs hosts mkHost;
legacyPackages.x86_64-linux =
(builtins.head (builtins.attrValues self.nixosConfigurations)).pkgs;
legacyPackages.x86_64-linux = pkgsFor "x86_64-linux";
defaultApp = deploy-rs.defaultApp;
overlay = import ./overlay.nix inputs;
lib = import ./lib.nix nixpkgs.lib;
devShell.x86_64-linux = with nixpkgs.legacyPackages.x86_64-linux;
mkShell {
buildInputs = [
@ -137,13 +154,16 @@
deploy = {
user = "root";
nodes = (builtins.mapAttrs (name: machine:
let activateable = name == "T420-Laptop" || name == "RasPi-Server"; in {
let activateable = name == "T420-Laptop" || name == "RasPi-Server";
in {
hostname = machine.config.networking.hostName;
profiles.system = {
user = if activateable then "root" else "balsoft";
path = with deploy-rs.lib.${machine.pkgs.system}.activate; if activateable
then nixos machine
else noop machine.config.system.build.toplevel;
path = with deploy-rs.lib.${machine.pkgs.system}.activate;
if activateable then
nixos machine
else
noop machine.config.system.build.toplevel;
};
}) self.nixosConfigurations);
};

61
lib.nix Normal file
View File

@ -0,0 +1,61 @@
lib: rec {
mkKeyValue = key: value:
let
mvalue = if builtins.isBool value then
(if value then "true" else "false")
else if builtins.isString value then
value
else
builtins.toString value;
in "${key}=${mvalue}";
attrsToList = with builtins;
x:
(map (key: {
name = key;
value = getAttr key x;
}) (attrNames x));
genIni = lib.generators.toINI { inherit mkKeyValue; };
genIniOrdered = lst:
(builtins.concatStringsSep "\n" (map ({ name ? "widget", ... }@attrs:
builtins.concatStringsSep "\n" ([ "[${name}]" ]
++ (map ({ name, value }: mkKeyValue name value)
(attrsToList (builtins.removeAttrs attrs [ "name" ]))))) lst)) + "\n";
splitHex = hexStr:
map (x: builtins.elemAt x 0)
(builtins.filter (a: a != "" && a != [ ]) (builtins.split "(.{2})" hexStr));
hex2decDigits = rec {
"0" = 0;
"1" = 1;
"2" = 2;
"3" = 3;
"4" = 4;
"5" = 5;
"6" = 6;
"7" = 7;
"8" = 8;
"9" = 9;
"a" = 10;
"b" = 11;
"c" = 12;
"d" = 13;
"e" = 14;
"f" = 15;
A = a;
B = b;
C = c;
D = d;
E = e;
F = f;
};
doubleDigitHexToDec = hex:
16 * hex2decDigits."${builtins.substring 0 1 hex}"
+ hex2decDigits."${builtins.substring 1 2 hex}";
thmDec = builtins.mapAttrs (name: color: colorHex2Dec color);
thmHash = builtins.mapAttrs (name: color: "#${color}");
colorHex2Dec = color:
builtins.concatStringsSep ","
(map (x: toString (doubleDigitHexToDec x)) (splitHex color));
}

104
overlay.nix Normal file
View File

@ -0,0 +1,104 @@
inputs: final: prev:
let
old =
import inputs.nixpkgs-old ({ localSystem = { inherit (final) system; }; });
inherit (final) system lib;
in rec {
my-lib = import ./lib.nix lib;
nur = (import inputs.NUR {
pkgs = old;
nurpkgs = final;
}).repos;
mopidy-ytmusic = with final;
python3Packages.buildPythonApplication rec {
pname = "mopidy-ytmusic";
version = "3.2";
src = inputs.mopidy-ytmusic;
propagatedBuildInputs = [
mopidy
(python3Packages.ytmusicapi.overrideAttrs (oa: rec {
name = "python3.9-ytmusicapi-${version}";
version = "0.19.1";
src = fetchFromGitHub {
owner = "sigma67";
repo = "ytmusicapi";
rev = "fd9f57750de103202106f02be1696bd440f2c05b";
sha256 = "/NMy2cGe0K/14OZd+/dXKA6Ez1ivrtrZ6Lwl0P8dioA=";
fetchSubmodules = true;
};
}))
(python3Packages.pytube.overrideAttrs (oa: rec {
name = "python3.9-pytube-${version}";
version = "11.0.1";
src = fetchFromGitHub {
owner = "pytube";
repo = "pytube";
rev = "f06e0710dcf5089e582487fee94f7bb0afbf7ba9";
sha256 = "sha256-yQCgrnoPOSdTnTPEsVkgLYpPLiHq7kXRUO72TxD152k=";
fetchSubmodules = true;
};
}))
];
doCheck = false;
};
inherit (nur.balsoft.pkgs) termNote nix-patch;
lambda-launcher = inputs.lambda-launcher.defaultPackage.${system};
simple-osd = inputs.simple-osd-daemons.packages.${system};
nerdfonts = nur.balsoft.pkgs.roboto-mono-nerd;
pass-secret-service =
prev.pass-secret-service.overrideAttrs (_: { installCheckPhase = null; });
nix-direnv = inputs.nix-direnv.defaultPackage.${system};
coeurl = final.stdenv.mkDerivation {
name = "coeurl";
src = inputs.coeurl;
buildInputs = [ final.curl.all final.libevent final.spdlog ];
nativeBuildInputs = [ final.meson final.ninja final.pkg-config final.cmake ];
};
mtxclient = prev.mtxclient.overrideAttrs (oa: {
src = inputs.mtxclient;
cmakeFlags = oa.cmakeFlags ++ [ "-DCMAKE_CXX_FLAGS=-DSPDLOG_FMT_EXTERNAL" ];
buildInputs = oa.buildInputs
++ [ final.libevent final.curl.all final.coeurl final.spdlog.dev ];
patches = [ ];
});
nheko = (prev.nheko.overrideAttrs (oa: {
src = inputs.nheko;
postPatch = ''
substituteInPlace CMakeLists.txt --replace "# Fixup bundled keychain include dirs" "find_package(Boost COMPONENTS iostreams system thread REQUIRED)"
'';
buildInputs = oa.buildInputs ++ [
final.xorg.libXdmcp
final.pcre
final.libunwind
final.elfutils
final.coeurl
final.curl
final.libevent
final.asciidoc
];
cmakeFlags = oa.cmakeFlags ++ [ "-DBUILD_SHARED_LIBS=OFF" ];
})).override { mtxclient = final.mtxclient; };
nix = inputs.nix.defaultPackage.${system}.overrideAttrs
(oa: { patches = [ ./profiles/nix/nix.patch ] ++ oa.patches or [ ]; });
mako = prev.mako.overrideAttrs (_: {
postInstall =
"sed 's/Exec=.*//' -i $out/share/dbus-1/services/fr.emersion.mako.service";
});
}

View File

@ -22,7 +22,7 @@
cursor.style = "Beam";
colors = with pkgs.my-lib.thmHash; {
colors = with pkgs.my-lib.thmHash config.themes.colors; {
primary = {
background = base00;
foreground = base05;

View File

@ -95,6 +95,6 @@ in {
xdg.configFile."emacs/init.el".source = pkgs.substituteAll ({
src = ./init.el;
font = with config.themes.fonts; "${mono.family} ${toString mono.size}";
} // pkgs.my-lib.thmHash);
} // pkgs.my-lib.thmHash config.themes.colors);
};
}

View File

@ -1,6 +1,6 @@
{ config, pkgs, lib, ... }:
let
thm = pkgs.my-lib.thmHash;
thm = pkgs.my-lib.thmHash config.themes.colors;
fonts = config.themes.fonts;
in {
environment.sessionVariables = {

View File

@ -62,15 +62,18 @@ in {
desktop = "org.gnome.Geary";
};
home-manager.users.balsoft = {
home-manager.users.balsoft = let
fonts = config.themes.fonts;
thm = pkgs.my-lib.thmHash config.themes.colors;
in {
xdg.configFile."geary/user-style.css".text = ''
*, html, body, body.plain div, body.plain a, body.plain p, body.plain span {
background: ${pkgs.my-lib.thmHash.base00} !important;
color: ${pkgs.my-lib.thmHash.base05} !important;
font-family: '${config.themes.fonts.mono.family}', monospace !important;
background: ${thm.base00} !important;
color: ${thm.base05} !important;
font-family: '${fonts.mono.family}', monospace !important;
}
*, html, body {
font-size: ${toString config.themes.fonts.mono.size}pt;
font-size: ${toString fonts.mono.size}pt;
}
'';
home.activation.geary = ''

View File

@ -4,7 +4,6 @@
# Internet
wget
curl
unrar
neochat
exa
@ -23,7 +22,6 @@
pavucontrol
# Tools
zip
unrar
plasma-systemmonitor
wl-clipboard
grim

View File

@ -1,173 +0,0 @@
{ pkgs, config, lib, inputs, ... }:
let
filterGit =
builtins.filterSource (type: name: name != ".git" || type != "directory");
inherit (pkgs) system;
old = import inputs.nixpkgs-old ({
config = config.nixpkgs.config;
localSystem = { inherit system; };
});
mkKeyValue = key: value:
let
mvalue = if builtins.isBool value then
(if value then "true" else "false")
else if builtins.isString value then
value
else
builtins.toString value;
in ''${key}=${mvalue}'';
attrsToList = with builtins;
x:
(map (key: {
name = key;
value = getAttr key x;
}) (attrNames x));
in {
nixpkgs.overlays = [
(import inputs.emacs-overlay)
(self: super: rec {
my-lib = rec {
genIni = lib.generators.toINI { inherit mkKeyValue; };
genIniOrdered = lst:
(builtins.concatStringsSep "\n" (map ({ name ? "widget", ... }@attrs:
builtins.concatStringsSep "\n" ([ "[${name}]" ]
++ (map ({ name, value }: mkKeyValue name value)
(attrsToList (builtins.removeAttrs attrs [ "name" ]))))) lst))
+ "\n";
thm = config.themes.colors;
splitHex = hexStr:
map (x: builtins.elemAt x 0) (builtins.filter (a: a != "" && a != [ ])
(builtins.split "(.{2})" hexStr));
hex2decDigits = rec {
"0" = 0;
"1" = 1;
"2" = 2;
"3" = 3;
"4" = 4;
"5" = 5;
"6" = 6;
"7" = 7;
"8" = 8;
"9" = 9;
"a" = 10;
"b" = 11;
"c" = 12;
"d" = 13;
"e" = 14;
"f" = 15;
A = a;
B = b;
C = c;
D = d;
E = e;
F = f;
};
doubleDigitHexToDec = hex:
16 * hex2decDigits."${builtins.substring 0 1 hex}"
+ hex2decDigits."${builtins.substring 1 2 hex}";
thmDec = builtins.mapAttrs (name: color: colorHex2Dec color) thm;
thmHash = builtins.mapAttrs (name: color: "#${color}") thm;
colorHex2Dec = color:
builtins.concatStringsSep ","
(map (x: toString (doubleDigitHexToDec x)) (splitHex color));
};
nur = (import inputs.NUR {
pkgs = old;
nurpkgs = pkgs;
}).repos;
mopidy-ytmusic = with pkgs;
python3Packages.buildPythonApplication rec {
pname = "mopidy-ytmusic";
version = "3.2";
src = inputs.mopidy-ytmusic;
propagatedBuildInputs = [
mopidy
(python3Packages.ytmusicapi.overrideAttrs (oa: rec {
name = "python3.9-ytmusicapi-${version}";
version = "0.19.1";
src = fetchFromGitHub {
owner = "sigma67";
repo = "ytmusicapi";
rev = "fd9f57750de103202106f02be1696bd440f2c05b";
sha256 = "/NMy2cGe0K/14OZd+/dXKA6Ez1ivrtrZ6Lwl0P8dioA=";
fetchSubmodules = true;
};
}))
(python3Packages.pytube.overrideAttrs (oa: rec {
name = "python3.9-pytube-${version}";
version = "11.0.1";
src = fetchFromGitHub {
owner = "pytube";
repo = "pytube";
rev = "f06e0710dcf5089e582487fee94f7bb0afbf7ba9";
sha256 = "sha256-yQCgrnoPOSdTnTPEsVkgLYpPLiHq7kXRUO72TxD152k=";
fetchSubmodules = true;
};
}))
];
doCheck = false;
};
inherit (nur.balsoft.pkgs) termNote nix-patch;
lambda-launcher = inputs.lambda-launcher.defaultPackage.${system};
simple-osd = inputs.simple-osd-daemons.packages.${system};
nerdfonts = nur.balsoft.pkgs.roboto-mono-nerd;
pass-secret-service = super.pass-secret-service.overrideAttrs (_: { installCheckPhase = null; });
nix-direnv = inputs.nix-direnv.defaultPackage.${system};
coeurl = self.stdenv.mkDerivation {
name = "coeurl";
src = inputs.coeurl;
buildInputs = [ self.curl.all self.libevent self.spdlog ];
nativeBuildInputs = [ self.meson self.ninja self.pkg-config self.cmake ];
};
mtxclient = super.mtxclient.overrideAttrs (oa: {
src = inputs.mtxclient;
cmakeFlags = oa.cmakeFlags ++ [ "-DCMAKE_CXX_FLAGS=-DSPDLOG_FMT_EXTERNAL" ];
buildInputs = oa.buildInputs ++ [ self.libevent self.curl.all self.coeurl self.spdlog.dev ];
patches = [];
});
nheko = (super.nheko.overrideAttrs (oa: {
src = inputs.nheko;
postPatch = ''
substituteInPlace CMakeLists.txt --replace "# Fixup bundled keychain include dirs" "find_package(Boost COMPONENTS iostreams system thread REQUIRED)"
'';
buildInputs = oa.buildInputs ++ [
self.xorg.libXdmcp
self.pcre
self.libunwind
self.elfutils
self.coeurl
self.curl
self.libevent
self.asciidoc
];
cmakeFlags = oa.cmakeFlags ++ [ "-DBUILD_SHARED_LIBS=OFF" ];
})).override { mtxclient = self.mtxclient; };
nix = inputs.nix.defaultPackage.${pkgs.system}.overrideAttrs (oa: {
patches = [ ./nix/nix.patch ] ++ oa.patches or [ ];
});
})
];
nixpkgs.config = {
allowUnfree = true;
android_sdk.accept_license = true;
};
}

View File

@ -19,7 +19,7 @@ in {
trayOutput = "primary";
command = "true";
colors = let
thm = pkgs.my-lib.thmHash;
thm = pkgs.my-lib.thmHash config.themes.colors;
default = {
background = thm.base00;
border = thm.base00;

View File

@ -21,7 +21,7 @@ with pkgs.my-lib; {
home-manager.users.balsoft = let fonts = config.themes.fonts;
in {
xdg.configFile."kdeglobals".text = with thmDec; lib.generators.toGitINI {
xdg.configFile."kdeglobals".text = with (thmDec config.themes.colors); lib.generators.toGitINI {
"Colors:Button" = {
BackgroundAlternate = base01;
BackgroundNormal = base01;

View File

@ -9,7 +9,7 @@
WantedBy = [ "sway-session.target" ];
};
};
programs.mako = with pkgs.my-lib.thmHash; {
programs.mako = with (pkgs.my-lib.thmHash config.themes.colors); {
enable = true;
layer = "overlay";
font = with config.themes.fonts; "${main.family} ${toString main.size}";

View File

@ -18,6 +18,8 @@
home.stateVersion = "20.09";
};
home-manager.useGlobalPkgs = true;
persist.cache.directories = [ "/home/balsoft/.cache" "/home/balsoft/.local/share/cargo" "/var/cache" ];
persist.state.directories = [ "/var/lib/nixos" "/var/lib/systemd" ];

View File

@ -1,6 +1,6 @@
{ pkgs, lib, config, ... }:
let
thm = pkgs.my-lib.thmHash;
thm = pkgs.my-lib.thmHash config.themes.colors;
apps = config.defaultApplications;
lock_fork =
pkgs.writeShellScript "lock_fork" "sudo /run/current-system/sw/bin/lock &";

View File

@ -21,7 +21,6 @@
misc
network
nix
overlay
security
ssh
zsh