From af019b10798fec306f1afd5aff45348bb6b4a55a Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 8 Jan 2023 19:07:20 +0100 Subject: [PATCH] packages: don't include self and inputs in perSystem --- packages/build-support/default.nix | 17 +-- packages/build-support/drv-parts/default.nix | 19 +-- packages/checks/default.nix | 25 ++-- packages/modules/devshell.nix | 121 +++++++++--------- packages/networking/hyprspace/project.nix | 66 +++++----- packages/networking/ipfs-cluster/project.nix | 103 +++++++-------- packages/projects.nix | 24 ++-- packages/servers/reflex-cache/project.nix | 64 ++++----- packages/websites/landing/project.nix | 99 +++++++------- .../websites/stop-using-nix-env/project.nix | 32 ++--- 10 files changed, 291 insertions(+), 279 deletions(-) diff --git a/packages/build-support/default.nix b/packages/build-support/default.nix index e914009..b6e1e4c 100644 --- a/packages/build-support/default.nix +++ b/packages/build-support/default.nix @@ -1,17 +1,18 @@ -{ pkgs, ... }: - { imports = [ - ./options.nix - ./drv-parts ]; + perSystem = { pkgs, ... }: { + imports = [ + ./options.nix + ]; - builders = rec { - fetchAsset = pkgs.callPackage ./fetch-asset { }; + builders = rec { + fetchAsset = pkgs.callPackage ./fetch-asset { }; - hydrateAssetDirectory = pkgs.callPackage ./hydrate-asset-directory { - inherit fetchAsset; + hydrateAssetDirectory = pkgs.callPackage ./hydrate-asset-directory { + inherit fetchAsset; + }; }; }; } diff --git a/packages/build-support/drv-parts/default.nix b/packages/build-support/drv-parts/default.nix index b1784bf..a69ef64 100644 --- a/packages/build-support/drv-parts/default.nix +++ b/packages/build-support/drv-parts/default.nix @@ -1,11 +1,12 @@ -{ config, inputs, ... }: - +{ inputs, ... }: { - imports = [ - ./backends - ./dependency-sets - ]; - _module.args = { - drv-backends = inputs.drv-parts.drv-backends // config.drv-backends; + perSystem = { config, ... }: { + imports = [ + ./backends + ./dependency-sets + ]; + _module.args = { + drv-backends = inputs.drv-parts.drv-backends // config.drv-backends; + }; }; -} +} \ No newline at end of file diff --git a/packages/checks/default.nix b/packages/checks/default.nix index 7eba7c9..60f1362 100644 --- a/packages/checks/default.nix +++ b/packages/checks/default.nix @@ -1,15 +1,18 @@ -{ filters, pkgs, self, self', ... }: -{ - checks = filters.doFilter filters.checks { - keycloak = pkgs.callPackage ./keycloak-custom-jre.nix { - jre = self'.packages.jre17_standard; - }; +{ self, ... }: - patroni = pkgs.callPackage ./patroni.nix { - patroniModule = self.nixosModules.patroni; - }; - tempo = pkgs.callPackage ./tempo.nix { - inherit (self'.packages) tempo; +{ + perSystem = { filters, pkgs, self', ... }: { + checks = filters.doFilter filters.checks { + keycloak = pkgs.callPackage ./keycloak-custom-jre.nix { + jre = self'.packages.jre17_standard; + }; + + patroni = pkgs.callPackage ./patroni.nix { + patroniModule = self.nixosModules.patroni; + }; + tempo = pkgs.callPackage ./tempo.nix { + inherit (self'.packages) tempo; + }; }; }; } diff --git a/packages/modules/devshell.nix b/packages/modules/devshell.nix index 2cfda02..2895d1e 100644 --- a/packages/modules/devshell.nix +++ b/packages/modules/devshell.nix @@ -1,67 +1,70 @@ -{ lib, config, inputs', system, ... }: -with lib; -let - inherit (inputs'.devshell.legacyPackages) mkShell; +{ lib, ... }: - wrapInAttrs = value: if builtins.isAttrs value then value else { inherit value; }; +{ + perSystem = { config, inputs', system, ... }: + with lib; + let + inherit (inputs'.devshell.legacyPackages) mkShell; - wrapPackage = package: { inherit package; }; + wrapInAttrs = value: if builtins.isAttrs value then value else { inherit value; }; - injectAttrName = name: value: { inherit name; } // wrapInAttrs value; + wrapPackage = package: { inherit package; }; - mkNamedAttrs = builtins.mapAttrs injectAttrName; + injectAttrName = name: value: { inherit name; } // wrapInAttrs value; - attrsToNamedList = attrs: builtins.attrValues (mkNamedAttrs attrs); + mkNamedAttrs = builtins.mapAttrs injectAttrName; - mkProjectShell = - { - packages ? [], - tools ? [], - commands ? {}, - env ? {}, - config ? {} - }: - mkShell { - imports = [ - config - { - commands = map wrapPackage tools; - } - { - inherit packages; - commands = attrsToNamedList commands; - env = attrsToNamedList env; - } - ]; + attrsToNamedList = attrs: builtins.attrValues (mkNamedAttrs attrs); + + mkProjectShell = + { + packages ? [], + tools ? [], + commands ? {}, + env ? {}, + config ? {} + }: + mkShell { + imports = [ + config + { + commands = map wrapPackage tools; + } + { + inherit packages; + commands = attrsToNamedList commands; + env = attrsToNamedList env; + } + ]; + }; + in { + options.projectShells = mkOption { + default = {}; + type = types.attrsOf (types.submodule { + options = { + packages = mkOption { + default = []; + type = types.listOf types.package; + }; + tools = mkOption { + default = []; + type = types.listOf types.package; + }; + commands = mkOption { + default = {}; + type = types.attrsOf types.attrs; + }; + env = mkOption { + default = {}; + type = with types; attrsOf (oneOf [ attrs str ] ); + }; + config = mkOption { + default = {}; + type = types.anything; + }; + }; + }); + }; + config.devShells = lib.mkIf (system == "x86_64-linux") (mapAttrs (_: mkProjectShell) config.projectShells); }; -in { - options.projectShells = mkOption { - default = {}; - type = types.attrsOf (types.submodule { - options = { - packages = mkOption { - default = []; - type = types.listOf types.package; - }; - tools = mkOption { - default = []; - type = types.listOf types.package; - }; - commands = mkOption { - default = {}; - type = types.attrsOf types.attrs; - }; - env = mkOption { - default = {}; - type = with types; attrsOf (oneOf [ attrs str ] ); - }; - config = mkOption { - default = {}; - type = types.anything; - }; - }; - }); - }; - config.devShells = lib.mkIf (system == "x86_64-linux") (mapAttrs (_: mkProjectShell) config.projectShells); } - diff --git a/packages/networking/hyprspace/project.nix b/packages/networking/hyprspace/project.nix index 1d991e7..6373a64 100644 --- a/packages/networking/hyprspace/project.nix +++ b/packages/networking/hyprspace/project.nix @@ -1,40 +1,42 @@ -{ inputs, lib, pkgs, ... }: +{ lib, inputs, ... }: { - projectShells.hyprspace = { - tools = [ - pkgs.go_1_18 - ]; - env.GOPATH.eval = "$REPO_DATA_DIR/go"; - }; - packages.hyprspace = with pkgs; buildGo118Module { - pname = "hyprspace"; - version = "0.3.2"; - - src = with inputs.nix-filter.lib; let - dirs = map inDirectory; - in filter { - root = ./.; - include = [ - "go.mod" - "go.sum" - (matchExt "go") - ] ++ (dirs [ - "cli" - "config" - "p2p" - "tun" - ]); + perSystem = { pkgs, ... }: { + projectShells.hyprspace = { + tools = [ + pkgs.go_1_18 + ]; + env.GOPATH.eval = "$REPO_DATA_DIR/go"; }; + packages.hyprspace = with pkgs; buildGo118Module { + pname = "hyprspace"; + version = "0.3.2"; - vendorSha256 = "sha256-BiNWV/uNPnplwNfAvqf/Xc9ReFkLhHWVVeZrb/NI4bE="; + src = with inputs.nix-filter.lib; let + dirs = map inDirectory; + in filter { + root = ./.; + include = [ + "go.mod" + "go.sum" + (matchExt "go") + ] ++ (dirs [ + "cli" + "config" + "p2p" + "tun" + ]); + }; - meta = with lib; { - description = "A Lightweight VPN Built on top of Libp2p for Truly Distributed Networks."; - homepage = "https://github.com/hyprspace/hyprspace"; - license = licenses.asl20; - maintainers = with maintainers; [ yusdacra ]; - platforms = platforms.linux ++ platforms.darwin; + vendorSha256 = "sha256-BiNWV/uNPnplwNfAvqf/Xc9ReFkLhHWVVeZrb/NI4bE="; + + meta = with lib; { + description = "A Lightweight VPN Built on top of Libp2p for Truly Distributed Networks."; + homepage = "https://github.com/hyprspace/hyprspace"; + license = licenses.asl20; + maintainers = with maintainers; [ yusdacra ]; + platforms = platforms.linux ++ platforms.darwin; + }; }; }; } diff --git a/packages/networking/ipfs-cluster/project.nix b/packages/networking/ipfs-cluster/project.nix index bb37bac..9e89fd2 100644 --- a/packages/networking/ipfs-cluster/project.nix +++ b/packages/networking/ipfs-cluster/project.nix @@ -1,58 +1,59 @@ -{ inputs, lib, pkgs, ... }: - +{ inputs, ... }: { - projectShells.ipfs-cluster = { - tools = [ - pkgs.go_1_19 - pkgs.gnumake - pkgs.gcc - ]; - env.GOPATH.eval = "$REPO_DATA_DIR/go"; - }; - packages.ipfs-cluster = with pkgs; buildGo119Module { - pname = "ipfs-cluster"; - version = "1.0.2"; - - src = with inputs.nix-filter.lib; filter { - root = ./.; - include = [ - "go.mod" - "go.sum" - (matchExt "go") - ] ++ (map inDirectory [ - "adder" - "allocator" - "api" - "cmd" - "cmdutils" - "config" - "consensus" - "datastore" - "docker" - "informer" - "ipfsconn" - "monitor" - "observations" - "pintracker" - "pstoremgr" - "rpcutil" - "sharness" - "state" - "test" - "version" - ]); + perSystem = { lib, pkgs, ... }: { + projectShells.ipfs-cluster = { + tools = [ + pkgs.go_1_19 + pkgs.gnumake + pkgs.gcc + ]; + env.GOPATH.eval = "$REPO_DATA_DIR/go"; }; + packages.ipfs-cluster = with pkgs; buildGo119Module { + pname = "ipfs-cluster"; + version = "1.0.2"; - vendorSha256 = "sha256-EpZQ7br+ChoAGIj0g6pdpWvFeOFOn2i+6YRBgtzoO+A="; + src = with inputs.nix-filter.lib; filter { + root = ./.; + include = [ + "go.mod" + "go.sum" + (matchExt "go") + ] ++ (map inDirectory [ + "adder" + "allocator" + "api" + "cmd" + "cmdutils" + "config" + "consensus" + "datastore" + "docker" + "informer" + "ipfsconn" + "monitor" + "observations" + "pintracker" + "pstoremgr" + "rpcutil" + "sharness" + "state" + "test" + "version" + ]); + }; - doCheck = false; + vendorSha256 = "sha256-EpZQ7br+ChoAGIj0g6pdpWvFeOFOn2i+6YRBgtzoO+A="; - meta = with lib; { - description = "Allocate, replicate, and track Pins across a cluster of IPFS daemons"; - homepage = "https://ipfscluster.io"; - license = licenses.mit; - platforms = platforms.unix; - maintainers = with maintainers; [ Luflosi jglukasik ]; - }; + doCheck = false; + + meta = with lib; { + description = "Allocate, replicate, and track Pins across a cluster of IPFS daemons"; + homepage = "https://ipfscluster.io"; + license = licenses.mit; + platforms = platforms.unix; + maintainers = with maintainers; [ Luflosi jglukasik ]; + }; + }; }; } diff --git a/packages/projects.nix b/packages/projects.nix index 442a99a..e0c27fe 100644 --- a/packages/projects.nix +++ b/packages/projects.nix @@ -1,6 +1,17 @@ { inputs, self, ... }: { + imports = [ + ./checks + ./modules/devshell.nix + ./build-support + + ./networking/hyprspace/project.nix + ./networking/ipfs-cluster/project.nix + ./servers/reflex-cache/project.nix + ./websites/landing/project.nix + ./websites/stop-using-nix-env/project.nix + ]; perSystem = { filters, pkgs, self', ... }: let inherit (self'.packages) nix-super; @@ -16,19 +27,6 @@ }; in { - _module.args = { inherit inputs self; }; - - imports = [ - ./checks - ./modules/devshell.nix - ./build-support - - ./networking/hyprspace/project.nix - ./networking/ipfs-cluster/project.nix - ./servers/reflex-cache/project.nix - ./websites/landing/project.nix - ./websites/stop-using-nix-env/project.nix - ]; packages = filters.doFilter filters.packages rec { cinny = pkgs.callPackage ./web-apps/cinny { inherit pins; }; diff --git a/packages/servers/reflex-cache/project.nix b/packages/servers/reflex-cache/project.nix index 3453f05..611484f 100644 --- a/packages/servers/reflex-cache/project.nix +++ b/packages/servers/reflex-cache/project.nix @@ -1,38 +1,40 @@ -{ config, drv-backends, inputs, lib, pkgs, ... }: +{ inputs, ... }: -let - deps = with config.dependencySets.python3Packages; [ - poetry-core - requests-unixsocket - py-multibase - py-multiaddr - ]; - - pythonForDev = pkgs.python3.withPackages (lib.const deps); -in { - projectShells.reflex-cache = { - tools = [ - pythonForDev + perSystem = { config, drv-backends, lib, pkgs, ... }: let + deps = with config.dependencySets.python3Packages; [ + poetry-core + requests-unixsocket + py-multibase + py-multiaddr ]; - env.PYTHON = pythonForDev.interpreter; - commands.reflex.command = "${pythonForDev.interpreter} -m reflex_cache.main"; - }; - drvs.reflex-cache = { dependencySets, ... }: { - imports = [ - drv-backends.buildPythonPackage - ]; - pyprojectToml = ./pyproject.toml; - inherit (pkgs) stdenv; - propagatedBuildInputs = deps; - - src = with inputs.nix-filter.lib; filter { - root = ./.; - include = [ - "pyproject.toml" - (inDirectory "reflex_cache") + pythonForDev = pkgs.python3.withPackages (lib.const deps); + in + { + projectShells.reflex-cache = { + tools = [ + pythonForDev ]; + env.PYTHON = pythonForDev.interpreter; + commands.reflex.command = "${pythonForDev.interpreter} -m reflex_cache.main"; + }; + drvs.reflex-cache = { dependencySets, ... }: { + imports = [ + drv-backends.buildPythonPackage + ]; + pyprojectToml = ./pyproject.toml; + inherit (pkgs) stdenv; + + propagatedBuildInputs = deps; + + src = with inputs.nix-filter.lib; filter { + root = ./.; + include = [ + "pyproject.toml" + (inDirectory "reflex_cache") + ]; + }; }; }; -} +} \ No newline at end of file diff --git a/packages/websites/landing/project.nix b/packages/websites/landing/project.nix index 687e447..9ba2bbc 100644 --- a/packages/websites/landing/project.nix +++ b/packages/websites/landing/project.nix @@ -1,54 +1,55 @@ -{ builders, lib, pkgs, self', ... }: -let - configFile = pkgs.writeText "hugo-config.json" (builtins.toJSON { - title = "Private Void | Zero-maintenance perfection"; - baseURL = "https://www.privatevoid.net/"; - languageCode = "en-us"; - disableKinds = [ - "page" - "RSS" - "section" - "sitemap" - "taxonomy" - "taxonomyTerm" - ]; - }); - hugoArgs = [ - "--config" configFile - ]; - hugoArgsStr = lib.concatStringsSep " " hugoArgs; -in { - projectShells.landing = { - commands.hugo = { - help = pkgs.hugo.meta.description; - command = "exec ${pkgs.hugo}/bin/hugo ${hugoArgsStr} \"$@\""; - }; - tools = with self'.packages; [ - dvc - ]; - }; - - packages.landing = with pkgs; let - site = stdenvNoCC.mkDerivation rec { - pname = "private-void-landing-page"; - version = "0.0.0"; - src = builders.hydrateAssetDirectory ./.; - nativeBuildInputs = [ - hugo + perSystem = { builders, lib, pkgs, self', ... }: let + configFile = pkgs.writeText "hugo-config.json" (builtins.toJSON { + title = "Private Void | Zero-maintenance perfection"; + baseURL = "https://www.privatevoid.net/"; + languageCode = "en-us"; + disableKinds = [ + "page" + "RSS" + "section" + "sitemap" + "taxonomy" + "taxonomyTerm" ]; - buildCommand = '' - unpackPhase - mkdir -p $out/share/www - hugo ${hugoArgsStr} -s $sourceRoot -d $out/share/www/${pname} - ''; - passthru = { - webroot = "${site}/share/www/${site.pname}"; - serve = writeShellScriptBin "serve-site" '' - command -v xdg-open >/dev/null && xdg-open http://127.0.0.1:1314 || true - ${darkhttpd}/bin/darkhttpd ${site.webroot} --addr 127.0.0.1 --port 1314 - ''; + }); + hugoArgs = [ + "--config" configFile + ]; + hugoArgsStr = lib.concatStringsSep " " hugoArgs; + in + { + projectShells.landing = { + commands.hugo = { + help = pkgs.hugo.meta.description; + command = "exec ${pkgs.hugo}/bin/hugo ${hugoArgsStr} \"$@\""; }; + tools = with self'.packages; [ + dvc + ]; }; - in site; + + packages.landing = with pkgs; let + site = stdenvNoCC.mkDerivation rec { + pname = "private-void-landing-page"; + version = "0.0.0"; + src = builders.hydrateAssetDirectory ./.; + nativeBuildInputs = [ + hugo + ]; + buildCommand = '' + unpackPhase + mkdir -p $out/share/www + hugo ${hugoArgsStr} -s $sourceRoot -d $out/share/www/${pname} + ''; + passthru = { + webroot = "${site}/share/www/${site.pname}"; + serve = writeShellScriptBin "serve-site" '' + command -v xdg-open >/dev/null && xdg-open http://127.0.0.1:1314 || true + ${darkhttpd}/bin/darkhttpd ${site.webroot} --addr 127.0.0.1 --port 1314 + ''; + }; + }; + in site; + }; } diff --git a/packages/websites/stop-using-nix-env/project.nix b/packages/websites/stop-using-nix-env/project.nix index 2c1439a..0c733d6 100644 --- a/packages/websites/stop-using-nix-env/project.nix +++ b/packages/websites/stop-using-nix-env/project.nix @@ -1,19 +1,19 @@ -{ pkgs, ... }: - { - packages.stop-using-nix-env = let - site = with pkgs; stdenvNoCC.mkDerivation rec { - pname = "stop-using-nix-env"; - version = "1.2.0"; - src = ./src; - buildCommand = '' - install -Dm644 $src/* -t $out/share/www/${pname} - substituteInPlace $out/share/www/${pname}/index.html \ - --replace '' 'Version ${version} |' - ''; - passthru = { - webroot = "${site}/share/www/${pname}"; + perSystem = { pkgs, ... }: { + packages.stop-using-nix-env = let + site = with pkgs; stdenvNoCC.mkDerivation rec { + pname = "stop-using-nix-env"; + version = "1.2.0"; + src = ./src; + buildCommand = '' + install -Dm644 $src/* -t $out/share/www/${pname} + substituteInPlace $out/share/www/${pname}/index.html \ + --replace '' 'Version ${version} |' + ''; + passthru = { + webroot = "${site}/share/www/${pname}"; + }; }; - }; - in site; + in site; + }; }