diff --git a/flake.lock b/flake.lock index f5b153a..5dfd03b 100644 --- a/flake.lock +++ b/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": { diff --git a/flake.nix b/flake.nix index 787844e..3b52eca 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; diff --git a/hosts/darwin.nix b/hosts/darwin.nix index 9d52e2d..d02e488 100644 --- a/hosts/darwin.nix +++ b/hosts/darwin.nix @@ -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 diff --git a/hosts/defaults.nix b/hosts/defaults.nix deleted file mode 100644 index 4265379..0000000 --- a/hosts/defaults.nix +++ /dev/null @@ -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; -} diff --git a/hosts/hetzner-vm/modules/piped/backend.nix b/hosts/hetzner-vm/modules/piped/backend.nix index 8c6aae4..50ba43f 100644 --- a/hosts/hetzner-vm/modules/piped/backend.nix +++ b/hosts/hetzner-vm/modules/piped/backend.nix @@ -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} diff --git a/hosts/nixos.nix b/hosts/nixos.nix index 449c251..5828743 100644 --- a/hosts/nixos.nix +++ b/hosts/nixos.nix @@ -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; diff --git a/outputs.nix b/outputs.nix index c134dcd..c4494fc 100644 --- a/outputs.nix +++ b/outputs.nix @@ -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; diff --git a/overlay/default.nix b/overlay/default.nix index 6719264..869766a 100644 --- a/overlay/default.nix +++ b/overlay/default.nix @@ -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; }; diff --git a/overlay/piped/backend/default.nix b/overlay/piped/backend/default.nix index ae11739..e2f0247 100644 --- a/overlay/piped/backend/default.nix +++ b/overlay/piped/backend/default.nix @@ -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}...' diff --git a/tree.nix b/tree.nix deleted file mode 100644 index 7d5d72d..0000000 --- a/tree.nix +++ /dev/null @@ -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; -} diff --git a/treeConfig.nix b/treeConfig.nix index d412b3a..c91cd0e 100644 --- a/treeConfig.nix +++ b/treeConfig.nix @@ -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 = [ ]; }; }; };