{"id":16343236,"url":"https://github.com/fricklerhandwerk/attr-cmd","last_synced_at":"2025-03-20T23:32:04.111Z","repository":{"id":221775946,"uuid":"755357243","full_name":"fricklerhandwerk/attr-cmd","owner":"fricklerhandwerk","description":"Build shell commands from Nix attribute sets.","archived":false,"fork":false,"pushed_at":"2024-05-23T01:47:04.000Z","size":34,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-12T00:24:02.748Z","etag":null,"topics":["nix","nix-shell"],"latest_commit_sha":null,"homepage":"","language":"Nix","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fricklerhandwerk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-10T00:40:24.000Z","updated_at":"2024-05-23T01:42:59.000Z","dependencies_parsed_at":"2024-02-14T15:26:15.754Z","dependency_job_id":"cc231037-6cf8-44df-b1aa-361feda19133","html_url":"https://github.com/fricklerhandwerk/attr-cmd","commit_stats":null,"previous_names":["fricklerhandwerk/attr-cmd"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fricklerhandwerk%2Fattr-cmd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fricklerhandwerk%2Fattr-cmd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fricklerhandwerk%2Fattr-cmd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fricklerhandwerk%2Fattr-cmd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fricklerhandwerk","download_url":"https://codeload.github.com/fricklerhandwerk/attr-cmd/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221810165,"owners_count":16884059,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nix","nix-shell"],"created_at":"2024-10-11T00:23:50.495Z","updated_at":"2024-10-28T08:53:00.710Z","avatar_url":"https://github.com/fricklerhandwerk.png","language":"Nix","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `attr-cmd`\nBuild shell commands from Nix attribute sets.\n\n## `lib.attr-cmd.exec`\n\n    exec :: AttrSet -\u003e AttrSet\n\n`exec` transforms a nested attribute set `\u003cinput\u003e` into a flat attribute set `\u003coutput\u003e`.\nFor each attribute `\u003cattr\u003e` of `\u003cinput\u003e` at the [attribute path](https://nix.dev/manual/nix/stable/language/operators.html#attribute-selection) `\u003croot\u003e . [...] . \u003cattr\u003e` that evaluates to a [derivation](https://nix.dev/manual/nix/stable/language/derivations), it creates an attribute `\u003croot\u003e` in `\u003coutput\u003e`.\nAll other attribute paths are ignored.\n\n\u003e **Example**\n\u003e\n\u003e ### Transformation of attributes\n\u003e\n\u003e ```nix\n\u003e { lib, attr-cmd }:\n\u003e let\n\u003e   input = {\n\u003e     a.b.c = drv;\n\u003e     d.e.f = drv';\n\u003e     g.h.i = \"ignored\";\n\u003e   };\n\u003e   output = attr-cmd.exec input;\n\u003e in\n\u003e {\n\u003e   inherit = output;\n\u003e   executable = lib.getExe output.a;\n\u003e }\n\u003e ```\n\u003e\n\u003e ```console\n\u003e { output = { a = drv''; d = drv'''; }; executable = \"/nix/store/...-a/bin/a\"}\n\u003e ```\n\u003e\n\nEach attribute `\u003croot\u003e` in `\u003coutput\u003e` is a derivation that produces an executable `/bin/\u003croot\u003e`.\nSuch an executable `\u003croot\u003e` accepts [command line words](https://www.gnu.org/software/bash/manual/bash.html#index-word) that correspond to attribute paths in `\u003cattrs-in\u003e` starting from `\u003croot\u003e`.\nThe final command line word `\u003cattr\u003e` executes the `meta.mainProgram` (or `/bin/\u003cattr\u003e`) from the derivation's `bin` (or `out`) [output](https://nix.dev/manual/nix/stable/language/derivations#attr-outputs) at the corresponding attribute `\u003cattr\u003e` from `\u003cinput\u003e`.\n\nAfter adding the derivations from `\u003coutput\u003e` to the environment, run the executable `\u003cattr\u003e` by specifying its attribute path as command line arguments:\n\n```console\n\u003croot\u003e ... \u003cattr\u003e [\u003carguments\u003e]...\n```\n\nHelp will be shown for intermediate subcommands, displaying `meta.description` on a derivation or attribute set if available.\n\n\u003e **Example**\n\u003e\n\u003e ### Create a command from a derivation in an attribute set\n\u003e\n\u003e Declare a nested attribute set `foo` with a derivation `baz` as a leaf attribute, and pass that attribute set to `attr-cmd`:\n\u003e\n\u003e ```nix\n\u003e # ./default.nix\n\u003e {\n\u003e   sources ? import ./npins,\n\u003e   system ? builtins.currentSystem,\n\u003e   pkgs ? import sources.nixpkgs { inherit system; config = { }; overlays = [ ]; },\n\u003e   attr-cmd ? pkgs.callPackage \"${sources.attr-cmd}/lib.nix\" {};\n\u003e }:\n\u003e let\n\u003e   lib = pkgs.lib // attr-cmd.lib\n\u003e lib\n\u003e rec {\n\u003e   foo.bar.baz = pkgs.writeScriptBin \"baz\" \"echo success $@\";\n\u003e   commands = lib.attr-cmd.exec { inherit foo; }; ;\n\u003e   shell = pkgs.mkShellNoCC {\n\u003e     packages = builtins.attrValues commands ++ [\n\u003e       pkgs.npins\n\u003e     ];\n\u003e   };\n\u003e }\n\u003e ```\n\u003e\n\u003e The values of the resulting attribute set `commands` are now derivations that create executables:\n\u003e\n\u003e ```shell-session\n\u003e $ nix-shell -p npins --run \"npins init\"\n\u003e $ nix-shell\n\u003e [nix-shell:~]$ foo bar baz\n\u003e success\n\u003e [nix-shell:~]$ foo bar baz or else\n\u003e success or else\n\u003e ```\n\u003e\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffricklerhandwerk%2Fattr-cmd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffricklerhandwerk%2Fattr-cmd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffricklerhandwerk%2Fattr-cmd/lists"}