refactor: restructure my custom nix functions
All checks were successful
Discord / discord commits (push) Has been skipped
All checks were successful
Discord / discord commits (push) Has been skipped
This commit is contained in:
parent
dafb2cf8ce
commit
f06b0d9c5b
10 changed files with 94 additions and 69 deletions
|
@ -9,7 +9,7 @@
|
||||||
inherit (config.vars) neovimIde;
|
inherit (config.vars) neovimIde;
|
||||||
inherit (pkgs) vimPlugins;
|
inherit (pkgs) vimPlugins;
|
||||||
|
|
||||||
inherit (import "${self}/lib.nix" {inherit pkgs;}) buildPlugin;
|
inherit (import "${self}/lib" {inherit pkgs;}) buildPlugin;
|
||||||
in
|
in
|
||||||
lib.mkIf neovimIde {
|
lib.mkIf neovimIde {
|
||||||
programs = {
|
programs = {
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
inherit (config.vars) neovimIde;
|
inherit (config.vars) neovimIde;
|
||||||
inherit (pkgs) vimPlugins;
|
inherit (pkgs) vimPlugins;
|
||||||
|
|
||||||
inherit (import "${self}/lib.nix" {inherit pkgs;}) buildPlugin;
|
inherit (import "${self}/lib" {inherit pkgs;}) buildPlugin;
|
||||||
in
|
in
|
||||||
lib.mkIf neovimIde {
|
lib.mkIf neovimIde {
|
||||||
programs = {
|
programs = {
|
||||||
|
|
|
@ -9,7 +9,7 @@ self: {
|
||||||
|
|
||||||
firefox-gx = pkgs.callPackage ./gx-theme.nix {
|
firefox-gx = pkgs.callPackage ./gx-theme.nix {
|
||||||
inherit (self.inputs) firefox-gx-src;
|
inherit (self.inputs) firefox-gx-src;
|
||||||
inherit (import "${self}/lib.nix" {}) mkVersion;
|
inherit (import "${self}/lib" {}) mkVersion;
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
config = {
|
config = {
|
||||||
|
|
35
inputs.nix
35
inputs.nix
|
@ -1,37 +1,6 @@
|
||||||
let
|
let
|
||||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
inherit (import ./lib {}) lib mkDep mkInput mkHyprDep mkSrc;
|
||||||
lib = import "${builtins.fetchTarball {
|
inherit (lib) listToAttrs map removeAttrs;
|
||||||
url = "https://github.com/NixOS/nixpkgs/archive/${lock.nodes.nixpkgs.locked.rev}.tar.gz";
|
|
||||||
sha256 = lock.nodes.nixpkgs.locked.narHash;
|
|
||||||
}}/lib";
|
|
||||||
|
|
||||||
inherit (lib) attrValues findFirst foldl' hasAttr listToAttrs matchAttrs map optionalAttrs recursiveUpdate removeAttrs;
|
|
||||||
|
|
||||||
recursiveUpdateList = list: foldl' recursiveUpdate {} list;
|
|
||||||
|
|
||||||
# Misc functions
|
|
||||||
mkInput = {type ? "github", ...} @ info: let
|
|
||||||
input =
|
|
||||||
findFirst
|
|
||||||
(x: matchAttrs (removeAttrs info ["inputs"]) (x.original or {})) {}
|
|
||||||
(attrValues lock.nodes);
|
|
||||||
|
|
||||||
mkOverride = i:
|
|
||||||
optionalAttrs
|
|
||||||
(hasAttr i (input.inputs or {}))
|
|
||||||
{inputs.${i}.follows = i;};
|
|
||||||
in
|
|
||||||
recursiveUpdateList [
|
|
||||||
info
|
|
||||||
{inherit type;}
|
|
||||||
(mkOverride "systems")
|
|
||||||
(mkOverride "flake-utils")
|
|
||||||
(mkOverride "lib-aggregate")
|
|
||||||
];
|
|
||||||
|
|
||||||
mkDep = info: mkInput (recursiveUpdate info {inputs.nixpkgs.follows = "nixpkgs";});
|
|
||||||
mkHyprDep = info: mkInput (recursiveUpdate info {inputs.hyprland.follows = "hyprland";});
|
|
||||||
mkSrc = info: mkInput (info // {flake = false;});
|
|
||||||
|
|
||||||
# Inputs
|
# Inputs
|
||||||
nixTools = {
|
nixTools = {
|
||||||
|
|
19
lib/default.nix
Normal file
19
lib/default.nix
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
inputs ? {},
|
||||||
|
pkgs ? {},
|
||||||
|
}: let
|
||||||
|
lock = builtins.fromJSON (builtins.readFile ../flake.lock);
|
||||||
|
|
||||||
|
lib = import "${builtins.fetchTarball {
|
||||||
|
url = "https://github.com/NixOS/nixpkgs/archive/${lock.nodes.nixpkgs.locked.rev}.tar.gz";
|
||||||
|
sha256 = lock.nodes.nixpkgs.locked.narHash;
|
||||||
|
}}/lib";
|
||||||
|
|
||||||
|
inherit (lib) optionalAttrs;
|
||||||
|
|
||||||
|
mkVersion = src: "0.0.0+" + src.shortRev;
|
||||||
|
in
|
||||||
|
{inherit lib mkVersion;}
|
||||||
|
// (import ./inputs.nix lib lock)
|
||||||
|
// optionalAttrs (inputs != {}) (import ./flake-lib.nix inputs)
|
||||||
|
// optionalAttrs (pkgs != {}) (import ./pkgs.nix pkgs mkVersion)
|
|
@ -1,32 +1,7 @@
|
||||||
{...} @ inputs: rec {
|
inputs: rec {
|
||||||
mkVersion = src: "0.0.0+" + src.shortRev;
|
# Import pkgs from a nixpkgs instance
|
||||||
|
mkPkgs = system: nixpkgs:
|
||||||
buildPlugin = pname: src:
|
import nixpkgs {
|
||||||
inputs.pkgs.vimUtils.buildVimPlugin {
|
|
||||||
inherit pname src;
|
|
||||||
version = mkVersion src;
|
|
||||||
};
|
|
||||||
|
|
||||||
buildNodeModules = dir: npmDepsHash: let
|
|
||||||
pkg = inputs.pkgs.callPackage ({buildNpmPackage, ...}: let
|
|
||||||
inherit (builtins) readFile fromJSON;
|
|
||||||
|
|
||||||
packageJSON = fromJSON (readFile (dir + /package.json));
|
|
||||||
in
|
|
||||||
buildNpmPackage {
|
|
||||||
pname = packageJSON.name;
|
|
||||||
inherit (packageJSON) version;
|
|
||||||
|
|
||||||
src = dir;
|
|
||||||
|
|
||||||
inherit npmDepsHash;
|
|
||||||
dontNpmBuild = true;
|
|
||||||
}) {};
|
|
||||||
in "${pkg}/lib/node_modules/${pkg.pname}/node_modules";
|
|
||||||
|
|
||||||
# Import pkgs from a nixpkgs
|
|
||||||
mkPkgs = system: input:
|
|
||||||
import input {
|
|
||||||
inherit system;
|
inherit system;
|
||||||
config.allowUnfree = true;
|
config.allowUnfree = true;
|
||||||
overlays =
|
overlays =
|
||||||
|
@ -56,7 +31,7 @@
|
||||||
modules =
|
modules =
|
||||||
[
|
[
|
||||||
{home-manager.extraSpecialArgs = specialArgs;}
|
{home-manager.extraSpecialArgs = specialArgs;}
|
||||||
./common
|
../common
|
||||||
]
|
]
|
||||||
++ mods;
|
++ mods;
|
||||||
};
|
};
|
||||||
|
@ -77,7 +52,7 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
{home-manager = {inherit extraSpecialArgs;};}
|
{home-manager = {inherit extraSpecialArgs;};}
|
||||||
./common/nix-on-droid.nix
|
../common/nix-on-droid.nix
|
||||||
]
|
]
|
||||||
++ mods;
|
++ mods;
|
||||||
};
|
};
|
38
lib/inputs.nix
Normal file
38
lib/inputs.nix
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
lib: lock: let
|
||||||
|
inherit (lib) attrValues findFirst foldl' hasAttr matchAttrs optionalAttrs recursiveUpdate removeAttrs;
|
||||||
|
|
||||||
|
recursiveUpdateList = list: foldl' recursiveUpdate {} list;
|
||||||
|
in rec {
|
||||||
|
/**
|
||||||
|
From an attrset, returns a flake input that has its type defaulted
|
||||||
|
to `github` and has some of its inputs following this flake's input
|
||||||
|
of the same name.
|
||||||
|
|
||||||
|
It gets information from the `flake.lock` file and can be used thanks
|
||||||
|
to flakegen
|
||||||
|
*/
|
||||||
|
mkInput = {type ? "github", ...} @ info: let
|
||||||
|
input =
|
||||||
|
findFirst
|
||||||
|
(x: matchAttrs (removeAttrs info ["inputs"]) (x.original or {})) {}
|
||||||
|
(attrValues lock.nodes);
|
||||||
|
|
||||||
|
mkOverride = i:
|
||||||
|
optionalAttrs
|
||||||
|
(hasAttr i (input.inputs or {}))
|
||||||
|
{inputs.${i}.follows = i;};
|
||||||
|
in
|
||||||
|
recursiveUpdateList [
|
||||||
|
info
|
||||||
|
{inherit type;}
|
||||||
|
(mkOverride "systems")
|
||||||
|
(mkOverride "flake-utils")
|
||||||
|
(mkOverride "lib-aggregate")
|
||||||
|
];
|
||||||
|
|
||||||
|
mkDep = info: mkInput (recursiveUpdate info {inputs.nixpkgs.follows = "nixpkgs";});
|
||||||
|
|
||||||
|
mkHyprDep = info: mkInput (recursiveUpdate info {inputs.hyprland.follows = "hyprland";});
|
||||||
|
|
||||||
|
mkSrc = info: mkInput (info // {flake = false;});
|
||||||
|
}
|
24
lib/pkgs.nix
Normal file
24
lib/pkgs.nix
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
pkgs: mkVersion: {
|
||||||
|
buildPlugin = pname: src:
|
||||||
|
pkgs.vimUtils.buildVimPlugin {
|
||||||
|
inherit pname src;
|
||||||
|
version = mkVersion src;
|
||||||
|
};
|
||||||
|
|
||||||
|
buildNodeModules = dir: npmDepsHash: let
|
||||||
|
pkg = pkgs.callPackage ({buildNpmPackage, ...}: let
|
||||||
|
inherit (builtins) readFile fromJSON;
|
||||||
|
|
||||||
|
packageJSON = fromJSON (readFile (dir + /package.json));
|
||||||
|
in
|
||||||
|
buildNpmPackage {
|
||||||
|
pname = packageJSON.name;
|
||||||
|
inherit (packageJSON) version;
|
||||||
|
|
||||||
|
src = dir;
|
||||||
|
|
||||||
|
inherit npmDepsHash;
|
||||||
|
dontNpmBuild = true;
|
||||||
|
}) {};
|
||||||
|
in "${pkg}/lib/node_modules/${pkg.pname}/node_modules";
|
||||||
|
}
|
|
@ -68,7 +68,7 @@ in {
|
||||||
|
|
||||||
home = {
|
home = {
|
||||||
file = let
|
file = let
|
||||||
inherit (import "${self}/lib.nix" {inherit pkgs;}) buildNodeModules;
|
inherit (import "${self}/lib" {inherit pkgs;}) buildNodeModules;
|
||||||
|
|
||||||
mkType = package: girName: {
|
mkType = package: girName: {
|
||||||
"${agsConfigDir}/config/types/@girs/${toLower girName}".source =
|
"${agsConfigDir}/config/types/@girs/${toLower girName}".source =
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
systems,
|
systems,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (import "${self}/lib.nix" inputs) mkVersion mkNixOS mkNixOnDroid mkPkgs;
|
inherit (import ./lib {inherit inputs;}) mkVersion mkNixOS mkNixOnDroid mkPkgs;
|
||||||
|
|
||||||
perSystem = attrs:
|
perSystem = attrs:
|
||||||
nixpkgs.lib.genAttrs (import systems) (system:
|
nixpkgs.lib.genAttrs (import systems) (system:
|
||||||
|
|
Loading…
Reference in a new issue