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",
|
"musicutil": "musicutil",
|
||||||
"nixpkgs-fixed": "nixpkgs-fixed",
|
"nixpkgs-fixed": "nixpkgs-fixed",
|
||||||
"nixpkgs-unstable": "nixpkgs-unstable",
|
"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": {
|
"utils": {
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
#nix-darwin-unstable.url = "github:lnl7/nix-darwin/master";
|
#nix-darwin-unstable.url = "github:lnl7/nix-darwin/master";
|
||||||
#nix-darwin-unstable.inputs.nixpkgs.follows = "nixpkgs-unstable";
|
#nix-darwin-unstable.inputs.nixpkgs.follows = "nixpkgs-unstable";
|
||||||
|
|
||||||
|
tree-input.url = "github:kittywitch/tree";
|
||||||
|
tree-input.inputs.nixpkgs.follows = "nixpkgs-unstable";
|
||||||
|
|
||||||
# update whenever
|
# update whenever
|
||||||
nixpkgs-fixed.url =
|
nixpkgs-fixed.url =
|
||||||
"github:nixos/nixpkgs/?branch=nixos-unstable&rev=20fc948445a6c22d4e8d5178e9a6bc6e1f5417c8";
|
"github:nixos/nixpkgs/?branch=nixos-unstable&rev=20fc948445a6c22d4e8d5178e9a6bc6e1f5417c8";
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
{ self, nixpkgs-unstable, nix-darwin-unstable, tree, ... }@inputs:
|
{ self, nixpkgs-unstable, nix-darwin-unstable, tree, ... }@inputs:
|
||||||
let
|
let
|
||||||
|
|
||||||
defaults = import ./defaults.nix inputs;
|
|
||||||
|
|
||||||
defaultSpecialArgs = defaults.defaultSpecialArgs // {
|
defaultSpecialArgs = defaults.defaultSpecialArgs // {
|
||||||
inputs = inputs // {
|
inputs = inputs // {
|
||||||
# set these to the correct versions from 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" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
WorkingDirectory = "/run/piped-backend";
|
WorkingDirectory = "/run/piped-backend";
|
||||||
ExecStartPre = let
|
ExecStartPre = let confFile = "/run/piped-backend/config.properties";
|
||||||
confFile = "/run/piped-backend/config.properties";
|
|
||||||
in "${pkgs.writeShellScript "piped-backend-init" ''
|
in "${pkgs.writeShellScript "piped-backend-init" ''
|
||||||
[ -f "${confFile}" ] && rm ${confFile}
|
[ -f "${confFile}" ] && rm ${confFile}
|
||||||
cp ${backend_config_file} ${confFile}
|
cp ${backend_config_file} ${confFile}
|
||||||
|
|
|
@ -1,27 +1,32 @@
|
||||||
{ self, nixpkgs-unstable, tree, ... }@inputs:
|
{ self, nixpkgs-unstable, ... }@inputs:
|
||||||
let
|
let
|
||||||
|
mkTree = inputs.tree-input.tree;
|
||||||
|
metaTree = mkTree ((import ../treeConfig.nix { }) // { inherit inputs; });
|
||||||
|
tree = metaTree.impure;
|
||||||
|
|
||||||
defaults = import ./defaults.nix inputs;
|
patchedInputs = inputs // {
|
||||||
|
|
||||||
defaultSpecialArgs = defaults.defaultSpecialArgs // {
|
|
||||||
inputs = inputs // {
|
|
||||||
# set these to the correct versions from inputs
|
# set these to the correct versions from inputs
|
||||||
nixpkgs = inputs.nixpkgs-unstable;
|
nixpkgs = inputs.nixpkgs-unstable;
|
||||||
home-manager = inputs.home-manager-unstable;
|
home-manager = inputs.home-manager-unstable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
defaultSpecialArgs = {
|
||||||
|
tree = metaTree.impure;
|
||||||
|
pureTree = metaTree.pure;
|
||||||
|
inputs = patchedInputs;
|
||||||
};
|
};
|
||||||
|
|
||||||
defaultModules = defaults.defaultModules ++ [
|
defaultModules = [
|
||||||
# NO_INLINE
|
# NO_INLINE
|
||||||
tree.impure.profiles.base
|
tree.profiles.base
|
||||||
inputs.home-manager-unstable.nixosModules.home-manager
|
inputs.home-manager-unstable.nixosModules.home-manager
|
||||||
inputs.gitlab_artifacts_sync.nixosModule
|
inputs.gitlab_artifacts_sync.nixosModule
|
||||||
|
|
||||||
inputs.nur.nixosModules.nur
|
inputs.nur.nixosModules.nur
|
||||||
|
|
||||||
tree.impure.modules.nixos.rclone-serve
|
tree.modules.nixos.rclone-serve
|
||||||
tree.impure.modules.nixos.rclone-sync
|
tree.modules.nixos.rclone-sync
|
||||||
tree.impure.modules.nixos.secrets
|
tree.modules.nixos.secrets
|
||||||
];
|
];
|
||||||
|
|
||||||
nixosUnstableSystem = nixpkgs-unstable.lib.nixosSystem;
|
nixosUnstableSystem = nixpkgs-unstable.lib.nixosSystem;
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
{ self, nixpkgs-unstable, ... }@inputs:
|
{ self, nixpkgs-unstable, ... }@inputs:
|
||||||
let
|
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;
|
pkgs-x86_64-linux = nixpkgs-unstable.legacyPackages.x86_64-linux;
|
||||||
hosts = import ./hosts ({ inherit tree; } // inputs);
|
hosts = import ./hosts inputs;
|
||||||
in {
|
in {
|
||||||
nixosConfigurations = hosts.nixosConfigurations;
|
nixosConfigurations = hosts.nixosConfigurations;
|
||||||
#darwinConfigurations = hosts.darwinConfigurations;
|
#darwinConfigurations = hosts.darswinConfigurations;
|
||||||
|
|
||||||
deploy.nodes = (import ./deployNodes.nix {
|
deploy.nodes = (import ./deployNodes.nix {
|
||||||
nixosConfigurations = self.nixosConfigurations;
|
nixosConfigurations = self.nixosConfigurations;
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
let
|
let
|
||||||
meta = builtins.fromJSON (builtins.readFile ../meta.json);
|
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" ''
|
gradleInit = writeText "init.gradle" ''
|
||||||
logger.lifecycle 'Replacing Maven repositories with ${deps}...'
|
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,5 +1,4 @@
|
||||||
{ mkTree, ... }: {
|
{ }: {
|
||||||
tree = mkTree {
|
|
||||||
folder = ./.;
|
folder = ./.;
|
||||||
config = {
|
config = {
|
||||||
"extras/*".functor.enable = true;
|
"extras/*".functor.enable = true;
|
||||||
|
@ -42,5 +41,4 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue