Style: formatting

This commit is contained in:
blahai 2025-01-27 14:03:42 +02:00
parent c6d2a9bf10
commit 70e622f996
Signed by: blahai
SSH key fingerprint: SHA256:ZfCryi+V64yG+vC1ZIIsqgvBCmA31tTi7RJ6M8CvpRc
5 changed files with 314 additions and 322 deletions

View file

@ -1,310 +1,311 @@
{ lib }:
let
{lib}: let
inherit (lib.lists) forEach filter;
inherit (lib.attrsets) filterAttrs mapAttrsToList;
inherit (lib.filesystem) listFilesRecursive;
inherit (lib.strings) hasSuffix;
/**
filter files for the .nix suffix
/*
*
filter files for the .nix suffix
# Arguments
# Arguments
- [k] they key, which is the file name
- [v] the value, which is the type of the file
- [k] they key, which is the file name
- [v] the value, which is the type of the file
# Type
# Type
```
filterNixFiles :: String -> String -> Bool
```
```
filterNixFiles :: String -> String -> Bool
```
# Example
# Example
```nix
filterNixFiles "default.nix" "regular"
=> true
```
```nix
filterNixFiles "default.nix" "regular"
=> true
```
*/
filterNixFiles = k: v: v == "regular" && hasSuffix ".nix" k;
/**
Import all file that filterNixFiles allows for
/*
*
Import all file that filterNixFiles allows for
# Arguments
# Arguments
- [path] the path to the directory
- [path] the path to the directory
# Type
# Type
```
importNixFiles :: String -> List
```
```
importNixFiles :: String -> List
```
# Example
# Example
```nix
importNixFiles ./.
=> [ {...} ]
```
```nix
importNixFiles ./.
=> [ {...} ]
```
*/
importNixFiles =
path:
importNixFiles = path:
(forEach (
mapAttrsToList (name: _: path + ("/" + name)) (filterAttrs filterNixFiles (builtins.readDir path))
))
import;
import;
/**
import all nix files and directories
/*
*
import all nix files and directories
# Arguments
# Arguments
- [dir] the directory to search for nix files
- [dir] the directory to search for nix files
# Type
# Type
```
importNixFilesAndDirs :: String -> List
```
```
importNixFilesAndDirs :: String -> List
```
# Example
# Example
```nix
importNixFilesAndDirs ./.
=> [ "flake.nix" ]
```
```nix
importNixFilesAndDirs ./.
=> [ "flake.nix" ]
```
*/
importNixFilesAndDirs = dir: filter (f: f != "default.nix") (listFilesRecursive dir);
/**
return an int based on boolean value
/*
*
return an int based on boolean value
# Arguments
# Arguments
- [bool] the boolean value
- [bool] the boolean value
# Type
# Type
```
boolToNum :: Bool -> Int
```
```
boolToNum :: Bool -> Int
```
# Example
# Example
```nix
boolToNum true
=> 1
```
```nix
boolToNum true
=> 1
```
*/
boolToNum = bool: if bool then 1 else 0;
boolToNum = bool:
if bool
then 1
else 0;
/**
convert a list of integers to a list of string
/*
*
convert a list of integers to a list of string
# Arguments
# Arguments
- [list] the list of integers
- [list] the list of integers
# Type
# Type
```
intListToStringList :: List -> List
```
```
intListToStringList :: List -> List
```
# Example
# Example
```nix
intListToStringList [1 2 3]
=> ["1" "2" "3"]
```
```nix
intListToStringList [1 2 3]
=> ["1" "2" "3"]
```
*/
intListToStringList = list: map (toString list);
/**
a function that returns the index of an element in a list
/*
*
a function that returns the index of an element in a list
# Arguments
# Arguments
- [list] the list to search in
- [elem] the element to search for
- [list] the list to search in
- [elem] the element to search for
# Type
# Type
```
indexOf :: List -> Any -> Int
```
```
indexOf :: List -> Any -> Int
```
# Example
# Example
```nix
indexOf [1 2 3] 2
=> 1
```
```nix
indexOf [1 2 3] 2
=> 1
```
*/
indexOf =
list: elem:
let
f =
f: i:
if i == (builtins.length list) then
null
else if (builtins.elemAt list i) == elem then
i
else
f f (i + 1);
in
indexOf = list: elem: let
f = f: i:
if i == (builtins.length list)
then null
else if (builtins.elemAt list i) == elem
then i
else f f (i + 1);
in
f f 0;
/**
a function that checks if a list contains a list of given strings
/*
*
a function that checks if a list contains a list of given strings
# Arguments
# Arguments
- [list] the list to search in
- [targetStrings] the list of strings to search for
- [list] the list to search in
- [targetStrings] the list of strings to search for
# Type
# Type
```
containsStrings :: List -> List -> Bool
```
```
containsStrings :: List -> List -> Bool
```
# Example
# Example
```nix
containsStrings ["a" "b" "c"] ["a" "b"]
=> true
```
```nix
containsStrings ["a" "b" "c"] ["a" "b"]
=> true
```
*/
containsStrings =
list: targetStrings: builtins.all (s: builtins.any (x: x == s) list) targetStrings;
containsStrings = list: targetStrings: builtins.all (s: builtins.any (x: x == s) list) targetStrings;
/**
Create git url aliases for a given domain
/*
*
Create git url aliases for a given domain
# Arguments
# Arguments
- [domain] the domain to create the alias for
- [alias] the alias to use
- [user] the user to use, this defaults to "git"
- [port] the port to use, this is optional
- [domain] the domain to create the alias for
- [alias] the alias to use
- [user] the user to use, this defaults to "git"
- [port] the port to use, this is optional
# Type
# Type
```
giturl :: (String -> String -> String -> Int) -> AttrSet
```
```
giturl :: (String -> String -> String -> Int) -> AttrSet
```
# Example
# Example
```nix
giturl { domain = "github.com"; alias = "gh"; }
=> {
"https://github.com/".insteadOf = "gh:";
"ssh://git@github.com/".pushInsteadOf = "gh:";
}
```
```nix
giturl { domain = "github.com"; alias = "gh"; }
=> {
"https://github.com/".insteadOf = "gh:";
"ssh://git@github.com/".pushInsteadOf = "gh:";
}
```
*/
giturl =
{
domain,
alias,
user ? "git",
port ? null,
...
}:
{
"https://${domain}/".insteadOf = "${alias}:";
"ssh://${user}@${domain}${
if (builtins.isNull port) then
""
else if (builtins.isInt port) then
":" + (builtins.toString port)
else
":" + port
}/".pushInsteadOf =
"${alias}:";
giturl = {
domain,
alias,
user ? "git",
port ? null,
...
}: {
"https://${domain}/".insteadOf = "${alias}:";
"ssh://${user}@${domain}${
if (builtins.isNull port)
then ""
else if (builtins.isInt port)
then ":" + (builtins.toString port)
else ":" + port
}/".pushInsteadOf = "${alias}:";
};
/*
*
Create a public key for a given host
# Arguments
- [host] the host to create the public key for
- [key] this is a attrset with the key type and key
# Type
```
mkPub :: (String -> AttrSet -> AttrSet) -> String -> AttrSet -> AttrSet
```
# Example
```nix
mkPub "github.com" {
type = "rsa";
key = "AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==";
}
=> {
"github.com-rsa" = {
hostNames = [ "github.com" ];
publicKey = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==";
};
/**
Create a public key for a given host
# Arguments
- [host] the host to create the public key for
- [key] this is a attrset with the key type and key
# Type
```
mkPub :: (String -> AttrSet -> AttrSet) -> String -> AttrSet -> AttrSet
```
# Example
```nix
mkPub "github.com" {
type = "rsa";
key = "AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==";
}
=> {
"github.com-rsa" = {
hostNames = [ "github.com" ];
publicKey = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==";
};
}
```
}
```
*/
mkPub = host: key: {
"${host}-${key.type}" = {
hostNames = [ host ];
hostNames = [host];
publicKey = "ssh-${key.type} ${key.key}";
};
};
/**
Create public keys for a given host
/*
*
Create public keys for a given host
# Arguments
# Arguments
- [host] the host to create the public keys for
- [keys] the list of keys to create
- [host] the host to create the public keys for
- [keys] the list of keys to create
# Type
# Type
```
mkPubs :: (String -> List) -> String -> List -> AttrSet
```
```
mkPubs :: (String -> List) -> String -> List -> AttrSet
```
# Example
# Example
```nix
mkPubs "github.com" [
{
type = "rsa";
key = "AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==";
}
{
type = "ed25519";
key = "AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl";
}
]
=> {
"github.com-ed25519" = {
hostNames = [ "github.com" ];
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl";
};
"github.com-rsa" = {
hostNames = [ "github.com" ];
publicKey = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==";
};
```nix
mkPubs "github.com" [
{
type = "rsa";
key = "AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==";
}
```
{
type = "ed25519";
key = "AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl";
}
]
=> {
"github.com-ed25519" = {
hostNames = [ "github.com" ];
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl";
};
"github.com-rsa" = {
hostNames = [ "github.com" ];
publicKey = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==";
};
}
```
*/
mkPubs = host: keys: lib.foldl' (acc: key: acc // mkPub host key) { } keys;
in
{
mkPubs = host: keys: lib.foldl' (acc: key: acc // mkPub host key) {} keys;
in {
inherit
mkPub
mkPubs

View file

@ -1,15 +1,13 @@
{ lib }:
let
{lib}: let
inherit (lib.options) mkEnableOption mkPackageOption;
inherit (lib.attrsets) recursiveUpdate;
mkProgram =
pkgs: name: extraConfig:
mkProgram = pkgs: name: extraConfig:
recursiveUpdate {
enable = mkEnableOption "Enable ${name}";
package = mkPackageOption pkgs name { };
} extraConfig;
in
{
package = mkPackageOption pkgs name {};
}
extraConfig;
in {
inherit mkProgram;
}

View file

@ -1,87 +1,85 @@
{ inputs }:
let
{inputs}: let
inherit (inputs) self;
/**
Create secrets for use with `agenix`.
/*
*
Create secrets for use with `agenix`.
# Arguments
# Arguments
- [file] the age file to use for the secret
- [owner] the owner of the secret, this defaults to "root"
- [group] the group of the secret, this defaults to "root"
- [mode] the permissions of the secret, this defaults to "400"
- [file] the age file to use for the secret
- [owner] the owner of the secret, this defaults to "root"
- [group] the group of the secret, this defaults to "root"
- [mode] the permissions of the secret, this defaults to "400"
# Type
# Type
```
mkSecret :: (String -> String -> String -> String) -> AttrSet
```
```
mkSecret :: (String -> String -> String -> String) -> AttrSet
```
# Example
# Example
```nix
mkSecret { file = "./my-secret.age"; }
=> {
file = "./my-secret.age";
owner = "root";
group = "root";
mode = "400";
}
```
```nix
mkSecret { file = "./my-secret.age"; }
=> {
file = "./my-secret.age";
owner = "root";
group = "root";
mode = "400";
}
```
*/
mkSecret =
{
file,
owner ? "root",
group ? "root",
mode ? "400",
...
}:
{
file = "${self}/secrets/${file}.age";
inherit owner group mode;
};
mkSecret = {
file,
owner ? "root",
group ? "root",
mode ? "400",
...
}: {
file = "${self}/secrets/${file}.age";
inherit owner group mode;
};
/**
A light wrapper around mkSecret that allows you to specify the output path
/*
*
A light wrapper around mkSecret that allows you to specify the output path
# Arguments
# Arguments
- [file] the age file to use for the secret
- [owner] the owner of the secret, this defaults to "root"
- [group] the group of the secret, this defaults to "root"
- [mode] the permissions of the secret, this defaults to "400"
- [path] the path to output the secret to
- [file] the age file to use for the secret
- [owner] the owner of the secret, this defaults to "root"
- [group] the group of the secret, this defaults to "root"
- [mode] the permissions of the secret, this defaults to "400"
- [path] the path to output the secret to
# Type
# Type
```
mkSecretWithPath :: (String -> String -> String -> String -> String) -> AttrSet
```
```
mkSecretWithPath :: (String -> String -> String -> String -> String) -> AttrSet
```
# Example
# Example
```nix
mkSecret { file = "./my-secret.age"; path = "/etc/my-secret"; }
=> {
file = "./my-secret.age";
path = "/etc/my-secret";
owner = "root";
group = "root";
mode = "400";
}
```
```nix
mkSecret { file = "./my-secret.age"; path = "/etc/my-secret"; }
=> {
file = "./my-secret.age";
path = "/etc/my-secret";
owner = "root";
group = "root";
mode = "400";
}
```
*/
mkSecretWithPath =
{
file,
path,
owner ? "root",
group ? "root",
mode ? "400",
...
}:
mkSecretWithPath = {
file,
path,
owner ? "root",
group ? "root",
mode ? "400",
...
}:
mkSecret {
inherit
file
@ -93,7 +91,6 @@ let
// {
inherit path;
};
in
{
in {
inherit mkSecret mkSecretWithPath;
}

View file

@ -1,42 +1,40 @@
{ lib }:
let
{lib}: let
inherit (lib.types) str;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.attrsets) recursiveUpdate;
mkGraphicalService = recursiveUpdate {
Unit.PartOf = [ "graphical-session.target" ];
Unit.After = [ "graphical-session.target" ];
Install.WantedBy = [ "graphical-session.target" ];
Unit.PartOf = ["graphical-session.target"];
Unit.After = ["graphical-session.target"];
Install.WantedBy = ["graphical-session.target"];
};
mkHyprlandService = recursiveUpdate {
Unit.PartOf = [ "graphical-session.target" ];
Unit.After = [ "graphical-session.target" ];
Install.WantedBy = [ "hyprland-session.target" ];
Unit.PartOf = ["graphical-session.target"];
Unit.After = ["graphical-session.target"];
Install.WantedBy = ["hyprland-session.target"];
};
/**
A quick way to use my services abstraction
/*
*
A quick way to use my services abstraction
# Arguments
# Arguments
- [name]: The name of the service
- [name]: The name of the service
# Type
# Type
```
mkServiceOption :: String -> (Int -> String -> String -> AttrSet) -> AttrSet
```
```
mkServiceOption :: String -> (Int -> String -> String -> AttrSet) -> AttrSet
```
*/
mkServiceOption =
name:
{
port ? 0,
host ? "127.0.0.1",
domain ? "",
extraConfig ? { },
}:
mkServiceOption = name: {
port ? 0,
host ? "127.0.0.1",
domain ? "",
extraConfig ? {},
}:
{
enable = mkEnableOption "Enable the ${name} service";
@ -59,7 +57,6 @@ let
};
}
// extraConfig;
in
{
in {
inherit mkGraphicalService mkHyprlandService mkServiceOption;
}

View file

@ -6,8 +6,7 @@ let
XDG_STATE_HOME = "$HOME/.local/state";
XDG_BIN_HOME = "$HOME/.local/bin";
XDG_RUNTIME_DIR = "/run/user/$UID";
in
{
in {
# global env
glEnv = {
inherit
@ -18,7 +17,7 @@ in
XDG_BIN_HOME
XDG_RUNTIME_DIR
;
PATH = [ "$XDG_BIN_HOME" ];
PATH = ["$XDG_BIN_HOME"];
};
sysEnv = {