From 317bd54038d6b68b39ce27d946892ebe4bda2f8c Mon Sep 17 00:00:00 2001 From: sterni Date: Thu, 5 Dec 2024 16:09:39 +0100 Subject: chore(nix/build): rename to reduce redundancy in attr path Change-Id: Ibefb924bb329c2a9dc0ac8e5ee1566253300b5cf Reviewed-on: https://cl.tvl.fyi/c/depot/+/12872 Tested-by: BuildkiteCI Reviewed-by: sterni Autosubmit: sterni --- users/sterni/lv/gopher/default.nix | 2 +- users/sterni/nix/build/buildGopherHole/default.nix | 109 --------------------- users/sterni/nix/build/gopherHole/default.nix | 107 ++++++++++++++++++++ 3 files changed, 108 insertions(+), 110 deletions(-) delete mode 100644 users/sterni/nix/build/buildGopherHole/default.nix create mode 100644 users/sterni/nix/build/gopherHole/default.nix (limited to 'users/sterni') diff --git a/users/sterni/lv/gopher/default.nix b/users/sterni/lv/gopher/default.nix index f8f42c82d56f..e3bf450b5a76 100644 --- a/users/sterni/lv/gopher/default.nix +++ b/users/sterni/lv/gopher/default.nix @@ -1,6 +1,6 @@ { depot, ... }: -depot.users.sterni.nix.build.buildGopherHole { +depot.users.sterni.nix.build.gopherHole { name = "gopher-sterni.lv"; dir = [ "🚧 closed for construction 🚧" diff --git a/users/sterni/nix/build/buildGopherHole/default.nix b/users/sterni/nix/build/buildGopherHole/default.nix deleted file mode 100644 index eec13a865421..000000000000 --- a/users/sterni/nix/build/buildGopherHole/default.nix +++ /dev/null @@ -1,109 +0,0 @@ -{ depot, pkgs, lib, ... }: - -let - inherit (pkgs) - runCommand - writeText - ; - - inherit (depot.users.sterni.nix.build) - buildGopherHole - ; - - fileTypes = { - # RFC1436 - text = "0"; - menu = "1"; - cso = "2"; - error = "3"; - binhex = "4"; - dos = "5"; - uuencoded = "6"; - index-server = "7"; - telnet = "8"; - binary = "9"; - mirror = "+"; - gif = "g"; - image = "I"; - tn3270 = "T"; - # non-standard - info = "i"; - html = "h"; - }; - - buildFile = { file, name, fileType ? fileTypes.text }: - runCommand name - { - passthru = { - # respect the file type the file derivation passes - # through. otherwise use explicitly set type or - # default value. - fileType = file.fileType or fileType; - }; - } '' - ln -s ${file} "$out" - ''; - - buildGopherMap = dir: - let - /* strings constitute an info line or an empty line - if their length is zero. sets that contain a menu - value have that added to the gophermap as-is. - - all other entries should be a set which can be built using - buildGopherHole and is linked by their name. The resulting - derivation is expected to passthru a fileType containing the - gopher file type char of themselves. - */ - gopherMapLine = e: - if builtins.isString e - then e - else if e ? menu - then e.menu - else - let - drv = buildGopherHole e; - title = e.title or e.name; - in - "${drv.fileType}${title}\t${drv.name}"; - in - writeText ".gophermap" (lib.concatMapStringsSep "\n" gopherMapLine dir); - - buildDir = - { dir, name, ... }: - - let - # filter all entries out that have to be symlinked: - # sets with the file or dir attribute - drvOnly = builtins.map buildGopherHole (builtins.filter - (x: !(builtins.isString x) && (x ? dir || x ? file)) - dir); - gopherMap = buildGopherMap dir; - in - runCommand name - { - passthru = { - fileType = fileTypes.dir; - }; - } - ('' - mkdir -p "$out" - ln -s "${gopherMap}" "$out/.gophermap" - '' + lib.concatMapStrings - (drv: '' - ln -s "${drv}" "$out/${drv.name}" - '') - drvOnly); -in - -{ - # Dispatch into different file / dir handling code - # which is mutually recursive with this function. - __functor = _: args: - if args ? file then buildFile args - else if args ? dir then buildDir args - else builtins.throw "Unrecognized gopher hole item type: " - + lib.generators.toPretty { } args; - - inherit fileTypes; -} diff --git a/users/sterni/nix/build/gopherHole/default.nix b/users/sterni/nix/build/gopherHole/default.nix new file mode 100644 index 000000000000..65a6bd5f442e --- /dev/null +++ b/users/sterni/nix/build/gopherHole/default.nix @@ -0,0 +1,107 @@ +{ depot, pkgs, lib, ... }: + +let + inherit (pkgs) + runCommand + writeText + ; + + buildGopherHole = depot.users.sterni.nix.build.gopherHole; + + fileTypes = { + # RFC1436 + text = "0"; + menu = "1"; + cso = "2"; + error = "3"; + binhex = "4"; + dos = "5"; + uuencoded = "6"; + index-server = "7"; + telnet = "8"; + binary = "9"; + mirror = "+"; + gif = "g"; + image = "I"; + tn3270 = "T"; + # non-standard + info = "i"; + html = "h"; + }; + + buildFile = { file, name, fileType ? fileTypes.text }: + runCommand name + { + passthru = { + # respect the file type the file derivation passes + # through. otherwise use explicitly set type or + # default value. + fileType = file.fileType or fileType; + }; + } '' + ln -s ${file} "$out" + ''; + + buildGopherMap = dir: + let + /* strings constitute an info line or an empty line + if their length is zero. sets that contain a menu + value have that added to the gophermap as-is. + + all other entries should be a set which can be built using + buildGopherHole and is linked by their name. The resulting + derivation is expected to passthru a fileType containing the + gopher file type char of themselves. + */ + gopherMapLine = e: + if builtins.isString e + then e + else if e ? menu + then e.menu + else + let + drv = buildGopherHole e; + title = e.title or e.name; + in + "${drv.fileType}${title}\t${drv.name}"; + in + writeText ".gophermap" (lib.concatMapStringsSep "\n" gopherMapLine dir); + + buildDir = + { dir, name, ... }: + + let + # filter all entries out that have to be symlinked: + # sets with the file or dir attribute + drvOnly = builtins.map buildGopherHole (builtins.filter + (x: !(builtins.isString x) && (x ? dir || x ? file)) + dir); + gopherMap = buildGopherMap dir; + in + runCommand name + { + passthru = { + fileType = fileTypes.dir; + }; + } + ('' + mkdir -p "$out" + ln -s "${gopherMap}" "$out/.gophermap" + '' + lib.concatMapStrings + (drv: '' + ln -s "${drv}" "$out/${drv.name}" + '') + drvOnly); +in + +{ + # Dispatch into different file / dir handling code + # which is mutually recursive with this function. + __functor = _: args: + if args ? file then buildFile args + else if args ? dir then buildDir args + else builtins.throw "Unrecognized gopher hole item type: " + + lib.generators.toPretty { } args; + + inherit fileTypes; +} -- cgit 1.4.1