use tree as a input and rework how tree and inputs are set/used
This commit is contained in:
parent
b48a64a1ef
commit
25ef2935ff
23
flake.lock
23
flake.lock
|
@ -229,7 +229,28 @@
|
|||
"musicutil": "musicutil",
|
||||
"nixpkgs-fixed": "nixpkgs-fixed",
|
||||
"nixpkgs-unstable": "nixpkgs-unstable",
|
||||
"nur": "nur"
|
||||
"nur": "nur",
|
||||
"tree-input": "tree-input"
|
||||
}
|
||||
},
|
||||
"tree-input": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs-unstable"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1669922720,
|
||||
"narHash": "sha256-xzoKL4RtKRECdrWHAM14OBaNdJRToc+AA9zmUWuo5eY=",
|
||||
"owner": "kittywitch",
|
||||
"repo": "tree",
|
||||
"rev": "fbe8ae96d7f4fb369d32dbbe8434606b23354caf",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "kittywitch",
|
||||
"repo": "tree",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"utils": {
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
#nix-darwin-unstable.url = "github:lnl7/nix-darwin/master";
|
||||
#nix-darwin-unstable.inputs.nixpkgs.follows = "nixpkgs-unstable";
|
||||
|
||||
tree-input.url = "github:kittywitch/tree";
|
||||
tree-input.inputs.nixpkgs.follows = "nixpkgs-unstable";
|
||||
|
||||
# update whenever
|
||||
nixpkgs-fixed.url =
|
||||
"github:nixos/nixpkgs/?branch=nixos-unstable&rev=20fc948445a6c22d4e8d5178e9a6bc6e1f5417c8";
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
{ self, nixpkgs-unstable, nix-darwin-unstable, tree, ... }@inputs:
|
||||
let
|
||||
|
||||
defaults = import ./defaults.nix inputs;
|
||||
|
||||
defaultSpecialArgs = defaults.defaultSpecialArgs // {
|
||||
inputs = inputs // {
|
||||
# set these to the correct versions from inputs
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
{ self, nixpkgs-unstable, tree, ... }@inputs:
|
||||
let
|
||||
defaultModules = [
|
||||
# NO_INLINE
|
||||
tree.impure.modules.nixos
|
||||
];
|
||||
defaultSpecialArgs = {
|
||||
tree = tree.impure;
|
||||
pureTree = tree.pure;
|
||||
};
|
||||
in {
|
||||
inherit defaultModules;
|
||||
inherit defaultSpecialArgs;
|
||||
}
|
|
@ -54,8 +54,7 @@ in {
|
|||
wantedBy = [ "multi-user.target" ];
|
||||
serviceConfig = {
|
||||
WorkingDirectory = "/run/piped-backend";
|
||||
ExecStartPre = let
|
||||
confFile = "/run/piped-backend/config.properties";
|
||||
ExecStartPre = let confFile = "/run/piped-backend/config.properties";
|
||||
in "${pkgs.writeShellScript "piped-backend-init" ''
|
||||
[ -f "${confFile}" ] && rm ${confFile}
|
||||
cp ${backend_config_file} ${confFile}
|
||||
|
|
|
@ -1,27 +1,32 @@
|
|||
{ self, nixpkgs-unstable, tree, ... }@inputs:
|
||||
{ self, nixpkgs-unstable, ... }@inputs:
|
||||
let
|
||||
mkTree = inputs.tree-input.tree;
|
||||
metaTree = mkTree ((import ../treeConfig.nix { }) // { inherit inputs; });
|
||||
tree = metaTree.impure;
|
||||
|
||||
defaults = import ./defaults.nix inputs;
|
||||
|
||||
defaultSpecialArgs = defaults.defaultSpecialArgs // {
|
||||
inputs = inputs // {
|
||||
# set these to the correct versions from inputs
|
||||
nixpkgs = inputs.nixpkgs-unstable;
|
||||
home-manager = inputs.home-manager-unstable;
|
||||
};
|
||||
patchedInputs = inputs // {
|
||||
# set these to the correct versions from inputs
|
||||
nixpkgs = inputs.nixpkgs-unstable;
|
||||
home-manager = inputs.home-manager-unstable;
|
||||
};
|
||||
|
||||
defaultModules = defaults.defaultModules ++ [
|
||||
defaultSpecialArgs = {
|
||||
tree = metaTree.impure;
|
||||
pureTree = metaTree.pure;
|
||||
inputs = patchedInputs;
|
||||
};
|
||||
|
||||
defaultModules = [
|
||||
# NO_INLINE
|
||||
tree.impure.profiles.base
|
||||
tree.profiles.base
|
||||
inputs.home-manager-unstable.nixosModules.home-manager
|
||||
inputs.gitlab_artifacts_sync.nixosModule
|
||||
|
||||
inputs.nur.nixosModules.nur
|
||||
|
||||
tree.impure.modules.nixos.rclone-serve
|
||||
tree.impure.modules.nixos.rclone-sync
|
||||
tree.impure.modules.nixos.secrets
|
||||
tree.modules.nixos.rclone-serve
|
||||
tree.modules.nixos.rclone-sync
|
||||
tree.modules.nixos.secrets
|
||||
];
|
||||
|
||||
nixosUnstableSystem = nixpkgs-unstable.lib.nixosSystem;
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
{ self, nixpkgs-unstable, ... }@inputs:
|
||||
let
|
||||
mkTree = import ./tree.nix { inherit (nixpkgs-unstable) lib; };
|
||||
tree = (import ./treeConfig.nix { inherit mkTree; }).tree;
|
||||
|
||||
pkgs-x86_64-linux = nixpkgs-unstable.legacyPackages.x86_64-linux;
|
||||
hosts = import ./hosts ({ inherit tree; } // inputs);
|
||||
hosts = import ./hosts inputs;
|
||||
in {
|
||||
nixosConfigurations = hosts.nixosConfigurations;
|
||||
#darwinConfigurations = hosts.darwinConfigurations;
|
||||
#darwinConfigurations = hosts.darswinConfigurations;
|
||||
|
||||
deploy.nodes = (import ./deployNodes.nix {
|
||||
nixosConfigurations = self.nixosConfigurations;
|
||||
|
|
|
@ -8,7 +8,7 @@ final: prev: {
|
|||
videojs = final.callPackage ./invidious/videojs.nix { };
|
||||
};
|
||||
misskey-static = final.callPackage ./misskey { };
|
||||
piped-backend = final.callPackage ./piped/backend {
|
||||
piped-backend = final.callPackage ./piped/backend {
|
||||
jre = final.openjdk17_headless;
|
||||
jdk = final.openjdk17;
|
||||
};
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
let
|
||||
meta = builtins.fromJSON (builtins.readFile ../meta.json);
|
||||
|
||||
deps = callPackage ./deps.nix { inherit stdenv fetchFromGitHub jdk gradle perl; };
|
||||
deps =
|
||||
callPackage ./deps.nix { inherit stdenv fetchFromGitHub jdk gradle perl; };
|
||||
|
||||
gradleInit = writeText "init.gradle" ''
|
||||
logger.lifecycle 'Replacing Maven repositories with ${deps}...'
|
||||
|
|
137
tree.nix
137
tree.nix
|
@ -1,137 +0,0 @@
|
|||
{ lib }:
|
||||
{ config, folder, ... }@args:
|
||||
with lib;
|
||||
let
|
||||
# Made by kat witch (kittywitch)
|
||||
pureTreeGrab = { base, path }:
|
||||
let
|
||||
realPath = toString path;
|
||||
dirContents = builtins.readDir path;
|
||||
isDirectory = entry: dirContents."${entry}" == "directory";
|
||||
isHidden = hasPrefix ".";
|
||||
isDir = entry: _: (isDirectory entry) && !(isHidden entry);
|
||||
directories = filterAttrs isDir dirContents;
|
||||
isNixFile = entry: _:
|
||||
let result = builtins.match "(.*)\\.nix" entry;
|
||||
in result != null && builtins.length result > 0;
|
||||
nixFiles = filterAttrs isNixFile dirContents;
|
||||
getPath = entry: "${realPath}/${entry}";
|
||||
getPaths =
|
||||
mapAttrs' (n: v: nameValuePair (removeSuffix ".nix" n) (getPath n));
|
||||
nixFilePaths = getPaths nixFiles;
|
||||
dirPaths = getPaths directories;
|
||||
recursedPaths = mapAttrs (_: fullPath:
|
||||
pureTreeGrab {
|
||||
inherit base;
|
||||
path = fullPath;
|
||||
}) dirPaths;
|
||||
contents = recursedPaths // nixFilePaths;
|
||||
in contents;
|
||||
configTreeStruct = { config, ... }: {
|
||||
options.treeConfig = mkOption {
|
||||
type = with types;
|
||||
attrsOf (submodule ({ name, options, config, ... }: {
|
||||
options = {
|
||||
evaluateDefault = mkOption {
|
||||
type = types.bool;
|
||||
description =
|
||||
"Replace the contents of this branch or leaf with those provided by the evaluation of default.nix.";
|
||||
default = false;
|
||||
};
|
||||
aliasDefault = mkOption {
|
||||
type = types.bool;
|
||||
description =
|
||||
"Replace the contents of this branch or leaf with the default.nix.";
|
||||
default = false;
|
||||
};
|
||||
excludes = mkOption {
|
||||
type = types.listOf types.str;
|
||||
description = "Exclude files or folders from the recurser.";
|
||||
default = [ ];
|
||||
};
|
||||
functor = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
description = "Provide a functor for the path provided";
|
||||
default = false;
|
||||
};
|
||||
external = mkOption {
|
||||
type = types.listOf types.unspecified;
|
||||
description = "Add external imports into the functor.";
|
||||
default = [ ];
|
||||
};
|
||||
excludes = mkOption {
|
||||
type = types.listOf types.str;
|
||||
description = "Exclude files or folders from the functor.";
|
||||
default = [ ];
|
||||
};
|
||||
};
|
||||
};
|
||||
}));
|
||||
};
|
||||
config.treeConfig = { "*" = { }; };
|
||||
};
|
||||
configTree.treeConfig = config;
|
||||
configTreeModule = (evalModules {
|
||||
modules = [ configTreeStruct configTree ];
|
||||
}).config.treeConfig;
|
||||
mapAttrsRecursive = f: set:
|
||||
let
|
||||
recurse = path: set:
|
||||
let
|
||||
g = name: value:
|
||||
if isAttrs value then
|
||||
f (path ++ [ name ]) (recurse (path ++ [ name ]) value)
|
||||
else
|
||||
f (path ++ [ name ]) value;
|
||||
in mapAttrs g set;
|
||||
in recurse [ ] set;
|
||||
getPathString = concatStringsSep "/";
|
||||
getConfig = path: default: configTreeModule.${getPathString path} or default;
|
||||
revtail = path: sublist 0 (length path - 1) path;
|
||||
getConfigRecursive = path:
|
||||
let parentPath = revtail path;
|
||||
in getConfig (path ++ singleton "*") (getConfigRecursive parentPath);
|
||||
processLeaves = tree: config:
|
||||
mapAttrsRecursive (path: value:
|
||||
let
|
||||
pathString = getPathString path;
|
||||
leafConfig = getConfig path (getConfigRecursive (revtail path));
|
||||
processConfig = path: value:
|
||||
let
|
||||
processFunctor = prev:
|
||||
prev // {
|
||||
__functor = self: _: {
|
||||
imports =
|
||||
attrValues (removeAttrs prev leafConfig.functor.excludes)
|
||||
++ leafConfig.functor.external;
|
||||
};
|
||||
};
|
||||
processAliasDefault = prev: prev.default;
|
||||
processDefault = prev:
|
||||
import prev.default (args // {
|
||||
inherit lib;
|
||||
tree = {
|
||||
prev = removeAttrs prev (singleton "default");
|
||||
pure = pureTree;
|
||||
impure = impureTree;
|
||||
};
|
||||
});
|
||||
processExcludes = prev: removeAttrs prev leafConfig.excludes;
|
||||
processes = optionals (isAttrs value)
|
||||
(optional (leafConfig.excludes != [ ]) processExcludes
|
||||
++ optional leafConfig.evaluateDefault processDefault
|
||||
++ optional leafConfig.aliasDefault processAliasDefault
|
||||
++ optional leafConfig.functor.enable processFunctor);
|
||||
in pipe value processes;
|
||||
in processConfig path value) tree;
|
||||
pureTree = pureTreeGrab {
|
||||
base = folder;
|
||||
path = folder;
|
||||
};
|
||||
impureTree = processLeaves pureTree configTreeModule;
|
||||
in {
|
||||
config = configTreeModule;
|
||||
pure = pureTree;
|
||||
impure = impureTree;
|
||||
}
|
|
@ -1,45 +1,43 @@
|
|||
{ mkTree, ... }: {
|
||||
tree = mkTree {
|
||||
folder = ./.;
|
||||
config = {
|
||||
"extras/*".functor.enable = true;
|
||||
{ }: {
|
||||
folder = ./.;
|
||||
config = {
|
||||
"extras/*".functor.enable = true;
|
||||
|
||||
"hosts/*/services".functor.enable = true;
|
||||
"hosts/hetzner-vm/modules/mailserver".functor.enable = true;
|
||||
"hosts/hetzner-vm/modules/piped".functor.enable = true;
|
||||
"hosts/raspberry/services/music-friend".functor.enable = true;
|
||||
"hosts/*/home".functor.enable = true;
|
||||
"hosts/*/profiles".functor.enable = true;
|
||||
"profiles/*".functor.enable = true;
|
||||
"profiles/sound/*".functor.enable = true;
|
||||
"profiles/sound/pulseaudio/*".functor.enable = true;
|
||||
"profiles/connectivity/*".functor.enable = true;
|
||||
"profiles/gaming/*".functor.enable = true;
|
||||
"profiles/gui/environments/*".functor.enable = true;
|
||||
"profiles/firewall-allow/*".functor.enable = true;
|
||||
"hosts/*/services".functor.enable = true;
|
||||
"hosts/hetzner-vm/modules/mailserver".functor.enable = true;
|
||||
"hosts/hetzner-vm/modules/piped".functor.enable = true;
|
||||
"hosts/raspberry/services/music-friend".functor.enable = true;
|
||||
"hosts/*/home".functor.enable = true;
|
||||
"hosts/*/profiles".functor.enable = true;
|
||||
"profiles/*".functor.enable = true;
|
||||
"profiles/sound/*".functor.enable = true;
|
||||
"profiles/sound/pulseaudio/*".functor.enable = true;
|
||||
"profiles/connectivity/*".functor.enable = true;
|
||||
"profiles/gaming/*".functor.enable = true;
|
||||
"profiles/gui/environments/*".functor.enable = true;
|
||||
"profiles/firewall-allow/*".functor.enable = true;
|
||||
|
||||
"users/*".functor.enable = true;
|
||||
"home/*".functor.enable = true;
|
||||
"home/gui/environments/*".functor.enable = true;
|
||||
"home/apps/*".functor.enable = true;
|
||||
"home/gaming/emulators/*".functor.enable = true;
|
||||
"home/gaming/games/*".functor.enable = true;
|
||||
"home/gaming/platforms/*".functor.enable = true;
|
||||
"home/programming/languages/*".functor.enable = true;
|
||||
"users/*".functor.enable = true;
|
||||
"home/*".functor.enable = true;
|
||||
"home/gui/environments/*".functor.enable = true;
|
||||
"home/apps/*".functor.enable = true;
|
||||
"home/gaming/emulators/*".functor.enable = true;
|
||||
"home/gaming/games/*".functor.enable = true;
|
||||
"home/gaming/platforms/*".functor.enable = true;
|
||||
"home/programming/languages/*".functor.enable = true;
|
||||
|
||||
"presets/nixos/*".functor.enable = true;
|
||||
"presets/nixos/*".functor.enable = true;
|
||||
|
||||
"modules/nixos" = {
|
||||
functor = {
|
||||
enable = true;
|
||||
external = [ ];
|
||||
};
|
||||
"modules/nixos" = {
|
||||
functor = {
|
||||
enable = true;
|
||||
external = [ ];
|
||||
};
|
||||
"modules/home" = {
|
||||
functor = {
|
||||
enable = true;
|
||||
external = [ ];
|
||||
};
|
||||
};
|
||||
"modules/home" = {
|
||||
functor = {
|
||||
enable = true;
|
||||
external = [ ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue