From ae682f1c07fb4b3bb14c47f4c74cd4d2b214a93a Mon Sep 17 00:00:00 2001 From: Alex Ameen Date: Wed, 28 Jun 2023 16:50:42 -0500 Subject: [PATCH] simplify drv --- .gitignore | 2 + pkgs/etc-profiles/base.nix | 70 --------------- pkgs/etc-profiles/default.nix | 142 ++++++++++++++++++++----------- pkgs/etc-profiles/mk-profile.nix | 56 ------------ 4 files changed, 93 insertions(+), 177 deletions(-) delete mode 100644 pkgs/etc-profiles/base.nix delete mode 100644 pkgs/etc-profiles/mk-profile.nix diff --git a/.gitignore b/.gitignore index 4a4b1d0..9d78e63 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /.flox +result +result-* diff --git a/pkgs/etc-profiles/base.nix b/pkgs/etc-profiles/base.nix deleted file mode 100644 index cc1d371..0000000 --- a/pkgs/etc-profiles/base.nix +++ /dev/null @@ -1,70 +0,0 @@ -# ============================================================================ # -# -# Creates a starter `/etc/profile' that aggregates -# `/etc/profile.d/*.sh' "child scripts". -# -# ---------------------------------------------------------------------------- # - -{ self, version, bash, coreutils, hostPlatform, ld-floxlib, lib, system }: let - pname = "profile-base"; -in ( derivation { - inherit system pname version; - name = pname + "-" + version; - builder = bash.outPath + "/bin/bash"; - PATH = coreutils.outPath + "/bin"; - args = ["-eu" "-o" "pipefail" "-c" ('' - mkdir -p "$out/etc" "$out/lib"; - cp -- ${self}/profile "$out/etc/profile"; - '' + lib.optionalString hostPlatform.isLinux '' - for i in ${ld-floxlib}/lib/*; do - ln -s "$i" "$out/lib/$(basename $i)"; - done - '')]; - preferLocalBuild = true; - allowSubstitutes = system == ( builtins.currentSystem or null ); -} ) // { - meta.description = - "An `/etc/profile' script to source `/etc/profile.d/*.sh`"; - meta.longDescription = '' - An `/etc/profile' script to source `/etc/profile.d/*.sh` - - Users can define and install scripts in `/etc/profile.d' as - "custom packages"/installables to share common setup processes - across environments. - - Recommended usage: - # flox.nix - { - packages.nixpkgs-flox.sqlite = { - meta.outputsToInstall = ["bin" "out" "dev"]; - }; - - # Provides developer environment hooks for use with python3. - packages.flox.etc-profiles = { - # Optionally, specify language packages to install. - # Invoke `flox search -c flox etc-profiles -l` to see - # a list of all supported language pack outputs. Please - # note that all/most language packs depend on including - # the "common_paths" output. - meta.outputsToInstall = [ "base" "common_paths" "python3" ]; - }; - - shell.hook = '${""}' - [[ -r "$FLOX_ENV/etc/profile" ]] && . "$FLOX_ENV/etc/profile"; - pkg-config --list-all >&2; - '${""}' - } - ''; - meta.outputsToInstall = ["out"]; - meta.platforms = [ - "x86_64-linux" "aarch64-linux" "i686-linux" - "x86_64-darwin" "aarch64-darwin" - ]; -} - - -# ---------------------------------------------------------------------------- # -# -# -# -# ============================================================================ # diff --git a/pkgs/etc-profiles/default.nix b/pkgs/etc-profiles/default.nix index 8cf064a..fc76817 100644 --- a/pkgs/etc-profiles/default.nix +++ b/pkgs/etc-profiles/default.nix @@ -1,63 +1,103 @@ -{ self, inputs, lib, buildEnv, runCommand, bash, coreutils, hostPlatform, system }: +# ============================================================================ # +# +# Creates a starter `/etc/profile' that aggregates +# `/etc/profile.d/*.sh' "child scripts". +# +# ---------------------------------------------------------------------------- # +{ self, inputs, lib, config, bash, coreutils, hostPlatform, system }: let -let - pname = "etc-profiles"; - version = "0.1.0-${lib.flox-floxpkgs.getRev self}"; - src = self; - ld-floxlib = inputs.ld-floxlib.packages.ld-floxlib; +# ---------------------------------------------------------------------------- # - splitSname = script: let - sname = baseNameOf script; - m = builtins.match "([^_]*)_(.*).sh" sname; - bname = builtins.elemAt m 1; - in { - inherit sname bname; - priority = builtins.head m; - pname = "profile-" + bname; + ldFloxlib = inputs.ld-floxlib.packages.ld-floxlib; + pname = "etc-profiles"; + version = "0.1.0-${lib.flox-floxpkgs.getRev self}"; + drv = derivation { + inherit pname version system ldFloxlib; + name = pname + "-" + version; + builder = bash.outPath + "/bin/bash"; + outputs = ["common_paths" "node" "python3" "out"]; + profile = builtins.path { path = ( toString self ) + "/profile"; }; + profile_d = builtins.path { path = ( toString self ) + "/profile.d"; }; + PATH = coreutils.outPath + "/bin"; + args = ["-eu" "-o" "pipefail" "-c" '' + mkdir -p "$out/etc" \ + "$out/lib" \ + "$common_paths/etc/profile.d" \ + "$node/etc/profile.d" \ + "$python3/etc/profile.d" \ + ; + cp -- "$profile" "$out/etc/profile"; + ${if ! hostPlatform.isLinux then "" else '' + ln -s -- "$ldFloxlib/lib/"* "$out/lib/"; + '' + } + cp -- "$profile_d/0100_common-paths.sh" "$common_paths/etc/profile.d/"; + cp -- "$profile_d/0500_node.sh" "$node/etc/profile.d/"; + cp -- "$profile_d/0500_python3.sh" "$python3/etc/profile.d/"; + '']; }; - base = import ./base.nix { - inherit self version bash coreutils hostPlatform ld-floxlib lib system; - }; - mkEtcProfile = import ./mk-profile.nix { - inherit bash coreutils system; - version = base.version; - }; +# --------------------------------------------------------------------------- # - mkProfileLocal = { - script - , description ? null - , longDescription ? null - , ... - } @ args: let - ss = splitSname script; +in drv // { + meta = let + lfm = ldFloxlib.meta or {}; + license = lib.licenses.mit; + # Inherit broken from `ld-floxlib' + broken = if hostPlatform.isLinux then ( lfm.broken or false ) else false; + platforms = [ + "x86_64-linux" "aarch64-linux" "i686-linux" + "x86_64-darwin" "aarch64-darwin" + ]; + unsupported = ! ( builtins.elem hostPlatform.system platforms ); + unfree = ! license.free; in { - name = lib.replaceStrings ["-"] ["_"] ss.bname; - value = lib.makeOverridable mkEtcProfile ( - ( removeAttrs ss ["bname"] ) // args - ); - }; + inherit (drv) name; + inherit license broken platforms unfree unsupported; + available = ( config.allowBroken || ( ! broken ) ) && + ( config.allowUnfree || ( ! unfree ) ) && + ( config.allowUnsupportedSystem || ( ! unsupported ) ); + homepage = "https://github.com/flox/etc-profiles"; + outputsToInstall = ["common_paths" "python3" "node" "out"]; + description = '' + Installable /etc/profile.d activation scripts for use with flox + ''; + longDescription = '' + An `/etc/profile' script to source `/etc/profile.d/*.sh` - profiles = builtins.listToAttrs ( map mkProfileLocal [ - { script = src + "/profile.d/0100_common-paths.sh"; } - { script = src + "/profile.d/0500_node.sh"; } - { script = src + "/profile.d/0500_python3.sh"; } - ] ); + Users can define and install scripts in `/etc/profile.d' as + "custom packages"/installables to share common setup processes + across environments. - etcProfiles = buildEnv { - name = pname + "-" + version; - paths = [ base ] ++ (builtins.attrValues profiles); + Recommended usage: + # flox.nix + { + packages.nixpkgs-flox.sqlite = { + meta.outputsToInstall = ["bin" "out" "dev"]; + }; + + # Provides developer environment hooks for use with python3. + packages.flox.etc-profiles = { + # Optionally, specify language packages to install. + # Please note that all/most language packs depend on including + # the "common_paths" output, and ALL depend on "out". + meta.outputsToInstall = ["out" "common_paths" "python3"]; + }; + + shell.hook = '${""}' + [[ -r "$FLOX_ENV/etc/profile" ]] && . "$FLOX_ENV/etc/profile"; + pkg-config --list-all >&2; + '${""}' + } + ''; }; +} + -in runCommand "etc-profiles.${version}" { - inherit pname version; - outputs = [ "out" "base" ] ++ (builtins.attrNames profiles); - meta.description = "Installable /etc/profile.d activation scripts for use with flox"; -} '' - cp -R -- ${etcProfiles}/. $out - cp -R -- ${base}/. $base - ${lib.concatStringsSep "\n" (lib.mapAttrsToList (output: outpath: - "cp -R -- ${outpath}/. \$${output}") profiles)} -'' +# ---------------------------------------------------------------------------- # +# +# +# +# ============================================================================ # diff --git a/pkgs/etc-profiles/mk-profile.nix b/pkgs/etc-profiles/mk-profile.nix deleted file mode 100644 index 658513d..0000000 --- a/pkgs/etc-profiles/mk-profile.nix +++ /dev/null @@ -1,56 +0,0 @@ -# ============================================================================ # -# -# Creates a `/etc/profile.d/*.sh' script as an installable. -# -# ---------------------------------------------------------------------------- # - -let - prioToPrefix = p: let - pi = if builtins.isString p then builtins.fromJSON p else p; - ps = if builtins.isString p then p else toString p; - in if p == null then "" else - if pi < 1000 then "000" + ps + "_" else - if pi < 100 then "00" + ps + "_" else - if pi < 10 then "0" + ps + "_" else - ps + "_"; - npp = p: let - m = builtins.match "profile-(.*)" p; - in if m == null then p else builtins.head m; -in -{ version, bash, coreutils, system }: -{ script -, pname -, priority ? null # Integer 0-9999 or `null' -, sname ? ( prioToPrefix priority ) + ( npp pname ) -, description ? "An `/etc/profile.d/*.sh` script managing ${npp pname}." -, longDescription ? description -, platforms ? [ - "x86_64-linux" "aarch64-linux" "i686-linux" - "x86_64-darwin" "aarch64-darwin" - ] -}: ( derivation { - inherit system pname script sname; - name = pname + "-" + version; - builder = bash.outPath + "/bin/bash"; - PATH = coreutils.outPath + "/bin"; - args = let - profile_d = builtins.path { path = ./profile.d; }; - in ["-eu" "-o" "pipefail" "-c" '' - mkdir -p "$out/etc/profile.d"; - cp -- "$script" "$out/etc/profile.d/$sname"; - '']; - preferLocalBuild = true; - allowSubstitutes = system == ( builtins.currentSystem or null ); -} ) // { - meta = { - inherit description longDescription platforms; - outputsToInstall = ["out"]; - }; -} - - -# ---------------------------------------------------------------------------- # -# -# -# -# ============================================================================ #