├── .github └── workflows │ └── all-tests.yml ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.org ├── builders ├── dist.nix ├── floco-builder.sh ├── tree.nix └── treeFromInfo.nix ├── check.sh ├── db ├── .gitignore ├── examples │ ├── pdefs.sql │ └── trees.sql ├── pdefs.sql └── trees.sql ├── doc ├── Makefile ├── guides │ ├── basic │ │ ├── bin.js │ │ ├── default.nix │ │ ├── index.ts │ │ ├── package-lock.json │ │ ├── package.json │ │ └── pdefs.nix │ ├── basic2 │ │ ├── bin.js │ │ ├── default.nix │ │ ├── floco-cfg.nix │ │ ├── foverrides.nix │ │ ├── index.ts │ │ ├── package-lock.json │ │ ├── package.json │ │ └── pdefs.nix │ ├── basic3 │ │ ├── bin.js │ │ ├── default.nix │ │ ├── floco-cfg.nix │ │ ├── foverrides.nix │ │ ├── index.ts │ │ ├── package-lock.json │ │ ├── package.json │ │ └── pdefs.nix │ ├── basics.org │ ├── gen-subs.org │ ├── gen-subs │ │ ├── default.nix │ │ ├── floco-cfg.nix │ │ ├── foverrides.nix │ │ ├── package.json │ │ └── pdefs.nix │ ├── module-system.org │ ├── multiple-projects.org │ ├── native-deps.org │ ├── native-deps │ │ ├── zeromq-5.3.1 │ │ │ ├── default.nix │ │ │ ├── floco-cfg.nix │ │ │ ├── foverrides.nix │ │ │ └── pdefs.nix │ │ └── zeromq-6.0.0-beta.16 │ │ │ ├── default.nix │ │ │ ├── floco-cfg.nix │ │ │ ├── foverrides.nix │ │ │ └── pdefs.nix │ ├── pdef-extension.org │ └── tree-info-strategies.org ├── modules │ ├── default.nix │ ├── formats.nix │ ├── gen-org.nix │ ├── make-options-doc.nix │ ├── options.nix │ └── top.org └── scripts │ ├── Makefile │ ├── README.org │ ├── from-registry.org │ ├── gen-docs.nix │ ├── install-module.org │ ├── npm-plock.org │ └── run-script.org ├── flake.lock ├── flake.nix ├── fpkgs ├── arborist │ ├── default.nix │ ├── floco-cfg.nix │ └── pdefs.nix ├── pacote │ ├── default.nix │ ├── floco-cfg.nix │ └── pdefs.nix ├── semver │ ├── default.nix │ ├── floco-cfg.nix │ └── pdefs.nix └── which │ ├── default.nix │ ├── floco-cfg.nix │ └── pdefs.nix ├── inputs ├── default.nix └── nixpkgs.nix ├── lib ├── access-pdefs.nix ├── checkSystemSupport.nix ├── closures.nix ├── default.nix ├── focus-tree.nix ├── graph │ ├── amat.nix │ ├── default.nix │ ├── hoisted.nix │ └── naive.nix ├── mdoc.nix ├── modules.nix ├── options.nix ├── overlay.lib.nix ├── paths.nix ├── pdef-filters.nix ├── sources.nix ├── trivial.nix ├── types.nix ├── types │ ├── depInfo │ │ ├── base.nix │ │ ├── default.nix │ │ ├── implementation.generic.nix │ │ └── serialize.nix │ ├── graph.nix │ ├── pdef.nix │ ├── pjsCore │ │ ├── default.nix │ │ └── submodule.nix │ ├── target │ │ └── default.nix │ └── topo.nix ├── update-pdef.nix ├── url-code.nix └── util.nix ├── modules ├── buildPlan │ ├── default.nix │ ├── implementation.nix │ └── interface.nix ├── configs │ └── use-fetchzip.nix ├── discover │ └── locals.nix ├── fetcher │ └── interface.nix ├── fetchers │ ├── composed │ │ ├── default.nix │ │ ├── implementation.nix │ │ └── interface.nix │ ├── default.nix │ ├── fetchTarballDrv │ │ ├── default.nix │ │ ├── implementation.nix │ │ └── interface.nix │ ├── fetchTree │ │ ├── default.nix │ │ ├── file │ │ │ ├── default.nix │ │ │ ├── implementation.nix │ │ │ └── interface.nix │ │ ├── git │ │ │ ├── default.nix │ │ │ ├── implementation.nix │ │ │ └── interface.nix │ │ ├── github │ │ │ ├── default.nix │ │ │ ├── implementation.nix │ │ │ └── interface.nix │ │ ├── implementation.nix │ │ ├── interface.nix │ │ └── tarball │ │ │ ├── default.nix │ │ │ ├── implementation.nix │ │ │ └── interface.nix │ ├── implementation.nix │ ├── interface.nix │ ├── path │ │ ├── default.nix │ │ ├── implementation.nix │ │ └── interface.nix │ └── types.nix ├── package │ ├── default.nix │ ├── implementation.nix │ ├── interface.nix │ ├── targets │ │ ├── built │ │ │ ├── default.nix │ │ │ ├── implementation.nix │ │ │ └── interface.nix │ │ ├── default.nix │ │ ├── implementation.nix │ │ ├── installed │ │ │ ├── default.nix │ │ │ ├── implementation.nix │ │ │ └── interface.nix │ │ ├── interface.nix │ │ └── source │ │ │ ├── default.nix │ │ │ ├── implementation.nix │ │ │ └── interface.nix │ └── trees │ │ ├── default.nix │ │ ├── implementation.nix │ │ └── interface.nix ├── packages │ ├── default.nix │ ├── implementation.nix │ └── interface.nix ├── packument │ ├── implementation.nix │ └── interface.nix ├── pdefs │ ├── default.nix │ ├── implementation.nix │ └── interface.nix ├── plock │ ├── default.nix │ ├── implementation.nix │ ├── interface.nix │ ├── plent │ │ └── interface.nix │ └── scope │ │ ├── implementation.nix │ │ └── interface.nix ├── plockToPdefs │ ├── default.nix │ ├── implementation.nix │ └── interface.nix ├── records │ ├── default.nix │ ├── implementation.nix │ ├── interface.nix │ ├── pdef │ │ ├── binInfo │ │ │ ├── default.nix │ │ │ ├── implementation.nix │ │ │ └── interface.nix │ │ ├── default.nix │ │ ├── deferred.nix │ │ ├── depInfo │ │ │ ├── default.nix │ │ │ └── implementation.nix │ │ ├── deserialize.nix │ │ ├── fsInfo │ │ │ ├── default.nix │ │ │ ├── implementation.nix │ │ │ └── interface.nix │ │ ├── implementation.nix │ │ ├── interface.nix │ │ ├── lifecycle │ │ │ ├── default.nix │ │ │ ├── implementation.nix │ │ │ └── interface.nix │ │ ├── peerInfo │ │ │ ├── default.nix │ │ │ ├── implementation.nix │ │ │ ├── interface.nix │ │ │ ├── single.implementation.nix │ │ │ └── single.interface.nix │ │ ├── sysInfo │ │ │ ├── default.nix │ │ │ ├── implementation.nix │ │ │ └── interface.nix │ │ └── treeInfo │ │ │ ├── default.nix │ │ │ ├── implementation.nix │ │ │ ├── interface.nix │ │ │ └── single.interface.nix │ └── pjsCore │ │ ├── default.nix │ │ └── module.nix ├── settings │ ├── default.nix │ ├── implementation.nix │ └── interface.nix ├── top │ ├── default.nix │ ├── implementation.nix │ └── interface.nix ├── topo │ ├── default.nix │ ├── implementation.nix │ └── interface.nix ├── vinfo │ ├── implementation.nix │ └── interface.nix ├── ylock │ ├── default.nix │ ├── implementation.nix │ ├── interface.nix │ └── types.nix └── ylockToPdefs │ └── implementation.nix ├── overlay.nix ├── pkgs ├── cli │ ├── default.nix │ ├── pkg-fun.nix │ ├── src │ │ ├── completion │ │ │ └── zsh │ │ │ │ └── _floco │ │ ├── lib │ │ │ ├── TEMPLATE.sh │ │ │ ├── common.sh │ │ │ ├── configs.sh │ │ │ ├── db.sh │ │ │ ├── dirs.sh │ │ │ ├── floco-cmd.sh │ │ │ ├── floco-ref.sh │ │ │ ├── fmt.sh │ │ │ ├── nix-system.sh │ │ │ └── search-up.sh │ │ ├── libexec │ │ │ └── nix-eval-wrapped.sh │ │ ├── main.sh │ │ ├── nix │ │ │ ├── common.nix │ │ │ ├── fromPlock.nix │ │ │ ├── fromRegistry.nix │ │ │ └── lib │ │ │ │ └── impure.nix │ │ ├── site-sql │ │ │ ├── pdefs.sql │ │ │ └── trees.sql │ │ └── tasks │ │ │ ├── build.sh │ │ │ ├── download.sh │ │ │ ├── edit.sh │ │ │ ├── list.sh │ │ │ ├── show.sh │ │ │ ├── translate-plock.sh │ │ │ └── translate-registry.sh │ └── test │ │ └── test-common.sh ├── get-packument │ └── get-packument.sh ├── lib │ ├── default.nix │ ├── semver │ │ ├── default.nix │ │ ├── intersects.nix │ │ ├── range-filt.nix │ │ ├── subset.nix │ │ └── valid.nix │ └── tree-for.nix ├── nix-plugin │ ├── .gitignore │ ├── default.nix │ ├── npm-fetcher.cc │ ├── npm-wrap.cc │ ├── parse.cc │ ├── parse.hh │ ├── pkg-fun.nix │ ├── progs.cc │ ├── progs.hh │ └── tests │ │ └── parse.cc └── treeFor │ ├── .gitignore │ ├── bin.js │ ├── default.nix │ ├── floco-cfg.nix │ ├── index.js │ ├── package.json │ └── pdefs.nix ├── setup ├── default.nix ├── functions │ ├── isScript │ └── unpatchShebang ├── hooks │ ├── add-nmdir.sh │ ├── default.nix │ ├── run-pjs-script.sh │ └── set-node-path.sh ├── install-module.sh ├── run-script.sh ├── show.sh └── unpatch-shebangs.sh ├── templates ├── basic │ ├── default.nix │ ├── floco-cfg.nix │ ├── foverrides.nix │ └── shell.nix └── registry │ ├── default.nix │ ├── floco-cfg.nix │ ├── foverrides.nix │ └── info.nix ├── tests ├── cli │ ├── show-extra.sh │ └── translate │ │ ├── local-mod1 │ │ ├── check.sh │ │ ├── floco-cfg.nix │ │ ├── foverrides.nix │ │ ├── package-2.json │ │ ├── package.json │ │ └── pdefs.nix │ │ ├── local1.sh │ │ └── remote1.sh ├── lib │ ├── check.sh │ ├── closures.nix │ ├── data │ │ ├── graph │ │ │ └── peers.nix │ │ ├── pacote │ │ │ ├── default.nix │ │ │ ├── floco-cfg.nix │ │ │ ├── foverrides.nix │ │ │ ├── info.nix │ │ │ └── pdefs.nix │ │ ├── proj0 │ │ │ ├── floco-cfg.nix │ │ │ └── pdefs.nix │ │ ├── proj1 │ │ │ ├── foverrides.nix │ │ │ ├── pdefs.json │ │ │ └── pdefs.nix │ │ └── proj2 │ │ │ └── pdefs.json │ ├── default.nix │ ├── sys.nix │ ├── tree │ │ ├── default.nix │ │ ├── hoist.nix │ │ └── naive.nix │ └── util.nix ├── modules │ ├── fetchInfo │ │ ├── fetchTarballDrv.nix │ │ ├── file.nix │ │ ├── path.nix │ │ └── tarball.nix │ ├── packages │ │ ├── check.sh │ │ ├── dist │ │ │ ├── check.sh │ │ │ ├── default.nix │ │ │ ├── floco-cfg.nix │ │ │ └── package.json │ │ ├── lodash.nix │ │ ├── nodePackage │ │ │ ├── bin.js │ │ │ ├── check.sh │ │ │ ├── default.nix │ │ │ ├── foverrides.nix │ │ │ ├── package.json │ │ │ └── pdefs.nix │ │ └── overrides │ │ │ ├── bin.js │ │ │ ├── default.nix │ │ │ ├── foverrides.nix │ │ │ ├── index.ts │ │ │ ├── package.json │ │ │ └── pdefs.nix │ ├── pdef │ │ ├── deserial │ │ │ ├── depInfoDefaults │ │ │ │ ├── default.nix │ │ │ │ ├── floco-cfg.nix │ │ │ │ ├── pdefs.nix │ │ │ │ └── test.nix │ │ │ └── noFetch │ │ │ │ ├── default.nix │ │ │ │ └── floco-cfg.nix │ │ └── from-registry.nix │ ├── pdefs │ │ └── pinned │ │ │ └── default.nix │ └── plock │ │ ├── babel │ │ ├── babel-core.nix │ │ ├── babel.core.package-lock.json │ │ └── package.json │ │ └── linked-locks │ │ ├── default.nix │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── proj0 │ │ ├── package-lock.json │ │ └── package.json │ │ └── proj1 │ │ ├── package-lock.json │ │ └── package.json ├── setup │ ├── lodash-install.nix │ ├── run-script.nix │ └── unpatch │ │ ├── script.sh │ │ ├── script2.sh │ │ └── script3.sh └── updaters │ ├── from-registry │ └── proj1.sh │ └── npm-plock │ └── proj1.sh └── updaters ├── default.nix ├── from-registry.sh └── npm-plock.sh /.gitignore: -------------------------------------------------------------------------------- 1 | result 2 | result-* 3 | .ccls-cache 4 | .ccls 5 | *.swp 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "doc/wiki"] 2 | path = doc/wiki 3 | url = https://github.com/aakropotkin/floco.wiki.git 4 | -------------------------------------------------------------------------------- /db/.gitignore: -------------------------------------------------------------------------------- 1 | *.db 2 | *.csv 3 | *.json 4 | pdefs.nix 5 | floco-cfg.nix 6 | foverrides.nix 7 | -------------------------------------------------------------------------------- /db/examples/pdefs.sql: -------------------------------------------------------------------------------- 1 | -- ========================================================================== -- 2 | -- 3 | -- NOTE: For relative paths to work PWD must be the `examples/' directory. 4 | -- 5 | -- -------------------------------------------------------------------------- -- 6 | 7 | .read ../pdefs.sql 8 | 9 | -- -------------------------------------------------------------------------- -- 10 | 11 | INSERT INTO pdefs ( 12 | key 13 | , ident 14 | , version 15 | , ltype 16 | , fetcher 17 | , fetchInfo 18 | , lifecycle_build 19 | , lifecycle_install 20 | ) VALUES 21 | ( 'lodash/4.17.21' -- key 22 | , 'lodash' -- ident 23 | , '4.17.21' -- version 24 | , 'file' -- ltype 25 | , 'composed' -- fetcher 26 | -- fetchInfo 27 | , '{"narHash":"sha256-amyN064Yh6psvOfLgcpktd5dRNQStUYHHoIqiI6DMek=","type":"tarball","url":"https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"}' 28 | , FALSE -- lifecycle_build 29 | , FALSE -- lifecycle_install 30 | ) 31 | , ( 'pacote/13.3.0' 32 | , 'pacote' 33 | , '13.3.0' 34 | , 'file' 35 | , 'composed' 36 | , '{"narHash":"sha256-RN8gBXHMJ9sekHLlVFBYhRf5iziJDFWmAxKw5mlAswA=","type":"tarball","url":"https://registry.npmjs.org/pacote/-/pacote-13.3.0.tgz"}' 37 | , FALSE 38 | , FALSE 39 | ) 40 | ; 41 | 42 | 43 | -- -------------------------------------------------------------------------- -- 44 | 45 | INSERT INTO depInfoEnts ( parent, ident, descriptor, runtime ) VALUES 46 | ( 'pacote/13.3.0', 'lodash', '^4.17.0', TRUE ) 47 | ; 48 | 49 | 50 | -- -------------------------------------------------------------------------- -- 51 | -- 52 | -- 53 | -- 54 | -- ========================================================================== -- 55 | -------------------------------------------------------------------------------- /db/examples/trees.sql: -------------------------------------------------------------------------------- 1 | -- ========================================================================== -- 2 | -- 3 | -- NOTE: For relative paths to work PWD must be the `examples/' directory. 4 | -- 5 | -- -------------------------------------------------------------------------- -- 6 | 7 | .read ../trees.sql 8 | 9 | -- -------------------------------------------------------------------------- -- 10 | 11 | INSERT OR REPLACE INTO treeInfo( parent ) VALUES ( 'pacote/13.3.0' ); 12 | 13 | INSERT OR REPLACE INTO treeInfoEnts( treeId, path, key ) VALUES 14 | ( ( SELECT treeId FROM treeInfo LIMIT 1 ), '', 'pacote/13.3.0' ) 15 | , ( ( SELECT treeId FROM treeInfo LIMIT 1 ) 16 | , 'node_modules/lodash', 'lodash/4.17.21' ) 17 | ; 18 | 19 | 20 | -- -------------------------------------------------------------------------- -- 21 | -- 22 | -- 23 | -- 24 | -- ========================================================================== -- 25 | -------------------------------------------------------------------------------- /doc/guides/basic/bin.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | // bin.js 3 | require( './index.js' ); 4 | -------------------------------------------------------------------------------- /doc/guides/basic/default.nix: -------------------------------------------------------------------------------- 1 | # default.nix 2 | # ============================================================================ # 3 | # 4 | # Package shim exposing installable targets from `floco' modules. 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | { floco ? builtins.getFlake ( toString ../../.. ) 9 | , lib ? floco.lib 10 | , system ? builtins.currentSystem 11 | }: let 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | fmod = lib.evalModules { 16 | modules = [ 17 | floco.nixosModules.floco 18 | # Loads our generated `pdefs.nix' as a "module config". 19 | ./pdefs.nix 20 | ( { config, ... }: { 21 | config.floco.settings = { inherit system; basedir = ./.; }; 22 | config.floco.packages."@floco/test"."4.2.0".built.extraBuildInputs = [ 23 | config.floco.packages.typescript."4.9.5".global 24 | ]; 25 | } ) 26 | ]; 27 | }; 28 | 29 | 30 | # ---------------------------------------------------------------------------- # 31 | 32 | # This attrset holds a few derivations related to our package. 33 | # We'll expose these below to the CLI. 34 | pkg = fmod.config.floco.packages."@floco/test"."4.2.0"; 35 | 36 | # ---------------------------------------------------------------------------- # 37 | 38 | in { 39 | inherit (pkg) 40 | dist # A tarball form of our built package suitable for publishing 41 | prepared # The "prepared" form of our project for use by other Nix builds 42 | global # A globally installed form to run our executable 43 | ; 44 | # Our project in it's "built" state 45 | built = pkg.built.package; 46 | } 47 | 48 | 49 | # ---------------------------------------------------------------------------- # 50 | # 51 | # 52 | # 53 | # ============================================================================ # 54 | -------------------------------------------------------------------------------- /doc/guides/basic/index.ts: -------------------------------------------------------------------------------- 1 | // index.ts 2 | import { 3 | VERSION, flatten, isEqual, last, omit, pick, pickBy, uniq 4 | } from 'lodash'; 5 | 6 | const f : Array = flatten( [[1, 2], [3, 4]] ); 7 | console.log( f ); 8 | const l : number = last( [1, 2, 3, 4] ) 9 | console.log( l ); 10 | const u : Array = uniq( [1, 2, 3, 1, 2, 3, 2] ); 11 | console.log( u ); 12 | console.log( VERSION ); 13 | -------------------------------------------------------------------------------- /doc/guides/basic/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/test", 3 | "version": "4.2.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "@floco/test", 9 | "version": "4.2.0", 10 | "dependencies": { 11 | "lodash": "^4.17.21" 12 | }, 13 | "bin": { 14 | "test": "bin.js" 15 | }, 16 | "devDependencies": { 17 | "@types/lodash": "^4.14.191", 18 | "typescript": "^4.9.4" 19 | } 20 | }, 21 | "node_modules/@types/lodash": { 22 | "version": "4.14.191", 23 | "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.191.tgz", 24 | "integrity": "sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==", 25 | "dev": true 26 | }, 27 | "node_modules/lodash": { 28 | "version": "4.17.21", 29 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", 30 | "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" 31 | }, 32 | "node_modules/typescript": { 33 | "version": "4.9.4", 34 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", 35 | "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", 36 | "dev": true, 37 | "bin": { 38 | "tsc": "bin/tsc", 39 | "tsserver": "bin/tsserver" 40 | }, 41 | "engines": { 42 | "node": ">=4.2.0" 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /doc/guides/basic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/test", 3 | "version": "4.2.0", 4 | "bin": { 5 | "test": "./bin.js" 6 | }, 7 | "scripts": { 8 | "clean": "rm -rf ./node_modules ./index.js", 9 | "build": "tsc ./index.ts" 10 | }, 11 | "devDependencies": { 12 | "@types/lodash": "^4.14.191", 13 | "typescript": "^4.9.4" 14 | }, 15 | "dependencies": { 16 | "lodash": "^4.17.21" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /doc/guides/basic2/bin.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | // bin.js 3 | require( './index.js' ); 4 | -------------------------------------------------------------------------------- /doc/guides/basic2/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Aggregates configs making them available to `default.nix', `flake.nix', 4 | # or other projects that want to consume this module/package as a dependency. 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | { ... }: { 9 | imports = let 10 | ifExist = builtins.filter builtins.pathExists [ 11 | # Loads generated `pdefs.nix' as a "module config". 12 | ./pdefs.nix 13 | 14 | # Explicit config 15 | ./foverrides.nix 16 | ]; 17 | in ifExist ++ [ 18 | # CHANGEME: If you depend on other `floco' projects, you can import their 19 | # `floco-cfg.nix' files here to make those configs available. 20 | ]; 21 | } 22 | 23 | 24 | # ---------------------------------------------------------------------------- # 25 | # 26 | # 27 | # 28 | # ============================================================================ # 29 | -------------------------------------------------------------------------------- /doc/guides/basic2/index.ts: -------------------------------------------------------------------------------- 1 | // index.ts 2 | import { 3 | VERSION, flatten, isEqual, last, omit, pick, pickBy, uniq 4 | } from 'lodash'; 5 | 6 | const f : Array = flatten( [[1, 2], [3, 4]] ); 7 | console.log( f ); 8 | const l : number = last( [1, 2, 3, 4] ) 9 | console.log( l ); 10 | const u : Array = uniq( [1, 2, 3, 1, 2, 3, 2] ); 11 | console.log( u ); 12 | console.log( VERSION ); 13 | -------------------------------------------------------------------------------- /doc/guides/basic2/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/test", 3 | "version": "4.2.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "@floco/test", 9 | "version": "4.2.0", 10 | "dependencies": { 11 | "lodash": "^4.17.21" 12 | }, 13 | "bin": { 14 | "test": "bin.js" 15 | }, 16 | "devDependencies": { 17 | "@types/lodash": "^4.14.191", 18 | "typescript": "^4.9.4" 19 | } 20 | }, 21 | "node_modules/@types/lodash": { 22 | "version": "4.14.191", 23 | "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.191.tgz", 24 | "integrity": "sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==", 25 | "dev": true 26 | }, 27 | "node_modules/lodash": { 28 | "version": "4.17.21", 29 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", 30 | "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" 31 | }, 32 | "node_modules/typescript": { 33 | "version": "4.9.4", 34 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", 35 | "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", 36 | "dev": true, 37 | "bin": { 38 | "tsc": "bin/tsc", 39 | "tsserver": "bin/tsserver" 40 | }, 41 | "engines": { 42 | "node": ">=4.2.0" 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /doc/guides/basic2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/test", 3 | "version": "4.2.0", 4 | "bin": { 5 | "test": "./bin.js" 6 | }, 7 | "scripts": { 8 | "clean": "rm -rf ./node_modules ./index.js", 9 | "build": "tsc ./index.ts" 10 | }, 11 | "devDependencies": { 12 | "@types/lodash": "^4.14.191", 13 | "typescript": "^4.9.4" 14 | }, 15 | "dependencies": { 16 | "lodash": "^4.17.21" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /doc/guides/basic3/bin.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | // bin.js 3 | require( './index.js' ); 4 | -------------------------------------------------------------------------------- /doc/guides/basic3/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Aggregates configs making them available to `default.nix', `flake.nix', 4 | # or other projects that want to consume this module/package as a dependency. 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | { ... }: { 9 | imports = let 10 | ifExist = builtins.filter builtins.pathExists [ 11 | ./pdefs.nix # Generated `pdefs.nix' 12 | ./foverrides.nix # Explicit config 13 | ]; 14 | in ifExist ++ [ 15 | # CHANGEME: If you depend on other `floco' projects, you can import their 16 | # `floco-cfg.nix' files here to make those configs available. 17 | ]; 18 | 19 | config.floco.buildPlan.deriveTreeInfo = true; 20 | } 21 | 22 | 23 | # ---------------------------------------------------------------------------- # 24 | # 25 | # 26 | # 27 | # ============================================================================ # 28 | -------------------------------------------------------------------------------- /doc/guides/basic3/index.ts: -------------------------------------------------------------------------------- 1 | // index.ts 2 | import { 3 | VERSION, flatten, isEqual, last, omit, pick, pickBy, uniq 4 | } from 'lodash'; 5 | 6 | const f : Array = flatten( [[1, 2], [3, 4]] ); 7 | console.log( f ); 8 | const l : number = last( [1, 2, 3, 4] ) 9 | console.log( l ); 10 | const u : Array = uniq( [1, 2, 3, 1, 2, 3, 2] ); 11 | console.log( u ); 12 | console.log( VERSION ); 13 | -------------------------------------------------------------------------------- /doc/guides/basic3/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/test", 3 | "version": "4.2.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "@floco/test", 9 | "version": "4.2.0", 10 | "dependencies": { 11 | "lodash": "^4.17.21" 12 | }, 13 | "bin": { 14 | "test": "bin.js" 15 | }, 16 | "devDependencies": { 17 | "@types/lodash": "^4.14.191", 18 | "typescript": "^4.9.4" 19 | } 20 | }, 21 | "node_modules/@types/lodash": { 22 | "version": "4.14.191", 23 | "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.191.tgz", 24 | "integrity": "sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==", 25 | "dev": true 26 | }, 27 | "node_modules/lodash": { 28 | "version": "4.17.21", 29 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", 30 | "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" 31 | }, 32 | "node_modules/typescript": { 33 | "version": "4.9.4", 34 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", 35 | "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", 36 | "dev": true, 37 | "bin": { 38 | "tsc": "bin/tsc", 39 | "tsserver": "bin/tsserver" 40 | }, 41 | "engines": { 42 | "node": ">=4.2.0" 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /doc/guides/basic3/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/test", 3 | "version": "4.2.0", 4 | "bin": { 5 | "test": "./bin.js" 6 | }, 7 | "scripts": { 8 | "clean": "rm -rf ./node_modules ./index.js", 9 | "build": "tsc ./index.ts" 10 | }, 11 | "devDependencies": { 12 | "@types/lodash": "^4.14.191", 13 | "typescript": "^4.9.4" 14 | }, 15 | "dependencies": { 16 | "lodash": "^4.17.21" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /doc/guides/gen-subs/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | { imports = [./pdefs.nix ./foverrides.nix]; } 2 | -------------------------------------------------------------------------------- /doc/guides/gen-subs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/phony", 3 | "version": "4.2.0", 4 | "devDependencies": { 5 | "@babel/core": "7.20.12" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /doc/guides/native-deps/zeromq-5.3.1/default.nix: -------------------------------------------------------------------------------- 1 | { floco ? builtins.getFlake "github:aakropotkin/floco" 2 | , lib ? floco.lib 3 | , system ? builtins.currentSystem 4 | , ... 5 | }: let 6 | mod = lib.evalModules { 7 | modules = [ 8 | floco.nixosModules.default 9 | ./floco-cfg.nix 10 | { floco.settings = { inherit system; }; } 11 | ]; 12 | }; 13 | in mod.config.floco.packages.zeromq."5.3.1".global 14 | 15 | -------------------------------------------------------------------------------- /doc/guides/native-deps/zeromq-5.3.1/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | { imports = [./pdefs.nix ./foverrides.nix]; } 2 | -------------------------------------------------------------------------------- /doc/guides/native-deps/zeromq-5.3.1/foverrides.nix: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /doc/guides/native-deps/zeromq-6.0.0-beta.16/default.nix: -------------------------------------------------------------------------------- 1 | { floco ? builtins.getFlake "github:aakropotkin/floco" 2 | , lib ? floco.lib 3 | , system ? builtins.currentSystem 4 | , ... 5 | }: let 6 | mod = lib.evalModules { 7 | modules = [ 8 | floco.nixosModules.default 9 | ./floco-cfg.nix 10 | { floco.settings = { inherit system; }; } 11 | ]; 12 | }; 13 | in mod.config.floco.packages.zeromq."6.0.0-beta.16".global 14 | -------------------------------------------------------------------------------- /doc/guides/native-deps/zeromq-6.0.0-beta.16/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | { imports = [./pdefs.nix ./foverrides.nix]; } 2 | -------------------------------------------------------------------------------- /doc/guides/native-deps/zeromq-6.0.0-beta.16/foverrides.nix: -------------------------------------------------------------------------------- 1 | { 2 | config.floco.packages.zeromq."6.0.0-beta.16".installed = { pkgs, ... }: { 3 | 4 | config.extraBuildInputs = let 5 | in [ 6 | # Always add this one. 7 | pkgs.zeromq 8 | ] ++ ( if ! pkgs.stdenv.hostPlatform.isDarwin then [] else [ 9 | # Only add these for when the host system is `darwin'. 10 | pkgs.pkg-config 11 | pkgs.libsodium.dev 12 | ] ); 13 | 14 | # Setting `override' attrs causes them to be set on the underlying 15 | # derivation, which then get set as environment variables in the 16 | # sandbox where we run out install. 17 | # We want to tell `node-gyp' to look for the shared `libzmq', so we'll 18 | # set the variable we found in their `binding.gyp' file. 19 | # XXX: You must quote "true" because `binding.gyp' expects a string, 20 | # and a Nix boolean of `false' gets stringized as the empty string. 21 | config.override.npm_config_zmq_shared = "true"; 22 | config.override.ARCH = 23 | if pkgs.stdenv.hostPlatform.isx86_64 then "x86_64" else "arm64"; 24 | }; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /doc/modules/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { nixpkgs ? ( import ../../inputs ).nixpkgs.flake 8 | , lib ? import ../../lib { inherit (nixpkgs) lib; } 9 | , system ? builtins.currentSystem 10 | , pkgsFor ? nixpkgs.legacyPackages.${system} 11 | , pandoc ? pkgsFor.pandoc 12 | , bash ? pkgsFor.bash 13 | }: let 14 | 15 | # ---------------------------------------------------------------------------- # 16 | 17 | # docbook, html, markdown, org 18 | formats = import ./formats.nix { 19 | inherit nixpkgs lib system pkgsFor pandoc bash; 20 | }; 21 | 22 | options = import ./options.nix { inherit nixpkgs lib system pkgsFor; }; 23 | 24 | 25 | # ---------------------------------------------------------------------------- # 26 | 27 | in builtins.mapAttrs ( _: f: f { 28 | bname = "floco-modules"; 29 | inherit options; 30 | } ) formats 31 | 32 | 33 | # ---------------------------------------------------------------------------- # 34 | # 35 | # 36 | # 37 | # ============================================================================ # 38 | -------------------------------------------------------------------------------- /doc/modules/gen-org.nix: -------------------------------------------------------------------------------- 1 | let 2 | nixpkgs = ( import ../../inputs ).nixpkgs.flake; 3 | lib = import ../../lib { inherit (nixpkgs) lib; }; 4 | system = builtins.currentSystem; 5 | in lib.libdoc.renderOrgFile { 6 | options = removeAttrs ( lib.evalModules { 7 | modules = [../../modules/top { 8 | config._module.args.pkgs = nixpkgs.legacyPackages.${system}; 9 | }]; 10 | } ).options ["_module"]; 11 | } 12 | -------------------------------------------------------------------------------- /doc/modules/make-options-doc.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { nixpkgs ? ( import ../../inputs ).nixpkgs.flake 8 | , lib ? import ../../lib { inherit (nixpkgs) lib; } 9 | , system ? builtins.currentSystem 10 | , pkgsFor ? nixpkgs.legacyPackages.${system} 11 | , basedir ? toString ../.. 12 | , options 13 | }: import "${nixpkgs}/nixos/lib/make-options-doc" { 14 | inherit lib; 15 | pkgs = pkgsFor; 16 | options = removeAttrs options ["_module"]; 17 | transformOptions = optDoc: optDoc // { 18 | declarations = map ( builtins.replaceStrings [basedir] ["/floco"] ) 19 | optDoc.declarations; 20 | }; 21 | } 22 | 23 | 24 | # ---------------------------------------------------------------------------- # 25 | # 26 | # 27 | # 28 | # ============================================================================ # 29 | -------------------------------------------------------------------------------- /doc/modules/options.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { nixpkgs ? ( import ../../inputs ).nixpkgs.flake 8 | , lib ? import ../../lib { inherit (nixpkgs) lib; } 9 | , system ? builtins.currentSystem 10 | , pkgsFor ? nixpkgs.legacyPackages.${system}.extend ( import ../../overlay.nix ) 11 | }: let 12 | inherit ( lib.evalModules { 13 | modules = [ 14 | { 15 | config._module.args.pkgs = pkgsFor; 16 | config.floco.settings = { inherit system; }; 17 | config.floco.pdefs.lodash."4.17.21" = { 18 | ident = "lodash"; 19 | version = "4.17.21"; 20 | }; 21 | } 22 | ../../modules/top 23 | ]; 24 | specialArgs = { inherit lib; }; 25 | } ) options; 26 | in removeAttrs options ["_module"] 27 | 28 | 29 | # ---------------------------------------------------------------------------- # 30 | # 31 | # 32 | # 33 | # ============================================================================ # 34 | -------------------------------------------------------------------------------- /doc/scripts/Makefile: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL = all 2 | .PHONY: all clean org man FORCE 3 | 4 | SCRIPT_BNAMES = \ 5 | run-script \ 6 | install-module \ 7 | npm-plock \ 8 | from-registry 9 | 10 | NIX ?= nix 11 | CAT ?= cat 12 | RM ?= rm -f 13 | 14 | %.org: FORCE 15 | $(CAT) $$( \ 16 | $(NIX) build -f ./gen-docs.nix $*-org --no-link --print-out-paths; \ 17 | ) > $@ 18 | 19 | %.1: FORCE 20 | $(CAT) $$( \ 21 | $(NIX) build -f ./gen-docs.nix $*-man --no-link --print-out-paths; \ 22 | ) > $@ 23 | 24 | clean: FORCE 25 | $(RM) $(foreach s,$(SCRIPT_BNAMES),$(s).org $(s).1) 26 | 27 | org: $(foreach s,$(SCRIPT_BNAMES),$(s).org) 28 | 29 | man: $(foreach s,$(SCRIPT_BNAMES),$(s).1) 30 | 31 | all: org man 32 | -------------------------------------------------------------------------------- /doc/scripts/from-registry.org: -------------------------------------------------------------------------------- 1 | * NAME 2 | from-registry.sh - manual page for from-registry.sh 0.1.1 3 | 4 | * SYNOPSIS 5 | *floco* /update registry IDENT/[/@DESCRIPTOR=latest/] [/-o PDEFS-FILE/] 6 | [/-- NPM-FLAGS/...] 7 | 8 | * DESCRIPTION 9 | Generate a package from the =npm= registry including its full dep-graph. 10 | 11 | Dev. dependencies will be omitted from generated definitions. 12 | 13 | * OPTIONS 14 | - *-o*,--out-file PATH :: Path to write generated =pdef= records. 15 | Defaults to =PWD/pdefs.nix=. If the outfile already exists, it may be 16 | used to optimize translation, and will be backed up to =PDEFS-FILE~=. 17 | 18 | - *-j*,--json :: Export JSON instead of a Nix expression. 19 | 20 | - *--* NPM-FLAGS... :: Used to separate =floco update registry= flags 21 | from =npm= flags. 22 | 23 | * ENVIRONMENT 24 | - NIX :: Command used as =nix= executable. 25 | 26 | - NPM :: Command used as =npm= executable. 27 | 28 | - JQ :: Command used as =jq= executable. 29 | 30 | - SED :: Command used as =sed= executable. 31 | 32 | - REALPATH :: Command used as =realpath= executable. 33 | 34 | - MKTEMP :: Command used as =mktemp= executable. 35 | 36 | - FLAKE_REF :: Flake URI ref to use for =floco=. defaults to 37 | =github:aakropotkin/floco=. 38 | -------------------------------------------------------------------------------- /doc/scripts/npm-plock.org: -------------------------------------------------------------------------------- 1 | * NAME 2 | npm-plock.sh - manual page for npm-plock.sh 0.1.1 3 | 4 | * SYNOPSIS 5 | *floco* /update npm-plock /[/-l LOCK-DIR/] [/-o PDEFS-FILE/] [/-- 6 | NPM-FLAGS/...] 7 | 8 | * DESCRIPTION 9 | Update a =pdefs.nix= file using a =package-lock.json= v3 provided by 10 | =npm=. 11 | 12 | This script will trash any existing =node_modules/= trees, and if a 13 | =package-lock.json= file already exists, it will be updated to use the 14 | v3 schema as a side effect of this script. 15 | 16 | * OPTIONS 17 | - *-l*,--lock-dir PATH :: Path to directory containing 18 | =package[-lock].json=. This directory must contain a =package.json=, 19 | but need not contain a =package-lock.json=. Defaults to current 20 | working directory. 21 | 22 | - *-o*,--out-file PATH :: Path to write generated =pdef= records. 23 | Defaults to =/pdefs.nix=. If the outfile already exists, it 24 | may be used to optimize translation, and will be backed up to 25 | =PDEFS-FILE~=. 26 | 27 | - *-j*,--json :: Export JSON instead of a Nix expression. 28 | 29 | - *--* NPM-FLAGS... :: Used to separate =floco update npm-plock= flags 30 | from =npm= flags. 31 | 32 | * ENVIRONMENT 33 | - NIX :: Command used as =nix= executable. 34 | 35 | - NPM :: Command used as =npm= executable. 36 | 37 | - JQ :: Command used as =jq= executable. 38 | 39 | - SED :: Command used as =sed= executable. 40 | 41 | - REALPATH :: Command used as =realpath= executable. 42 | 43 | - FLAKE_REF :: Flake URI ref to use for =floco=. defaults to 44 | =github:aakropotkin/floco=. 45 | -------------------------------------------------------------------------------- /doc/scripts/run-script.org: -------------------------------------------------------------------------------- 1 | * NAME 2 | run-script.sh - manual page for run-script.sh 0.1.1 3 | 4 | * SYNOPSIS 5 | *run-script.sh* [/OPTIONS/] /SCRIPT-NAME /[/SCRIPT-NAMES/...] 6 | 7 | * DESCRIPTION 8 | Run one or more scripts from =package.json= in a wrapped runtime 9 | environment. This script must be run from a directory containing a 10 | =package.json= file. 11 | 12 | * OPTIONS 13 | - *-p*,--modify-path :: Force modification of =PATH= with bin 14 | directories 15 | 16 | - *-P*,--no-modify-path :: Do not modify =PATH= with bin directories 17 | 18 | - *-I*,--no-ignore-missing :: Throw an error if a script is undefined 19 | 20 | - *-i*,--ignore-missing :: Do not throw an error if a script is 21 | undefined 22 | 23 | - *-b*,--parent-bins :: Force searching up for bin directories 24 | 25 | - *-B*,--no-parent-bins :: Do not search up for bin directories 26 | 27 | - *-u*,--usage :: Print usage message to STDOUT 28 | 29 | - *-h*,--help :: Print this message to STDOUT 30 | 31 | - *-V*,--version :: Print version to STDOUT 32 | 33 | * ENVIRONMENT 34 | 35 | #+begin_quote 36 | The following environment variables may be used to locate various 37 | executables or in place of options/flags. 38 | 39 | Variables marked as "Bool" are treated as false when unset or set to the 40 | empty string, or true for any non-empty value. Flags will always take 41 | priority over environment variables. 42 | 43 | #+end_quote 44 | 45 | - NO_MODIFY_PATH :: Do not modify =PATH= with bin directories. ( Bool ) 46 | 47 | - NO_PARENT_BINS :: Do not search up for bin directories. ( Bool ) 48 | 49 | - IGNORE_MISSING :: Do not throw an error if a script is undefined. ( 50 | Bool ) 51 | 52 | - NODEJS :: Absolute path to =node= executable. 53 | 54 | - JQ :: Absolute path to =jq= executable. 55 | 56 | - BASH :: Absolute path to =bash= executable. 57 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "nixpkgs": { 4 | "locked": { 5 | "lastModified": 1689413807, 6 | "narHash": "sha256-exuzOvOhGAEKWQKwDuZAL4N8a1I837hH5eocaTcIbLc=", 7 | "owner": "NixOS", 8 | "repo": "nixpkgs", 9 | "rev": "46ed466081b9cad1125b11f11a2af5cc40b942c7", 10 | "type": "github" 11 | }, 12 | "original": { 13 | "id": "nixpkgs", 14 | "type": "indirect" 15 | } 16 | }, 17 | "root": { 18 | "inputs": { 19 | "nixpkgs": "nixpkgs" 20 | } 21 | } 22 | }, 23 | "root": "root", 24 | "version": 7 25 | } 26 | -------------------------------------------------------------------------------- /fpkgs/arborist/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Package shim exposing installable targets from `floco` modules. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { nixpkgs ? ( import ../../inputs ).nixpkgs.flake 8 | , lib ? import ../../lib { inherit (nixpkgs) lib; } 9 | , system ? builtins.currentSystem 10 | , pkgsFor ? nixpkgs.legacyPackages.${system} 11 | , nodePackage ? pkgsFor.nodejs 12 | , extraModules ? [] 13 | }: let 14 | 15 | # ---------------------------------------------------------------------------- # 16 | 17 | fmod = lib.evalModules { 18 | modules = [ 19 | ../../modules/top 20 | ../../modules/configs/use-fetchzip.nix 21 | { 22 | config._module.args.pkgs = pkgsFor; 23 | config.floco.settings = { inherit system nodePackage; }; 24 | } 25 | ./floco-cfg.nix 26 | ] ++ ( lib.toList extraModules ); 27 | }; 28 | 29 | 30 | # ---------------------------------------------------------------------------- # 31 | 32 | in fmod.config.floco.packages."@npmcli/arborist"."6.1.5".global 33 | 34 | 35 | # ---------------------------------------------------------------------------- # 36 | # 37 | # 38 | # 39 | # ============================================================================ # 40 | -------------------------------------------------------------------------------- /fpkgs/arborist/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [./pdefs.nix]; 3 | config.floco.buildPlan.deriveTreeInfo = true; 4 | } 5 | -------------------------------------------------------------------------------- /fpkgs/pacote/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Package shim exposing installable targets from `floco` modules. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { nixpkgs ? ( import ../../inputs ).nixpkgs.flake 8 | , lib ? import ../../lib { inherit (nixpkgs) lib; } 9 | , system ? builtins.currentSystem 10 | , pkgsFor ? nixpkgs.legacyPackages.${system} 11 | , nodePackage ? pkgsFor.nodejs 12 | , extraModules ? [] 13 | }: let 14 | 15 | # ---------------------------------------------------------------------------- # 16 | 17 | fmod = lib.evalModules { 18 | modules = [ 19 | ../../modules/top 20 | ../../modules/configs/use-fetchzip.nix 21 | { 22 | config._module.args.pkgs = pkgsFor; 23 | config.floco.settings = { inherit system nodePackage; }; 24 | } 25 | ./floco-cfg.nix 26 | ] ++ ( lib.toList extraModules ); 27 | }; 28 | 29 | 30 | # ---------------------------------------------------------------------------- # 31 | 32 | in fmod.config.floco.packages.pacote."13.3.0".global 33 | 34 | 35 | # ---------------------------------------------------------------------------- # 36 | # 37 | # 38 | # 39 | # ============================================================================ # 40 | -------------------------------------------------------------------------------- /fpkgs/pacote/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [./pdefs.nix]; 3 | config.floco.buildPlan.deriveTreeInfo = true; 4 | } 5 | -------------------------------------------------------------------------------- /fpkgs/semver/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Package shim exposing installable targets from `floco` modules. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { nixpkgs ? ( import ../../inputs ).nixpkgs.flake 8 | , lib ? import ../../lib { inherit (nixpkgs) lib; } 9 | , system ? builtins.currentSystem 10 | , pkgsFor ? nixpkgs.legacyPackages.${system} 11 | , nodePackage ? pkgsFor.nodejs 12 | , extraModules ? [] 13 | }: let 14 | 15 | # ---------------------------------------------------------------------------- # 16 | 17 | fmod = lib.evalModules { 18 | modules = [ 19 | ../../modules/top 20 | ../../modules/configs/use-fetchzip.nix 21 | { 22 | config._module.args.pkgs = pkgsFor; 23 | config.floco.settings = { inherit system; }; 24 | } 25 | ./floco-cfg.nix 26 | ] ++ ( lib.toList extraModules ); 27 | }; 28 | 29 | 30 | # ---------------------------------------------------------------------------- # 31 | 32 | in fmod.config.floco.packages.semver."7.3.8".global 33 | 34 | 35 | # ---------------------------------------------------------------------------- # 36 | # 37 | # 38 | # 39 | # ============================================================================ # 40 | -------------------------------------------------------------------------------- /fpkgs/semver/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [./pdefs.nix]; 3 | config.floco.buildPlan.deriveTreeInfo = true; 4 | } 5 | -------------------------------------------------------------------------------- /fpkgs/semver/pdefs.nix: -------------------------------------------------------------------------------- 1 | { 2 | floco.pdefs = { 3 | 4 | semver."7.3.8" = { 5 | binInfo = { 6 | binPairs = { 7 | semver = "bin/semver.js"; 8 | }; 9 | }; 10 | depInfo = { 11 | lru-cache = { 12 | descriptor = "^6.0.0"; 13 | runtime = true; 14 | }; 15 | }; 16 | fetchInfo = { 17 | narHash = "sha256-vqtjrIFs0Yw18hcdfShdL7BwyzqXdZ+K60Rp3oLNo/A="; 18 | type = "tarball"; 19 | url = "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz"; 20 | }; 21 | ident = "semver"; 22 | ltype = "file"; 23 | treeInfo."node_modules/lru-cache" = { 24 | key = "lru-cache/6.0.0"; 25 | link = true; 26 | }; 27 | version = "7.3.8"; 28 | }; 29 | 30 | lru-cache."6.0.0" = { 31 | depInfo = { 32 | yallist = { 33 | descriptor = "^4.0.0"; 34 | runtime = true; 35 | }; 36 | }; 37 | fetchInfo = { 38 | narHash = "sha256-lBc6340YZYAh1Numj5iz418ChtGb3UUtRZLOYj/WJXg="; 39 | type = "tarball"; 40 | url = "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz"; 41 | }; 42 | ident = "lru-cache"; 43 | ltype = "file"; 44 | version = "6.0.0"; 45 | treeInfo."node_modules/yallist" = { 46 | key = "yallist/4.0.0"; 47 | link = true; 48 | }; 49 | }; 50 | 51 | yallist."4.0.0" = { 52 | fetchInfo = { 53 | narHash = "sha256-JQNNkqswg1ZH4o8PQS2R8WsZWJtv/5R3vRgc4d1vDR0="; 54 | type = "tarball"; 55 | url = "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz"; 56 | }; 57 | ident = "yallist"; 58 | ltype = "file"; 59 | treeInfo = { }; 60 | version = "4.0.0"; 61 | }; 62 | 63 | }; 64 | } 65 | -------------------------------------------------------------------------------- /fpkgs/which/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Package shim exposing installable targets from `floco` modules. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { nixpkgs ? ( import ../../inputs ).nixpkgs.flake 8 | , lib ? import ../../lib { inherit (nixpkgs) lib; } 9 | , system ? builtins.currentSystem 10 | , pkgsFor ? nixpkgs.legacyPackages.${system} 11 | , extraModules ? [] 12 | }: let 13 | 14 | # ---------------------------------------------------------------------------- # 15 | 16 | fmod = lib.evalModules { 17 | modules = [ 18 | ../../modules/top 19 | ../../modules/configs/use-fetchzip.nix 20 | { 21 | config._module.args.pkgs = pkgsFor; 22 | config.floco.settings = { inherit system; }; 23 | } 24 | ./floco-cfg.nix 25 | ] ++ ( lib.toList extraModules ); 26 | }; 27 | 28 | 29 | # ---------------------------------------------------------------------------- # 30 | 31 | in floco.config.floco.packages.which."2.0.2".global 32 | 33 | 34 | # ---------------------------------------------------------------------------- # 35 | # 36 | # 37 | # 38 | # ============================================================================ # 39 | -------------------------------------------------------------------------------- /fpkgs/which/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [./pdefs.nix]; 3 | config.floco.buildPlan.deriveTreeInfo = true; 4 | } 5 | -------------------------------------------------------------------------------- /fpkgs/which/pdefs.nix: -------------------------------------------------------------------------------- 1 | { 2 | floco.pdefs = { 3 | 4 | isexe."2.0.0" = { 5 | ident = "isexe"; 6 | version = "2.0.0"; 7 | ltype = "file"; 8 | fetchInfo = { 9 | narHash = "sha256-l3Fv+HpHS6H1TqfC1WSGjsGlX08oDHyHdsEu9JQkvhE="; 10 | type = "tarball"; 11 | url = "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz"; 12 | }; 13 | treeInfo = { }; 14 | }; 15 | 16 | which."2.0.2" = { 17 | ident = "which"; 18 | version = "2.0.2"; 19 | ltype = "file"; 20 | binInfo.binPairs.node-which = "bin/node-which"; 21 | depInfo.isexe = { 22 | descriptor = "^2.0.0"; 23 | runtime = true; 24 | }; 25 | fetchInfo = { 26 | type = "tarball"; 27 | url = "https://registry.npmjs.org/which/-/which-2.0.2.tgz"; 28 | narHash = "sha256-u114pFUXCCiUamLVVZma0Au+didZhD6RCoGTbrh2OhU="; 29 | }; 30 | treeInfo."node_modules/isexe" = { 31 | key = "isexe/2.0.0"; 32 | link = true; 33 | }; 34 | }; 35 | 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /inputs/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | nixpkgs = import ./nixpkgs.nix; 3 | } 4 | -------------------------------------------------------------------------------- /inputs/nixpkgs.nix: -------------------------------------------------------------------------------- 1 | let 2 | lock = builtins.fromJSON ( builtins.readFile ../flake.lock ); 3 | nl = lock.nodes.nixpkgs.locked; 4 | uri = nl.type + ":" + nl.owner + "/" + nl.repo + "/" + nl.rev; 5 | in { 6 | inherit uri; 7 | flake = builtins.getFlake uri; 8 | tree = builtins.fetchTree nl; 9 | } 10 | -------------------------------------------------------------------------------- /lib/checkSystemSupport.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib }: { 8 | 9 | # FIXME: this doesn't handle `!' properly. 10 | checkSystemSupportFor = config: { 11 | stdenv ? throw "checkSystemSupport: You must pass an arg" 12 | , platform ? stdenv.hostPlatform 13 | , system ? platform.system 14 | }: let 15 | m = builtins.match "(.*)-([^-]+)" system; 16 | archPart = builtins.head m; 17 | archOk = let 18 | hasStar = builtins.elem "*" config.sysInfo.cpu; 19 | pn = builtins.partition ( lib.hasPrefix "!" ) config.sysInfo.cpu; 20 | hasMatch = builtins.elem archPart pn.wrong; 21 | hasNope = builtins.elem ( "!" + archPart ) pn.right; 22 | pred = assert ( ( builtins.length pn.right ) == 0 ) || 23 | ( ( builtins.length pn.wrong ) == 0 ); 24 | if ( builtins.length pn.right ) == 0 then hasMatch 25 | else ! hasNope; 26 | in hasStar || pred; 27 | osPart = builtins.elemAt m 1; 28 | osOk = let 29 | hasStar = builtins.elem "*" config.sysInfo.os; 30 | pn = builtins.partition ( lib.hasPrefix "!" ) config.sysInfo.os; 31 | hasMatch = builtins.elem archPart pn.wrong; 32 | hasNope = builtins.elem ( "!" + archPart ) pn.right; 33 | pred = assert ( ( builtins.length pn.right ) == 0 ) || 34 | ( ( builtins.length pn.wrong ) == 0 ); 35 | if ( builtins.length pn.right ) == 0 then hasMatch 36 | else ! hasNope; 37 | in hasStar || pred; 38 | in archOk && osOk; 39 | 40 | } 41 | 42 | # ---------------------------------------------------------------------------- # 43 | # 44 | # 45 | # 46 | # ============================================================================ # 47 | -------------------------------------------------------------------------------- /lib/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Nixpkgs libs extended with `libfloco' and other routines exposed 4 | # by `./overlay.lib.nix'. 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | { lib ? ( import ../inputs ).nixpkgs.flake.lib }: 9 | lib.extend ( import ./overlay.lib.nix ) 10 | 11 | 12 | # ---------------------------------------------------------------------------- # 13 | # 14 | # 15 | # 16 | # ============================================================================ # 17 | -------------------------------------------------------------------------------- /lib/graph/amat.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | nt = lib.types; 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | # Maps keys to an integer index in an adjacency matrix. 16 | mkKeyIndex = p: let 17 | pdefs = if ! ( builtins.isAttrs p ) then p else 18 | p.pdefs or p.floco.pdefs or p.config.floco.pdefs or p; 19 | pdl = if builtins.isList pdefs then pdefs else 20 | lib.libfloco.pdefsToList pdefs; 21 | mkEnt = i: let 22 | pdef = builtins.elemAt pdl i; 23 | in { 24 | name = pdef.key or ( pdef.ident + "/" + pdef.version ); 25 | value = i; 26 | }; 27 | index = 28 | builtins.listToAttrs ( builtins.genList mkEnt ( builtins.length pdl ) ); 29 | lookup = index: let 30 | keys = builtins.attrNames index; 31 | vals = builtins.attrValues index; 32 | in x: let 33 | forIdx = 34 | if x < ( builtins.length keys ) then builtins.elemAt vals x else null; 35 | key = x.key or ( ( x.ident or x.name ) + "/" + ( x.version or x.pin ) ); 36 | in if builtins.isString x then index.${x} or null else 37 | if builtins.isAttrs x then index.${key} or null else 38 | if builtins.isInt x then forIdx else throw ( 39 | "libfloco.keyIndex:lookup: expected string or integer but second" + 40 | "argument is of type '${builtins.typeOf x}'." 41 | ); 42 | in { 43 | inherit index; 44 | __functor = self: lookup self.index; 45 | }; 46 | 47 | 48 | # ---------------------------------------------------------------------------- # 49 | 50 | in { 51 | 52 | inherit 53 | mkKeyIndex 54 | ; 55 | 56 | } 57 | 58 | 59 | # ---------------------------------------------------------------------------- # 60 | # 61 | # 62 | # 63 | # ============================================================================ # 64 | -------------------------------------------------------------------------------- /lib/graph/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib }: 8 | ( import ./hoisted.nix { inherit lib; } ) 9 | // ( import ./naive.nix { inherit lib; } ) 10 | // ( import ./amat.nix { inherit lib; } ) 11 | 12 | 13 | # ---------------------------------------------------------------------------- # 14 | # 15 | # 16 | # 17 | # ============================================================================ # 18 | -------------------------------------------------------------------------------- /lib/graph/naive.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Implements `getChildReqs' and initializer for "naive" install strategy. 4 | # This file is paired with the interfaces defined in `./types/graph.nix'. 5 | # 6 | # This strategy isn't really recommended for real usage, but serves as the 7 | # simplest implementation of an install strategy. 8 | # 9 | # This strategy adds and dependencies that aren't satisfied by the parent scope 10 | # as children. 11 | # With that in mind it is somewhat similar to "hoisted", except that we do not 12 | # create a giant top-level scope upfront. 13 | # 14 | # This strategy can be useful as a helper function in more advanced strategies. 15 | # 16 | # 17 | # ---------------------------------------------------------------------------- # 18 | 19 | { lib }: let 20 | 21 | # ---------------------------------------------------------------------------- # 22 | 23 | in { 24 | 25 | getChildReqsBasic = { 26 | ident 27 | , version 28 | , path 29 | , depInfo 30 | , peerInfo 31 | , isRoot 32 | , needs ? if isRoot then depInfo else 33 | lib.libfloco.getRuntimeDeps { bundled = false; } depInfo 34 | , pscope ? node._module.args.pscope 35 | , ... 36 | } @ node: let 37 | keep = di: de: ( pscope.${di}.pin or null ) == de.pin; 38 | part = lib.partitionAttrs keep needs; 39 | bund = lib.libfloco.getDepsWith ( de: de.bundled or false ) depInfo; 40 | in { 41 | requires = builtins.intersectAttrs ( part.right // peerInfo ) pscope; 42 | children = builtins.mapAttrs ( ident: { pin, ... }: { 43 | inherit pin; 44 | path = lib.nmjoin path ident; 45 | } ) ( bund // part.wrong ); 46 | }; 47 | 48 | } 49 | 50 | 51 | # ---------------------------------------------------------------------------- # 52 | # 53 | # 54 | # 55 | # ============================================================================ # 56 | -------------------------------------------------------------------------------- /lib/types/depInfo/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib }: 8 | ( import ./base.nix { inherit lib; } ) // 9 | ( import ./implementation.generic.nix { inherit lib; } ) // { 10 | depInfoSerialize = import ./serialize.nix { inherit lib; }; 11 | } 12 | 13 | 14 | 15 | # ---------------------------------------------------------------------------- # 16 | # 17 | # 18 | # 19 | # ============================================================================ # 20 | -------------------------------------------------------------------------------- /lib/types/depInfo/serialize.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Serializes a `depInfo' record to prepare for writing to a file. 4 | # 5 | # `depInfo' is returned as a member of an attrset that can be merged with other 6 | # export data. 7 | # This allows `depInfo' to be omitted entirely if there are no dependencies. 8 | # 9 | # 10 | # ---------------------------------------------------------------------------- # 11 | 12 | { lib }: let 13 | 14 | # ---------------------------------------------------------------------------- # 15 | 16 | defaultEntry = { 17 | # descriptor = "*"; # Always preserve 18 | pin = null; 19 | optional = false; 20 | bundled = false; 21 | runtime = false; 22 | dev = true; 23 | devOptional = false; 24 | }; 25 | 26 | dropDefaults = entry: lib.filterAttrs ( k: v: 27 | ( ! ( defaultEntry ? ${k} ) ) || ( v != defaultEntry.${k} ) 28 | ) entry; 29 | 30 | 31 | # ---------------------------------------------------------------------------- # 32 | 33 | in depInfo: if depInfo == {} then {} else { 34 | depInfo = lib.mapAttrs ( name: entry: dropDefaults entry ) depInfo; 35 | } 36 | 37 | 38 | # ---------------------------------------------------------------------------- # 39 | # 40 | # 41 | # 42 | # ============================================================================ # 43 | -------------------------------------------------------------------------------- /lib/types/pjsCore/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # This is the "standard" for of a `pjsCore' record which summarizes "manifest" 4 | # fields found in `package.json' and similar files. 5 | # 6 | # This has been added as a `lib' member because of how common it is used in 7 | # extensions and custom translators. 8 | # 9 | # This implementation is the default used by `floco.records.pjsCore' which was 10 | # intentionally exposed as an overridable/extensible record in the 11 | # module system. 12 | # 13 | # For anyone who needs to extend this record to perform preprocessing or other 14 | # fixup during `translation' routines in modules - you will likely want to 15 | # "include" this record as a base or at least align your record with this 16 | # core collection of fields. 17 | # 18 | # ---------------------------------------------------------------------------- # 19 | 20 | { lib }: let 21 | 22 | # ---------------------------------------------------------------------------- # 23 | 24 | nt = lib.types; 25 | 26 | # ---------------------------------------------------------------------------- # 27 | 28 | pjsCoreDeferred = ./submodule.nix; 29 | 30 | pjsCore = nt.submodule pjsCoreDeferred; 31 | 32 | 33 | # ---------------------------------------------------------------------------- # 34 | 35 | in { 36 | 37 | inherit 38 | pjsCoreDeferred 39 | pjsCore 40 | ; 41 | 42 | mkPjsCoreOption = lib.mkOption { 43 | description = lib.mdDoc '' 44 | Project "manifest" information like those found in 45 | `package.json` and similar files, extended with `floco` specific 46 | "core" information such as `key` and `ident`. 47 | ''; 48 | type = pjsCore; 49 | }; 50 | 51 | } 52 | 53 | 54 | # ---------------------------------------------------------------------------- # 55 | # 56 | # 57 | # 58 | # ============================================================================ # 59 | -------------------------------------------------------------------------------- /lib/types/pjsCore/submodule.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib 8 | , config 9 | , ... 10 | }: let 11 | 12 | # ---------------------------------------------------------------------------- # 13 | 14 | nt = lib.types; 15 | 16 | # ---------------------------------------------------------------------------- # 17 | 18 | in { 19 | 20 | _file = "/types/pjsCore/submodule.nix"; 21 | 22 | imports = [( lib.mkAliasOptionModule ["name"] ["ident"] )]; 23 | 24 | options = { 25 | key = lib.mkKeyOption; 26 | ident = lib.mkIdentOption; 27 | version = lib.mkVersionOption; 28 | 29 | dependencies = lib.mkDepAttrsOption; 30 | devDependencies = lib.mkDepAttrsOption; 31 | devDependenciesMeta = lib.mkDepMetasOption; 32 | peerDependencies = lib.mkDepAttrsOption; 33 | peerDependenciesMeta = lib.mkDepMetasOption; 34 | optionalDependencies = lib.mkDepAttrsOption; 35 | bundledDependencies = lib.mkOption { 36 | type = nt.either nt.bool ( nt.listOf nt.str ); 37 | default = []; 38 | }; 39 | 40 | os = lib.mkOption { type = nt.listOf nt.str; default = ["*"]; }; 41 | cpu = lib.mkOption { type = nt.listOf nt.str; default = ["*"]; }; 42 | 43 | engines = lib.mkOption { 44 | type = nt.attrsOf nt.str; 45 | default = {}; 46 | example.node = ">=8.0.0"; 47 | }; 48 | 49 | bin = lib.mkPjsBinOption // { 50 | type = nt.coercedTo nt.str 51 | ( p: { ${baseNameOf config.ident} = p; } ) 52 | lib.libfloco.binPairs; 53 | }; 54 | 55 | }; 56 | 57 | config.key = lib.mkDefault ( config.ident + "/" + config.version ); 58 | 59 | 60 | } 61 | 62 | 63 | # ---------------------------------------------------------------------------- # 64 | # 65 | # 66 | # 67 | # ============================================================================ # 68 | -------------------------------------------------------------------------------- /modules/buildPlan/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/buildPlan"; 3 | imports = [ 4 | ../topo 5 | ./interface.nix ./implementation.nix 6 | ]; 7 | } 8 | -------------------------------------------------------------------------------- /modules/buildPlan/implementation.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, config, ... }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | nt = lib.types; 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | in { 16 | 17 | _file = "/buildPlan/implementation.nix"; 18 | 19 | #config.buildPlan.deriveTreeInfo = lib.mkDefault ( 20 | # config.topo.pdefsHavePins && config.topo.toposortedAll.isDAG 21 | #); 22 | 23 | } 24 | 25 | 26 | # ---------------------------------------------------------------------------- # 27 | # 28 | # 29 | # 30 | # ============================================================================ # 31 | -------------------------------------------------------------------------------- /modules/buildPlan/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | nt = lib.types; 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | in { 16 | 17 | _file = "/buildPlan/interface.nix"; 18 | 19 | options.buildPlan = lib.mkOption { 20 | description = lib.mdDoc '' 21 | Functions and metadata associated with build planning. 22 | ''; 23 | type = nt.submodule { 24 | options.deriveTreeInfo = lib.mkOption { 25 | description = lib.mdDoc '' 26 | Whether `floco` should attempt to derive `.treeInfo` records 27 | from pinned `.depInfo.*.pin` fields. 28 | 29 | This option should not be enabled if the build plan contains 30 | dependency cycles, unless explicit `treeInfo` records have been 31 | provided forall cycle members. 32 | ''; 33 | type = nt.bool; 34 | default = false; 35 | }; 36 | }; 37 | default = {}; 38 | }; 39 | 40 | } 41 | 42 | 43 | # ---------------------------------------------------------------------------- # 44 | # 45 | # 46 | # 47 | # ============================================================================ # 48 | -------------------------------------------------------------------------------- /modules/configs/use-fetchzip.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: { 2 | config.floco.fetchers.fetchTree_tarball.function = { 3 | type ? "tarball" 4 | , url 5 | , narHash ? ( builtins.fetchTree args ).narHash 6 | } @ args: let 7 | base = pkgs.fetchzip { 8 | inherit url; 9 | outputHash = narHash; 10 | outputHashAlgo = "sha256"; 11 | }; 12 | forLinux = base.overrideAttrs ( prev: { 13 | postFetch = '' 14 | unpackFile() { 15 | tar tf "$1"|xargs -i dirname '{}'|sort -u|xargs -i mkdir -p '{}'; 16 | tar --no-same-owner --delay-directory-restore \ 17 | --no-same-permissions --no-overwrite-dir \ 18 | -xf "$1" --warning=no-timestamp; 19 | } 20 | '' + prev.postFetch; 21 | } ); 22 | drv = if pkgs.stdenv.isLinux then forLinux else base; 23 | in drv // { inherit narHash; }; 24 | } 25 | -------------------------------------------------------------------------------- /modules/fetchers/composed/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/fetchers/composed"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/fetchers/composed/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Arguments used to fetch a source tree or file. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: { 8 | 9 | _file = "/fetchers/composed/interface.nix"; 10 | 11 | options.composed = lib.mkOption { 12 | description = lib.mdDoc '' 13 | Generic fetcher comprised of multiple sub-fetchers. 14 | ''; 15 | visible = "shallow"; 16 | }; 17 | 18 | } 19 | 20 | 21 | # ---------------------------------------------------------------------------- # 22 | # 23 | # 24 | # 25 | # ============================================================================ # 26 | -------------------------------------------------------------------------------- /modules/fetchers/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/fetchers"; 3 | imports = [ 4 | ../fetcher/interface.nix 5 | ./interface.nix ./implementation.nix 6 | ]; 7 | } 8 | -------------------------------------------------------------------------------- /modules/fetchers/fetchTarballDrv/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/fetchers/fetcher/fetchTarballDrv"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/fetchers/fetchTarballDrv/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Interface used to fetch a source tree or file. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: { 8 | 9 | _file = "/fetchers/fetcher/fetchTarballDrv/interface.nix"; 10 | 11 | options.fetchTarballDrv = lib.mkOption { 12 | description = lib.mdDoc "Derivation form of `nixpgkgs.fetchzip`."; 13 | visible = "shallow"; 14 | }; 15 | 16 | } 17 | 18 | 19 | # ---------------------------------------------------------------------------- # 20 | # 21 | # 22 | # 23 | # ============================================================================ # 24 | -------------------------------------------------------------------------------- /modules/fetchers/fetchTree/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/fetchers/fetchTree"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/fetchers/fetchTree/file/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/fetchers/fetcher/fetchTree/file"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/fetchers/fetchTree/file/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Arguments used to fetch a file. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: { 8 | 9 | _file = "/fetchers/fetcher/fetchTree/file/interface.nix"; 10 | 11 | options.fetchTree_file = lib.mkOption { 12 | description = lib.mdDoc "`builtins.fetchTree[file]` args"; 13 | visible = "shallow"; 14 | }; 15 | 16 | } 17 | 18 | 19 | # ---------------------------------------------------------------------------- # 20 | # 21 | # 22 | # 23 | # ============================================================================ # 24 | -------------------------------------------------------------------------------- /modules/fetchers/fetchTree/git/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/fetchers/fetcher/fetchTree/git"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/fetchers/fetchTree/git/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Arguments used to fetch a source tree using `git'. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: { 8 | 9 | _file = "/fetchers/fetcher/fetchTree/git/interface.nix"; 10 | 11 | options.fetchTree_git = lib.mkOption { 12 | description = lib.mdDoc "`builtins.fetchTree[git]` fetcher"; 13 | visible = "shallow"; 14 | }; 15 | 16 | } 17 | 18 | 19 | # ---------------------------------------------------------------------------- # 20 | # 21 | # 22 | # 23 | # ============================================================================ # 24 | -------------------------------------------------------------------------------- /modules/fetchers/fetchTree/github/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/fetchers/fetcher/fetchTree/github"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/fetchers/fetchTree/github/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Arguments used to fetch a source tree from github. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: { 8 | 9 | _file = "/fetchers/fetcher/fetchTree/github/interface.nix"; 10 | 11 | options.fetchTree_github = lib.mkOption { 12 | description = lib.mdDoc "`builtins.fetchTree[github]` fetcher"; 13 | visible = "shallow"; 14 | }; 15 | 16 | } 17 | 18 | 19 | # ---------------------------------------------------------------------------- # 20 | # 21 | # 22 | # 23 | # ============================================================================ # 24 | -------------------------------------------------------------------------------- /modules/fetchers/fetchTree/tarball/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/fetchers/fetcher/fetchTree/tarball"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/fetchers/fetchTree/tarball/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Arguments used to fetch a source tree or file. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: { 8 | 9 | _file = "/fetchers/fetcher/fetchTree/tarball/interface.nix"; 10 | 11 | options.fetchTree_tarball = lib.mkOption { 12 | description = lib.mdDoc "`builtins.fetchTree[tarball]` args"; 13 | visible = "shallow"; 14 | }; 15 | 16 | } 17 | 18 | 19 | # ---------------------------------------------------------------------------- # 20 | # 21 | # 22 | # 23 | # ============================================================================ # 24 | -------------------------------------------------------------------------------- /modules/fetchers/implementation.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, config, pkgs, ... }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | nt = lib.types; 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | in { 16 | 17 | # ---------------------------------------------------------------------------- # 18 | 19 | _file = "/fetchers/implementation.nix"; 20 | 21 | # ---------------------------------------------------------------------------- # 22 | 23 | options.fetchers = lib.mkOption { 24 | type = nt.submoduleWith { 25 | modules = [ 26 | ( { ... }: { 27 | 28 | _file = "/fetchers/implementation.nix"; 29 | 30 | freeformType = nt.attrsOf ( nt.submodule { 31 | imports = [config.fetcher]; 32 | } ); 33 | 34 | imports = [ 35 | ./path/implementation.nix 36 | ./fetchTree/implementation.nix 37 | ./fetchTarballDrv/implementation.nix 38 | ./composed/implementation.nix 39 | ]; 40 | 41 | config._module.args = { 42 | inherit (config) fetcher; 43 | pkgs = lib.mkDefault pkgs; 44 | }; 45 | 46 | } ) 47 | ]; 48 | }; 49 | default = {}; 50 | }; 51 | 52 | } 53 | 54 | 55 | # ---------------------------------------------------------------------------- # 56 | # 57 | # 58 | # 59 | # ============================================================================ # 60 | -------------------------------------------------------------------------------- /modules/fetchers/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | nt = lib.types; 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | in { 16 | 17 | # ---------------------------------------------------------------------------- # 18 | 19 | _file = "/fetchers/interface.nix"; 20 | 21 | # ---------------------------------------------------------------------------- # 22 | 23 | options.fetchers = lib.mkOption { 24 | description = lib.mdDoc '' 25 | Fetcher abstractions associated with various forms of inputs and 26 | evaluation rules. 27 | ''; 28 | type = nt.submoduleWith { 29 | modules = [ 30 | ( { ... }: { 31 | 32 | _file = "/fetchers/interface.nix"; 33 | 34 | config._module.args.name = "fetchers"; 35 | 36 | imports = [ 37 | ./path/interface.nix 38 | ./fetchTree/interface.nix 39 | ./fetchTarballDrv/interface.nix 40 | ./composed/interface.nix 41 | ]; 42 | 43 | options.pure = lib.mkOption { 44 | description = lib.mdDoc '' 45 | Whether fetchers are restricted to pure evaluations. 46 | Impure fetchers often autofill missing `sha256`, `narHash`, `rev`, 47 | and other fields which allow later runs to refetch 48 | resources purely. 49 | ''; 50 | type = nt.bool; 51 | default = ! ( builtins ? currentSystem ); 52 | }; 53 | 54 | } ) 55 | ]; 56 | }; 57 | }; 58 | 59 | 60 | } 61 | 62 | 63 | # ---------------------------------------------------------------------------- # 64 | # 65 | # 66 | # 67 | # ============================================================================ # 68 | -------------------------------------------------------------------------------- /modules/fetchers/path/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/fetchers/path"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/fetchers/path/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Arguments used to fetch a source tree or file. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: { 8 | 9 | _file = "/fetchers/path/interface.nix"; 10 | 11 | options.path = lib.mkOption { 12 | description = lib.mdDoc "`builtins.path` fetcher"; 13 | visible = "shallow"; 14 | }; 15 | 16 | } 17 | 18 | 19 | # ---------------------------------------------------------------------------- # 20 | # 21 | # 22 | # 23 | # ============================================================================ # 24 | -------------------------------------------------------------------------------- /modules/fetchers/types.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Arguments used to fetch a source tree or file. 4 | # By default we provide types used by `builtins.fetchTree', and `builtins.path'. 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | { lib, ... }: let 9 | 10 | # ---------------------------------------------------------------------------- # 11 | 12 | nt = lib.types; 13 | 14 | # ---------------------------------------------------------------------------- # 15 | 16 | types = { 17 | 18 | # ---------------------------------------------------------------------------- # 19 | 20 | sha256_hash = nt.strMatching "[[:xdigit:]]{64}"; 21 | sha256_sri = nt.strMatching "sha256-[a-zA-Z0-9+/]{42,44}={0,2}"; 22 | narHash = types.sha256_sri; 23 | 24 | # ---------------------------------------------------------------------------- # 25 | 26 | rev = nt.strMatching "[[:xdigit:]]{40}"; 27 | short_rev = nt.strMatching "[[:xdigit:]]{7}"; 28 | 29 | 30 | # ---------------------------------------------------------------------------- # 31 | 32 | }; 33 | 34 | in types 35 | 36 | 37 | # ---------------------------------------------------------------------------- # 38 | # 39 | # 40 | # 41 | # ============================================================================ # 42 | -------------------------------------------------------------------------------- /modules/package/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | 3 | _file = "/package"; 4 | 5 | imports = [ 6 | ./targets 7 | ./trees 8 | ./interface.nix ./implementation.nix 9 | ]; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /modules/package/targets/built/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/package/targets/built"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/package/targets/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/package/targets"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/package/targets/implementation.nix: -------------------------------------------------------------------------------- 1 | { lib, config, pkgs, pdef, packages, nodePackage, ... }: { 2 | 3 | _file = "/package/targets/implementation.nix"; 4 | 5 | imports = [ 6 | ./source/implementation.nix 7 | ./built/implementation.nix 8 | ./installed/implementation.nix 9 | ]; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /modules/package/targets/installed/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/package/targets/installed"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/package/targets/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | _file = "/targets/interface.nix"; 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | imports = [ 16 | ./source/interface.nix 17 | ./built/interface.nix 18 | ./installed/interface.nix 19 | ]; 20 | 21 | 22 | # ---------------------------------------------------------------------------- # 23 | 24 | } 25 | 26 | 27 | # ---------------------------------------------------------------------------- # 28 | # 29 | # 30 | # 31 | # ============================================================================ # 32 | -------------------------------------------------------------------------------- /modules/package/targets/source/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/package/targets/source"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/package/targets/source/implementation.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, pdef, ... }: { 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | _file = "/package/targets/source/implementation.nix"; 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | config.source = lib.mkDefault pdef.sourceInfo.outPath; 16 | 17 | 18 | # ---------------------------------------------------------------------------- # 19 | 20 | 21 | } 22 | 23 | # ---------------------------------------------------------------------------- # 24 | # 25 | # 26 | # 27 | # ============================================================================ # 28 | -------------------------------------------------------------------------------- /modules/package/targets/source/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: let 8 | 9 | nt = lib.types; 10 | 11 | in { 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | _file = "/package/targets/source/interface.nix"; 16 | 17 | # ---------------------------------------------------------------------------- # 18 | 19 | options = { 20 | 21 | # ---------------------------------------------------------------------------- # 22 | 23 | source = lib.mkOption { 24 | description = lib.mdDoc '' 25 | Unpacked source tree used as the basis for package/module preparation. 26 | 27 | It is strongly recommended that you use `config.pdef.sourceInfo` here 28 | unless you are intentionally applying patches, filters, or your package 29 | resides in a subdir of `sourceInfo`. 30 | 31 | XXX: This tree should NOT patch shebangs yet, since this would deprive 32 | builders which produce distributable tarballs or otherwise "un-nixify" a 33 | module of an "unpatched" point of reference to work with. 34 | ''; 35 | type = nt.package; 36 | }; 37 | 38 | 39 | # ---------------------------------------------------------------------------- # 40 | 41 | }; # End `options' 42 | 43 | 44 | # ---------------------------------------------------------------------------- # 45 | 46 | 47 | } 48 | 49 | # ---------------------------------------------------------------------------- # 50 | # 51 | # 52 | # 53 | # ============================================================================ # 54 | -------------------------------------------------------------------------------- /modules/package/trees/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/package/trees"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/packages/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/packages"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/packages/implementation.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # A `options.floco.packages' collection, represented as a list of 4 | # Node.js package/module submodules. 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | { lib, config, options, pkgs, ... }: let 9 | 10 | nt = lib.types; 11 | 12 | in { 13 | 14 | # ---------------------------------------------------------------------------- # 15 | 16 | _file = "/packages/implementation.nix"; 17 | 18 | # ---------------------------------------------------------------------------- # 19 | 20 | options.packages = lib.mkOption { 21 | type = nt.attrsOf ( nt.attrsOf ( nt.submoduleWith { 22 | shorthandOnlyDefinesConfig = true; 23 | modules = [../package/implementation.nix]; 24 | } ) ); 25 | }; 26 | 27 | 28 | # ---------------------------------------------------------------------------- # 29 | 30 | config = { 31 | # An example module, but also there's basically a none percent chance that 32 | # a real build plan won't include this so yeah you depend on `lodash' now. 33 | packages = builtins.mapAttrs ( ident: builtins.mapAttrs ( version: pdef: 34 | { ... }: { 35 | config = { 36 | inherit (pdef) key; 37 | _module.args = { 38 | inherit pkgs pdef; 39 | inherit (config) packages pdefs; 40 | inherit (config.records) target; 41 | inherit (config.settings) nodePackage; 42 | }; 43 | }; 44 | } 45 | ) ) config.pdefs; 46 | }; # End `config' 47 | 48 | # ---------------------------------------------------------------------------- # 49 | 50 | } 51 | 52 | 53 | # ---------------------------------------------------------------------------- # 54 | # 55 | # 56 | # 57 | # ============================================================================ # 58 | -------------------------------------------------------------------------------- /modules/packages/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # A `options.floco.packages' collection, represented as a list of 4 | # Node.js package/module submodules. 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | { lib, options, ... }: let 9 | 10 | nt = lib.types; 11 | 12 | in { 13 | 14 | # ---------------------------------------------------------------------------- # 15 | 16 | _file = "/packages/interface.nix"; 17 | 18 | # ---------------------------------------------------------------------------- # 19 | 20 | options.packages = lib.mkOption { 21 | 22 | description = lib.mdDoc '' 23 | Collection of built/prepared packages and modules. 24 | ''; 25 | 26 | # NOTE: modifying the `getSubOptions' routine isn't working here. 27 | # I have no idea why but the issue is relatively benign since it only 28 | # effects documentation generation. 29 | # Nonetheless I'm leaving it until it can be properly debugged. 30 | type = let 31 | pkgType = nt.submoduleWith { 32 | shorthandOnlyDefinesConfig = true; 33 | modules = [../package/interface.nix]; 34 | }; 35 | in nt.attrsOf ( nt.attrsOf pkgType ); 36 | 37 | example.lodash."4.17.21".key = "lodash/4.17.21"; 38 | 39 | }; 40 | 41 | 42 | # ---------------------------------------------------------------------------- # 43 | 44 | } 45 | 46 | 47 | # ---------------------------------------------------------------------------- # 48 | # 49 | # 50 | # 51 | # ============================================================================ # 52 | -------------------------------------------------------------------------------- /modules/packument/implementation.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, config, ... }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | metaFiles.packumentUrl = lib.mkDefault ( 12 | if config.ltype != "file" then null else 13 | "https://registry.npmjs.org/${config.ident}" 14 | ); 15 | 16 | metaFiles.packumentHash = lib.mkDefault ( 17 | if config.metaFiles.packumentUrl == null then null else 18 | ( builtins.fetchTree { 19 | type = "file"; 20 | url = config.metaFiles.packumentUrl; 21 | } ).narHash 22 | ); 23 | 24 | metaFiles.packument = let 25 | fetched = builtins.fetchTree { 26 | type = "file"; 27 | url = config.metaFiles.packumentUrl; 28 | narHash = config.metaFiles.packumentHash; 29 | }; 30 | attrs = lib.importJSON fetched; 31 | in lib.mkDefault ( 32 | if config.metaFiles.packumentUrl != null then attrs else null 33 | ); 34 | 35 | metaFiles.packumentRev = 36 | if config.metaFiles.packument == null then null else 37 | config.metaFiles.packument._rev or null; 38 | 39 | 40 | # ---------------------------------------------------------------------------- # 41 | 42 | in { 43 | 44 | _file = "/packument/implementation.nix"; 45 | 46 | } 47 | 48 | # ---------------------------------------------------------------------------- # 49 | # 50 | # 51 | # 52 | # ============================================================================ # 53 | -------------------------------------------------------------------------------- /modules/pdefs/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/pdefs"; 3 | imports = [ 4 | ../fetchers 5 | ../records 6 | ./interface.nix ./implementation.nix 7 | ]; 8 | } 9 | -------------------------------------------------------------------------------- /modules/plock/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/plock"; 3 | imports = [ 4 | ../records 5 | ./implementation.nix ./interface.nix 6 | ]; 7 | } 8 | -------------------------------------------------------------------------------- /modules/plock/scope/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | nt = lib.types; 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | in { 16 | 17 | _file = "/plock/scope/interface.nix"; 18 | 19 | # ---------------------------------------------------------------------------- # 20 | 21 | options = { 22 | 23 | path = lib.mkOption { 24 | type = nt.addCheck nt.str ( s: ! ( lib.hasSuffix "node_modules" s ) ); 25 | }; 26 | 27 | direct = lib.mkOption { 28 | type = nt.attrsOf lib.libfloco.version; 29 | readOnly = true; 30 | }; 31 | 32 | inherited = lib.mkOption { 33 | type = nt.attrsOf lib.libfloco.version; 34 | readOnly = true; 35 | }; 36 | 37 | isRoot = lib.mkOption { 38 | type = nt.bool; 39 | readOnly = true; 40 | }; 41 | 42 | following = lib.mkOption { 43 | type = nt.attrsOf lib.libfloco.version; 44 | readOnly = true; 45 | }; 46 | 47 | pins = lib.mkOption { 48 | type = nt.attrsOf lib.libfloco.version; 49 | readOnly = true; 50 | }; 51 | 52 | all = lib.mkOption { 53 | type = nt.attrsOf lib.libfloco.version; 54 | readOnly = true; 55 | }; 56 | 57 | }; 58 | 59 | 60 | # ---------------------------------------------------------------------------- # 61 | 62 | } 63 | 64 | 65 | # ---------------------------------------------------------------------------- # 66 | # 67 | # 68 | # 69 | # ============================================================================ # 70 | -------------------------------------------------------------------------------- /modules/plockToPdefs/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/plockToPdefs"; 3 | imports = [ 4 | ../plock 5 | ../records 6 | ../fetchers 7 | ../pdefs 8 | ./interface.nix ./implementation.nix 9 | ]; 10 | } 11 | -------------------------------------------------------------------------------- /modules/records/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/records"; 3 | imports = [ 4 | ./interface.nix ./implementation.nix 5 | ./pjsCore 6 | ]; 7 | } 8 | -------------------------------------------------------------------------------- /modules/records/implementation.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, config, pkgs, ... }: let 8 | 9 | nt = lib.types; 10 | 11 | in { 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | _file = "/records/implementation.nix"; 16 | 17 | imports = [../fetchers]; 18 | 19 | # ---------------------------------------------------------------------------- # 20 | 21 | config.records = { 22 | _module.args.pkgs = lib.mkDefault pkgs; 23 | _module.args.floco = lib.mkDefault config; 24 | }; # End `config.records' 25 | 26 | 27 | # ---------------------------------------------------------------------------- # 28 | 29 | } 30 | 31 | 32 | # ---------------------------------------------------------------------------- # 33 | # 34 | # 35 | # 36 | # ============================================================================ # 37 | -------------------------------------------------------------------------------- /modules/records/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | nt = lib.types; 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | in { 16 | 17 | # ---------------------------------------------------------------------------- # 18 | 19 | _file = "/records/interface.nix"; 20 | 21 | # ---------------------------------------------------------------------------- # 22 | 23 | options = { 24 | 25 | # ---------------------------------------------------------------------------- # 26 | 27 | records = lib.mkOption { 28 | description = lib.mdDoc '' 29 | Abstract records used to construct instances of common submodule types. 30 | 31 | These base interface must be implemented, but the implementations 32 | themselves may be swapped or overridden. 33 | ''; 34 | type = nt.submodule ./pdef/deferred.nix; 35 | }; # End `options.records' 36 | 37 | 38 | # ---------------------------------------------------------------------------- # 39 | 40 | 41 | }; # End `options' 42 | 43 | 44 | # ---------------------------------------------------------------------------- # 45 | 46 | } 47 | 48 | 49 | # ---------------------------------------------------------------------------- # 50 | # 51 | # 52 | # 53 | # ============================================================================ # 54 | -------------------------------------------------------------------------------- /modules/records/pdef/binInfo/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/pdef/binInfo"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/records/pdef/binInfo/implementation.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, config, options, ... }: { 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | _file = "/records/pdef/binInfo/implementation.nix"; 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | config.binInfo = let 16 | 17 | mf = config.metaFiles; 18 | 19 | bin = mf.metaRaw.bin or ( 20 | if ( mf.plent or null ) != null then mf.plent.bin or {} else 21 | if ( mf.pjs or null ) != null then mf.pjs.bin or {} else 22 | null 23 | ); 24 | 25 | binDir = lib.mkDefault ( 26 | if bin != null then null else 27 | config.metaFiles.metaRaw.binDir or 28 | config.metaFiles.metaRaw.directories.bin or 29 | config.metaFiles.pjs.directories.bin or null 30 | ); 31 | 32 | in lib.mkDefault ( config.metaFiles.metaRaw.binInfo or { 33 | inherit binDir; 34 | binPairs = lib.mkDefault ( 35 | if bin == null then {} else 36 | if builtins.isAttrs bin then bin else 37 | { ${baseNameOf config.ident} = bin; } 38 | ); 39 | 40 | } ); 41 | 42 | 43 | # ---------------------------------------------------------------------------- # 44 | 45 | config._export = let 46 | subs = options.binInfo.type.getSubOptions []; 47 | in lib.mkIf ( config.binInfo != options.binInfo.default ) { 48 | binInfo = { 49 | binDir = lib.mkIf ( config.binInfo.binDir != subs.binDir.default ) 50 | config.binInfo.binDir; 51 | binPairs = lib.mkIf ( config.binInfo.binPairs != subs.binPairs.default ) 52 | config.binInfo.binPairs; 53 | }; 54 | }; 55 | 56 | 57 | # ---------------------------------------------------------------------------- # 58 | 59 | } 60 | 61 | # ---------------------------------------------------------------------------- # 62 | # 63 | # 64 | # 65 | # ============================================================================ # 66 | -------------------------------------------------------------------------------- /modules/records/pdef/binInfo/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, options, ... }: let 8 | 9 | nt = lib.types; 10 | 11 | in { 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | _file = "/records/pdef/binInfo/interface.nix"; 16 | 17 | # ---------------------------------------------------------------------------- # 18 | 19 | options.binInfo = lib.mkOption { 20 | 21 | description = lib.mdDoc '' 22 | Indicates files or directories which should be prepared for use as 23 | executable scripts. 24 | ''; 25 | 26 | default = { binPairs = {}; binDir = null; }; 27 | 28 | # ---------------------------------------------------------------------------- # 29 | 30 | type = nt.submodule { 31 | 32 | options.binPairs = lib.mkBinPairsOption; 33 | 34 | options.binDir = lib.mkOption { 35 | description = '' 36 | Relative path to a subdir from which all files should be prepared 37 | as executables. 38 | 39 | Executable names will be defined as the basename of each file with 40 | any extensions stripped. 41 | ''; 42 | type = nt.nullOr nt.str; 43 | default = null; 44 | }; 45 | 46 | }; # End `options.binInfo.type.options' 47 | 48 | 49 | # ---------------------------------------------------------------------------- # 50 | 51 | }; # End `options.binInfo' 52 | 53 | 54 | # ---------------------------------------------------------------------------- # 55 | 56 | } 57 | 58 | 59 | # ---------------------------------------------------------------------------- # 60 | # 61 | # 62 | # 63 | # ============================================================================ # 64 | -------------------------------------------------------------------------------- /modules/records/pdef/default.nix: -------------------------------------------------------------------------------- 1 | { lib, pkgs, ... }: let 2 | mod = lib.evalModules { 3 | modules = [./deferred.nix { config._module.args = { inherit pkgs; }; }]; 4 | }; 5 | in mod.config.pdef 6 | -------------------------------------------------------------------------------- /modules/records/pdef/depInfo/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/pdef/depInfo"; 3 | imports = [./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/records/pdef/depInfo/implementation.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Indicates information about dependencies of a package/module. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, config, ... }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | raw = let 12 | # Ignore `devDependencies*' for distributed tarballs. 13 | dev' = if config.ltype == "file" then {} else { 14 | devDependencies = true; 15 | devDependenciesMeta = true; 16 | }; 17 | take = builtins.intersectAttrs ( dev' // { 18 | requires = true; 19 | dependencies = true; 20 | optionalDependencies = true; 21 | bundleDependencies = true; 22 | bundledDependencies = true; 23 | } ); 24 | get = f: 25 | if ( config.metaFiles.${f} or {} ) == null then {} else 26 | take config.metaFiles.${f}; 27 | in ( get "pjs" ) // ( get "plent" ) // ( get "ylent" ) // ( get "metaRaw" ); 28 | 29 | 30 | # ---------------------------------------------------------------------------- # 31 | 32 | in { 33 | 34 | # ---------------------------------------------------------------------------- # 35 | 36 | _file = "/records/pdef/depInfo/implementation.nix"; 37 | 38 | # ---------------------------------------------------------------------------- # 39 | 40 | config._module.args = { 41 | requires = raw.requires or {}; 42 | dependencies = raw.dependencies or {}; 43 | devDependencies = raw.devDependencies or {}; 44 | devDependenciesMeta = raw.devDependenciesMeta or {}; 45 | optionalDependencies = raw.optionalDependencies or {}; 46 | bundledDependencies = raw.bundledDependencies or []; 47 | bundleDependencies = raw.bundleDependencies or false; 48 | }; 49 | 50 | } 51 | 52 | 53 | # ---------------------------------------------------------------------------- # 54 | # 55 | # 56 | # 57 | # ============================================================================ # 58 | -------------------------------------------------------------------------------- /modules/records/pdef/deserialize.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, config, options, ... }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | # We use `priority' of 900 to put us above `lib.mkDefault', while staying 12 | # below `lib.mkForce'. 13 | # This allows users' `foverrides.nix'/explicit config to still "work", 14 | # while avoiding the network fetches and other scraping which may occur if 15 | # we hit `lib.mkDefault' 16 | mkCached = lib.mkOverride 900; 17 | 18 | mkCachedRec = lib.mapAttrsRecursive ( _: mkCached ); 19 | 20 | 21 | # ---------------------------------------------------------------------------- # 22 | 23 | in { 24 | 25 | _file = "/records/pdef/deserialize.nix"; 26 | 27 | config.binInfo = mkCachedRec options.binInfo.default; 28 | config.depInfo = mkCached {}; 29 | config.peerInfo = mkCached {}; 30 | config.sysInfo = mkCachedRec options.sysInfo.default; 31 | config.lifecycle = mkCachedRec options.lifecycle.default; 32 | config.fsInfo = mkCachedRec options.fsInfo.default; 33 | config.deserialized = true; 34 | 35 | # We explicitly set this to empty to prevent various routines from trying to 36 | # fetch the file contents. 37 | # This ensures that only the declared information is used. 38 | config.metaFiles.pjs = mkCached {}; 39 | config.metaFiles.plent = mkCached {}; 40 | config.metaFiles.ylent = mkCached {}; 41 | 42 | } 43 | 44 | 45 | # ---------------------------------------------------------------------------- # 46 | # 47 | # 48 | # 49 | # ============================================================================ # 50 | -------------------------------------------------------------------------------- /modules/records/pdef/fsInfo/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/pdef/fsInfo"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/records/pdef/fsInfo/implementation.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, config, options, ... }: { 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | _file = "/records/pdef/fsInfo/implementation.nix"; 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | config = { 16 | 17 | fsInfo.gypfile = lib.mkDefault ( 18 | if config.deserialized then false else 19 | builtins.pathExists ( config.metaFiles.pjsDir + "/binding.gyp" ) 20 | ); 21 | 22 | fsInfo.shrinkwrap = lib.mkDefault ( 23 | if config.deserialized then false else 24 | builtins.pathExists ( config.metaFiles.pjsDir + "/npm-shrinkwrap.json" ) 25 | ); 26 | 27 | _export = let 28 | subs = options.fsInfo.type.getSubOptions []; 29 | rsl = if config.fsInfo == options.fsInfo.default then {} else { 30 | dir = lib.mkIf ( config.fsInfo.dir != subs.dir.default ) 31 | config.fsInfo.dir; 32 | gypfile = lib.mkIf ( config.fsInfo.gypfile != subs.gypfile.default ) 33 | config.fsInfo.gypfile; 34 | shrinkwrap = 35 | lib.mkIf ( config.fsInfo.shrinkwrap != subs.shrinkwrap.default ) 36 | config.fsInfo.shrinkwrap; 37 | }; 38 | in lib.mkIf ( rsl != {} ) { fsInfo = rsl; }; 39 | }; 40 | 41 | 42 | # ---------------------------------------------------------------------------- # 43 | 44 | } 45 | 46 | 47 | # ---------------------------------------------------------------------------- # 48 | # 49 | # 50 | # 51 | # ============================================================================ # 52 | -------------------------------------------------------------------------------- /modules/records/pdef/lifecycle/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/pdef/lifecycle"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/records/pdef/peerInfo/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/pdef/peerInfo"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/records/pdef/peerInfo/implementation.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Information concerning `peerDependencies' or "propagated dependencies". 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, config, ... }: let 8 | 9 | nt = lib.types; 10 | 11 | # ---------------------------------------------------------------------------- # 12 | 13 | raw = let 14 | take = builtins.intersectAttrs { 15 | peerDependencies = true; 16 | peerDependenciesMeta = true; 17 | }; 18 | get = f: 19 | if ( config.metaFiles.${f} or null ) == null then {} else 20 | take config.metaFiles.${f}; 21 | in ( get "pjs" ) // ( get "plent" ) // ( get "metaRaw" ); 22 | 23 | # ---------------------------------------------------------------------------- # 24 | 25 | in { 26 | 27 | # ---------------------------------------------------------------------------- # 28 | 29 | _file = "/records/pdef/peerInfo/implementation.nix"; 30 | 31 | # ---------------------------------------------------------------------------- # 32 | 33 | 34 | config = { 35 | 36 | peerInfo = let 37 | base = builtins.mapAttrs ( ident: _: 38 | import ./single.implementation.nix ( { inherit lib ident; } // raw ) 39 | ) ( ( raw.peerDependencies or {} ) // 40 | ( raw.peerDependenciesMeta or {} ) ); 41 | in lib.mkDefault ( if config.deserialized then {} else base ); 42 | 43 | _export = lib.mkIf ( config.peerInfo != {} ) { 44 | peerInfo = let 45 | iface = import ./single.interface.nix { inherit lib; }; 46 | in builtins.mapAttrs ( _: builtins.mapAttrs ( f: v: 47 | if f == "descriptor" then v else 48 | lib.mkIf ( v != iface.options.${f}.default ) v 49 | ) ) config.peerInfo; 50 | }; 51 | }; 52 | 53 | } 54 | 55 | # ---------------------------------------------------------------------------- # 56 | # 57 | # 58 | # 59 | # ============================================================================ # 60 | -------------------------------------------------------------------------------- /modules/records/pdef/peerInfo/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Information concerning `peerDependencies' or "propagated dependencies". 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: let 8 | 9 | nt = lib.types; 10 | 11 | # ---------------------------------------------------------------------------- # 12 | 13 | in { 14 | 15 | # ---------------------------------------------------------------------------- # 16 | 17 | _file = "/records/pdef/peerInfo/interface.nix"; 18 | 19 | # ---------------------------------------------------------------------------- # 20 | 21 | options = { 22 | peerInfo = lib.mkOption { 23 | description = lib.mdDoc '' 24 | Set of propagated dependencies that consumers of this package/module 25 | must provide at runtime. 26 | 27 | Often peer dependencies are used to enforce interface alignment across 28 | a set of modules but do not necessarily imply that the requestor depends 29 | on the declared peer at build time or runtime - rather it states 30 | "my consumers depend on the declared peer as a side effect of their 31 | dependence on me". 32 | 33 | NOTE: For the purposes of `treeInfo` and the construction of a 34 | `node_modules/` tree, if a module declares a peer then that peer must 35 | be placed in a "sibling" or parent `node_modules/` directory, and never 36 | as a subdirectory of the requestor! 37 | The "sibling" case is why the term "peer" is used, indicating that these 38 | modules must be "peers" living in the same `node_modules/` directory; 39 | in practice a parent directory also works, but you get the idea. 40 | ''; 41 | type = nt.attrsOf ( nt.submoduleWith { 42 | modules = [./single.interface.nix]; 43 | } ); 44 | default = {}; 45 | }; 46 | }; 47 | 48 | } 49 | 50 | # ---------------------------------------------------------------------------- # 51 | # 52 | # 53 | # 54 | # ============================================================================ # 55 | -------------------------------------------------------------------------------- /modules/records/pdef/peerInfo/single.implementation.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Information concerning `peerDependencies' or "propagated dependencies". 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib 8 | , ident 9 | , peerDependencies ? {} 10 | , peerDependenciesMeta ? {} 11 | , ... 12 | }: { 13 | 14 | # ---------------------------------------------------------------------------- # 15 | 16 | config = { 17 | descriptor = lib.mkDefault ( peerDependencies.${ident} or "*" ); 18 | optional = 19 | lib.mkDefault ( peerDependenciesMeta.${ident}.optional or false ); 20 | }; 21 | 22 | } 23 | 24 | # ---------------------------------------------------------------------------- # 25 | # 26 | # 27 | # 28 | # ============================================================================ # 29 | -------------------------------------------------------------------------------- /modules/records/pdef/sysInfo/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/records/pdef/sysInfo"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/records/pdef/sysInfo/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: let 8 | 9 | nt = lib.types; 10 | 11 | in { 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | _file = "/records/pdef/sysInfo/interface.nix"; 16 | 17 | options.sysInfo = lib.mkOption { 18 | description = '' 19 | Indicates platform, arch, and Node.js version support. 20 | ''; 21 | 22 | type = nt.submodule { 23 | options = { 24 | 25 | # ---------------------------------------------------------------------------- # 26 | 27 | os = lib.libfloco.mkSysOssOption; 28 | cpu = lib.libfloco.mkSysCpusOption; 29 | 30 | 31 | # ---------------------------------------------------------------------------- # 32 | 33 | engines = lib.mkOption { 34 | description = '' 35 | Indicates supported tooling versions. 36 | ''; 37 | type = nt.submodule { 38 | freeformType = nt.attrsOf nt.str; 39 | options.node = lib.mkOption { 40 | description = '' 41 | Supported Node.js versions. 42 | ''; 43 | type = nt.str; 44 | default = "*"; 45 | example = ">=14"; 46 | }; 47 | }; 48 | default.node = "*"; 49 | }; 50 | 51 | 52 | # ---------------------------------------------------------------------------- # 53 | 54 | }; # End `options.sysInfo.type.options' 55 | }; # End `options.sysInfo.type' 56 | 57 | default = { 58 | os = ["*"]; 59 | cpu = ["*"]; 60 | engines.node = "*"; 61 | }; 62 | 63 | }; # End `options' 64 | 65 | 66 | # ---------------------------------------------------------------------------- # 67 | 68 | } 69 | 70 | 71 | # ---------------------------------------------------------------------------- # 72 | # 73 | # 74 | # 75 | # ============================================================================ # 76 | -------------------------------------------------------------------------------- /modules/records/pdef/treeInfo/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/records/pdef/treeInfo"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/records/pdef/treeInfo/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: let 8 | 9 | nt = lib.types; 10 | 11 | in { 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | _file = "/records/pdef/treeInfo/interface.nix"; 16 | 17 | options.treeInfo = lib.mkOption { 18 | description = lib.mdDoc '' 19 | `node_modules/` trees used for various lifecycle events. 20 | These declarations are analogous to the `package.*` field found in 21 | `package-lock.json(v2/3)` files. 22 | This means that these fields should describe both direct and indirect 23 | dependencies for the full dependency graph. 24 | 25 | Tree declarations are expected to be pairs of `node_modules/` paths to 26 | "keys" ( matching the `key` field in its Nix declaration ). 27 | 28 | In practice we expect users to explicitly define this field only for 29 | targets which they actually intend to create installables from, and we 30 | recommend using a `package-lock.json(v2/3)` to fill these values. 31 | ''; 32 | 33 | type = nt.nullOr ( nt.attrsOf ( nt.submodule ./single.interface.nix ) ); 34 | 35 | default = null; 36 | 37 | example = lib.literalExpression '' 38 | { 39 | "node_modules/@foo/bar" = { 40 | key = "@foo/bar/1.0.0"; 41 | dev = true; 42 | # ... 43 | }; 44 | "node_modules/@foo/bar/node_modules/baz" = { 45 | key = "baz/4.2.0"; 46 | dev = false; 47 | # ... 48 | }; 49 | # ... 50 | } 51 | ''; 52 | 53 | }; 54 | 55 | 56 | # ---------------------------------------------------------------------------- # 57 | 58 | } 59 | 60 | 61 | # ---------------------------------------------------------------------------- # 62 | # 63 | # 64 | # 65 | # ============================================================================ # 66 | -------------------------------------------------------------------------------- /modules/records/pjsCore/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/records/pjsCore"; 3 | imports = [./module.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/settings/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/settings"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/settings/implementation.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, pkgs, ... }: { 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | _file = "/settings/implementation.nix"; 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | config.settings.system = lib.mkDefault ( 16 | builtins.currentSystem or "unknown" 17 | ); 18 | 19 | # ---------------------------------------------------------------------------- # 20 | 21 | config.settings.nodePackage = lib.mkDefault pkgs.nodejs; 22 | 23 | 24 | # ---------------------------------------------------------------------------- # 25 | 26 | } 27 | 28 | 29 | # ---------------------------------------------------------------------------- # 30 | # 31 | # 32 | # 33 | # ============================================================================ # 34 | -------------------------------------------------------------------------------- /modules/top/default.nix: -------------------------------------------------------------------------------- 1 | { lib, config, pkgs, ... }: { 2 | _file = "/top"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /modules/top/implementation.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, pkgs, ... }: let 8 | 9 | nt = lib.types; 10 | 11 | in { 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | _file = "/top/implementation.nix"; 16 | 17 | # ---------------------------------------------------------------------------- # 18 | 19 | options.floco = lib.mkOption { 20 | type = nt.submoduleWith { 21 | shorthandOnlyDefinesConfig = false; 22 | modules = [ 23 | ../records 24 | ( { config, ... }: { 25 | 26 | imports = [ 27 | ../settings/implementation.nix 28 | ../buildPlan/implementation.nix 29 | ../topo/implementation.nix 30 | ../pdefs/implementation.nix 31 | ../packages/implementation.nix 32 | ../fetchers/implementation.nix 33 | ]; 34 | 35 | config._module.args.pkgs = let 36 | nixpkgs = ( import ../../inputs ).nixpkgs.flake; 37 | pkgsFor = nixpkgs.legacyPackages.${config.settings.system}; 38 | ov = lib.composeExtensions 39 | ( import ../../overlay.nix ) 40 | ( _: _: { inherit (config.settings) nodePackage; } ); 41 | withOv = pkgsFor.extend ov; 42 | in lib.mkOverride 999 withOv; 43 | 44 | config.settings.system = lib.mkIf ( 45 | ( builtins.currentSystem or null ) == null 46 | ) ( lib.mkOverride 999 pkgs.system ); 47 | 48 | } ) 49 | ]; 50 | }; 51 | }; 52 | 53 | 54 | # ---------------------------------------------------------------------------- # 55 | 56 | 57 | 58 | # ---------------------------------------------------------------------------- # 59 | 60 | } 61 | 62 | 63 | # ---------------------------------------------------------------------------- # 64 | # 65 | # 66 | # 67 | # ============================================================================ # 68 | -------------------------------------------------------------------------------- /modules/top/interface.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Top level `floco' module. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: let 8 | 9 | nt = lib.types; 10 | 11 | in { 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | _file = "/top/interface.nix"; 16 | 17 | # ---------------------------------------------------------------------------- # 18 | 19 | options.floco = lib.mkOption { 20 | description = lib.mdDoc '' 21 | Scope used for configuring `floco` framework. 22 | ''; 23 | 24 | type = nt.submoduleWith { 25 | shorthandOnlyDefinesConfig = false; 26 | modules = [ 27 | ../settings/interface.nix 28 | ../buildPlan/interface.nix 29 | ../topo/interface.nix 30 | ../pdefs/interface.nix 31 | ../packages/interface.nix 32 | ../fetcher/interface.nix 33 | ../fetchers/interface.nix 34 | ]; 35 | specialArgs.lib = 36 | if lib ? libfloco then lib else import ../../lib { inherit lib; }; 37 | }; 38 | 39 | default = {}; 40 | }; 41 | 42 | 43 | # ---------------------------------------------------------------------------- # 44 | 45 | } 46 | 47 | 48 | # ---------------------------------------------------------------------------- # 49 | # 50 | # 51 | # 52 | # ============================================================================ # 53 | -------------------------------------------------------------------------------- /modules/topo/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/topo"; 3 | imports = [ 4 | ../pdefs 5 | ./interface.nix ./implementation.nix 6 | ]; 7 | } 8 | -------------------------------------------------------------------------------- /modules/vinfo/implementation.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, config, ... }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | metaFiles.vinfoUrl = lib.mkDefault ( 12 | if config.ltype != "file" then null else 13 | "https://registry.npmjs.org/${config.ident}/${config.version}" 14 | ); 15 | 16 | metaFiles.vinfoHash = lib.mkDefault ( 17 | if config.metaFiles.vinfoUrl == null then null else 18 | ( builtins.fetchTree { 19 | type = "file"; 20 | url = config.metaFiles.vinfoUrl; 21 | } ).narHash 22 | ); 23 | 24 | metaFiles.vinfo = let 25 | fetched = builtins.fetchTree { 26 | type = "file"; 27 | url = config.metaFiles.vinfoUrl; 28 | narHash = config.metaFiles.vinfoHash; 29 | }; 30 | attrs = lib.importJSON fetched; 31 | in lib.mkDefault ( 32 | if config.metaFiles.vinfoUrl != null then attrs else null 33 | ); 34 | 35 | 36 | # ---------------------------------------------------------------------------- # 37 | 38 | in { 39 | 40 | _file = "/vinfo/implementation.nix"; 41 | 42 | } 43 | 44 | # ---------------------------------------------------------------------------- # 45 | # 46 | # 47 | # 48 | # ============================================================================ # 49 | -------------------------------------------------------------------------------- /modules/ylock/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | _file = "/ylock"; 3 | imports = [./interface.nix ./implementation.nix]; 4 | } 5 | -------------------------------------------------------------------------------- /pkgs/cli/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { nixpkgs ? ( import ../../inputs ).nixpkgs.flake 8 | , system ? builtins.currentSystem 9 | , pkgsFor ? nixpkgs.legacyPackages.${system} 10 | , lib ? nixpkgs.lib 11 | , stdenv ? pkgsFor.stdenv 12 | , bash ? pkgsFor.bash 13 | , coreutils ? pkgsFor.coreutils 14 | , gnugrep ? pkgsFor.gnugrep 15 | , jq ? pkgsFor.jq 16 | , makeWrapper ? pkgsFor.makeWrapper 17 | , nix ? pkgsFor.nix 18 | , npm ? pkgsFor.nodejs.npm 19 | , sqlite ? pkgsFor.sqlite 20 | }: lib.makeOverridable ( import ./pkg-fun.nix ) { 21 | inherit lib stdenv bash coreutils gnugrep jq makeWrapper nix npm sqlite; 22 | } 23 | 24 | 25 | # ---------------------------------------------------------------------------- # 26 | # 27 | # 28 | # 29 | # ============================================================================ # 30 | -------------------------------------------------------------------------------- /pkgs/cli/pkg-fun.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib 8 | , stdenv 9 | , bash 10 | , coreutils 11 | , gnugrep 12 | , jq 13 | , makeWrapper 14 | , nix 15 | , npm 16 | , sqlite 17 | , ... 18 | }: let 19 | propagatedBuildInputs = [bash coreutils gnugrep jq nix npm sqlite]; 20 | in stdenv.mkDerivation { 21 | pname = "floco"; 22 | version = "0.2.2"; 23 | src = builtins.path { 24 | path = ./src; 25 | filter = name: type: ( baseNameOf name ) != "site-sql"; 26 | }; 27 | nativeBuildInputs = [makeWrapper]; 28 | dontConfigure = true; 29 | dontBuild = true; 30 | installPhase = '' 31 | mkdir -p \ 32 | "$out/bin" \ 33 | "$out/share/floco" \ 34 | "$out/share/floco/site-sql" \ 35 | "$out/share/zsh/site-functions" \ 36 | ; 37 | mv ./libexec "$out/libexec"; 38 | 39 | mv ./completion/zsh/_floco "$out/share/zsh/site-functions/"; 40 | rm -rf ./completion; 41 | 42 | mv * "$out/share/floco/"; 43 | 44 | cp -- ${builtins.path { path = ../../db; }}/*.sql \ 45 | "$out/share/floco/site-sql/"; 46 | 47 | cp -r -- ${builtins.path { path = ../../lib; }}/* \ 48 | "$out/share/floco/nix/lib/"; 49 | 50 | makeShellWrapper \ 51 | "$out/share/floco/main.sh" \ 52 | "$out/bin/floco" \ 53 | --prefix PATH : "${lib.makeBinPath propagatedBuildInputs}" \ 54 | --suffix PATH : "$out/libexec" \ 55 | ; 56 | ''; 57 | inherit propagatedBuildInputs; 58 | } 59 | 60 | 61 | # ---------------------------------------------------------------------------- # 62 | # 63 | # 64 | # 65 | # ============================================================================ # 66 | -------------------------------------------------------------------------------- /pkgs/cli/src/lib/TEMPLATE.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | # ============================================================================ # 3 | # 4 | # TODO: Replace `NAME', `FUNCTION', and `DESCRIPTION'. 5 | # TODO: Replace or remove reference to `HELPER.sh'. 6 | # TODO: remove `shellcheck disable=1091'. 7 | # 8 | # ---------------------------------------------------------------------------- # 9 | 10 | if [[ -n "${_floco_cli_NAME_sourced:-}" ]]; then return 0; fi 11 | 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | set -eu; 16 | set -o pipefail; 17 | 18 | 19 | # ---------------------------------------------------------------------------- # 20 | 21 | : "${REALPATH:=realpath}"; 22 | export REALPATH; 23 | 24 | 25 | # ---------------------------------------------------------------------------- # 26 | 27 | : "${FLOCO_LIBDIR:=$( $REALPATH "${BASH_SOURCE[0]%/*}"; )}"; 28 | export FLOCO_LIBDIR; 29 | 30 | 31 | # ---------------------------------------------------------------------------- # 32 | 33 | # Source Helpers 34 | 35 | #shellcheck disable=SC1091 36 | #shellcheck source-path=SCRIPTDIR 37 | #shellcheck source=./HELPER.sh 38 | . "$FLOCO_LIBDIR/HELPER.sh"; 39 | 40 | 41 | # ---------------------------------------------------------------------------- # 42 | 43 | # FUNCTION ARGS 44 | # ------------- 45 | # DESCRIPTION 46 | FUNCTION() { 47 | echo "TODO"; 48 | } 49 | export -f FUNCTION; 50 | 51 | 52 | # ---------------------------------------------------------------------------- # 53 | 54 | if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then 55 | # Make this file usable as a script. 56 | FUNCTION "$@"; 57 | else 58 | export _floco_cli_NAME_sourced=:; 59 | fi 60 | 61 | 62 | # ---------------------------------------------------------------------------- # 63 | # 64 | # 65 | # 66 | # ============================================================================ # 67 | -------------------------------------------------------------------------------- /pkgs/cli/src/lib/nix-system.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | # ============================================================================ # 3 | # 4 | # Print the running machine's `nix' system pair. 5 | # Examples: x86_64-linux, aarch64-linux, x86_64-darwin, etc... 6 | # 7 | # ---------------------------------------------------------------------------- # 8 | 9 | if [[ -n "${_floco_cli_nix_system_sourced:-}" ]]; then return 0; fi 10 | 11 | 12 | # ---------------------------------------------------------------------------- # 13 | 14 | set -eu; 15 | set -o pipefail; 16 | 17 | 18 | # ---------------------------------------------------------------------------- # 19 | 20 | # @BEGIN_INJECT_UTILS@ 21 | : "${NIX:=nix}"; 22 | export NIX; 23 | 24 | 25 | # ---------------------------------------------------------------------------- # 26 | 27 | # Records the running system pair as recognized by `nix CMD --system SYSTEM'. 28 | : "${_nix_system=}"; 29 | export _nix_system; 30 | 31 | nixSystem() { 32 | if [[ -z "$_nix_system" ]]; then 33 | _nix_system="$( $NIX eval --raw --impure --expr builtins.currentSystem; )"; 34 | fi 35 | echo "$_nix_system"; 36 | export _nix_system; 37 | } 38 | export -f nixSystem; 39 | 40 | 41 | # ---------------------------------------------------------------------------- # 42 | 43 | if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then 44 | # Make this file usable as a script. 45 | nixSystem; 46 | else 47 | export _floco_cli_nix_system_sourced=:; 48 | fi 49 | 50 | 51 | # ---------------------------------------------------------------------------- # 52 | # 53 | # 54 | # 55 | # ============================================================================ # 56 | -------------------------------------------------------------------------------- /pkgs/cli/src/lib/search-up.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | # ============================================================================ # 3 | # 4 | # Helper function which searches for a file in a directory and in its parent 5 | # directories until it is located or the project/filesystem root is reached. 6 | # 7 | # ---------------------------------------------------------------------------- # 8 | 9 | if [[ -n "${_floco_cli_search_up_sourced:-}" ]]; then return 0; fi 10 | 11 | 12 | # ---------------------------------------------------------------------------- # 13 | 14 | set -eu; 15 | set -o pipefail; 16 | 17 | 18 | # ---------------------------------------------------------------------------- # 19 | 20 | # @BEGIN_INJECT_UTILS@ 21 | : "${REALPATH:=realpath}"; 22 | export REALPATH; 23 | 24 | 25 | # ---------------------------------------------------------------------------- # 26 | 27 | # stopSearch DIR 28 | # -------------- 29 | # Return 0 if DIR's parent is searchable, 1 otherwise. 30 | keepSearching() { 31 | ! { [[ "$( $REALPATH "$1"; )" = '/' ]] || [[ -d "$1/.git" ]]; }; 32 | } 33 | export -f keepSearching; 34 | 35 | 36 | # searchUp FILE [DIR] 37 | # ------------------- 38 | searchUp() { 39 | if [[ -r "${2:-$PWD}/$1" ]]; then 40 | $REALPATH "${2:-$PWD}/$1"; 41 | elif keepSearching "${2:-$PWD}"; then 42 | searchUp "$1" "${2:-$PWD}/.."; 43 | else 44 | return 1; 45 | fi 46 | } 47 | export -f searchUp; 48 | 49 | 50 | # ---------------------------------------------------------------------------- # 51 | 52 | if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then 53 | # Make this file usable as a script. 54 | if [[ "$#" -gt 2 ]] || [[ "$#" -lt 1 ]]; then 55 | echo "floco-ref.sh: You may pass one or two arguments." >&2; 56 | exit 1; 57 | fi 58 | searchUp "$@"; 59 | else 60 | export _floco_cli_search_up_sourced=:; 61 | fi 62 | 63 | 64 | # ---------------------------------------------------------------------------- # 65 | # 66 | # 67 | # 68 | # ============================================================================ # 69 | -------------------------------------------------------------------------------- /pkgs/cli/src/nix/common.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | let 8 | impure = import ./lib/impure.nix; 9 | in { 10 | system ? impure.system 11 | , flocoRef ? impure.flocoRef 12 | , floco ? impure.floco 13 | , lib ? impure.lib 14 | , pkgsFor ? impure.pkgsFor 15 | , globalConfig ? impure.globalConfig 16 | , userConfig ? impure.userConfig 17 | , localConfig ? impure.localConfig 18 | , extraConfig ? impure.extraConfig 19 | , basedir ? impure.getBasedir args 20 | , ... 21 | } @ args: let 22 | 23 | # ---------------------------------------------------------------------------- # 24 | 25 | configModules = impure.getConfigModules args; 26 | 27 | modules = configModules ++ [ 28 | floco.nixosModules.default 29 | { config.floco.settings = { inherit system basedir; }; } 30 | ]; 31 | 32 | mod = lib.evalModules { inherit modules; }; 33 | 34 | 35 | # ---------------------------------------------------------------------------- # 36 | 37 | in { 38 | 39 | inherit (impure // args) 40 | system 41 | flocoRef 42 | floco 43 | lib 44 | pkgsFor 45 | globalConfig 46 | userConfig 47 | localConfig 48 | extraConfig 49 | ; 50 | 51 | inherit 52 | args 53 | basedir 54 | configModules 55 | modules 56 | mod 57 | ; 58 | 59 | pdefsExport = builtins.mapAttrs ( _: builtins.mapAttrs ( _: v: v._export ) ) 60 | mod.config.floco.pdefs; 61 | 62 | } 63 | 64 | 65 | # ---------------------------------------------------------------------------- # 66 | # 67 | # 68 | # 69 | # ============================================================================ # 70 | -------------------------------------------------------------------------------- /pkgs/cli/src/nix/fromPlock.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | let 8 | 9 | impure = import ./lib/impure.nix; 10 | 11 | in { 12 | system ? impure.system 13 | , flocoRef ? impure.flocoRef 14 | , floco ? impure.floco 15 | , lib ? impure.lib 16 | , globalConfig ? impure.globalConfig 17 | , userConfig ? impure.userConfig 18 | , localConfig ? impure.localConfig 19 | , extraConfig ? impure.extraConfig 20 | 21 | , outfile ? builtins.getEnv "OUTFILE" 22 | , asJSON ? ( builtins.getEnv "JSON" ) != "" 23 | , includePins ? ( builtins.getEnv "PINS" ) != "" 24 | , includeRootTreeInfo ? ( builtins.getEnv "TREE" ) != "" 25 | , lockDir ? /. + ( builtins.getEnv "LOCKDIR" ) 26 | } @ args: let 27 | 28 | # Sets low priority on potentially stale fields in `pdef' records. 29 | moduleForUpdate = impure.lib.libfloco.prepConfigForUpdate' { 30 | flocoTopModule = floco.nixosModules.floco; 31 | configModules = impure.getConfigModules args; 32 | settingsModule = { 33 | config.floco.settings = { inherit system; basedir = lockDir; }; 34 | }; 35 | }; 36 | 37 | mod = lib.evalModules { 38 | modules = [ 39 | moduleForUpdate 40 | floco.nixosModules.plockToPdefs 41 | { 42 | config._module.args.basedir = /. + ( dirOf outfile ); 43 | config._module.args.lockDir = lockDir; 44 | config.floco = { 45 | buildPlan.deriveTreeInfo = false; 46 | inherit includePins includeRootTreeInfo lockDir; 47 | }; 48 | } 49 | ]; 50 | }; 51 | 52 | contents.floco.pdefs = mod.config.floco.exports; 53 | in if asJSON then contents else lib.generators.toPretty {} contents 54 | 55 | 56 | # ---------------------------------------------------------------------------- # 57 | # 58 | # 59 | # 60 | # ============================================================================ # 61 | -------------------------------------------------------------------------------- /pkgs/cli/src/site-sql/pdefs.sql: -------------------------------------------------------------------------------- 1 | ../../../../db/pdefs.sql -------------------------------------------------------------------------------- /pkgs/cli/src/site-sql/trees.sql: -------------------------------------------------------------------------------- 1 | ../../../../db/trees.sql -------------------------------------------------------------------------------- /pkgs/cli/test/test-common.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | # ============================================================================ # 3 | # 4 | # 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | : "${REALPATH:=realpath}"; 9 | export REALPATH; 10 | 11 | # ---------------------------------------------------------------------------- # 12 | 13 | : "${FLOCO_LIBDIR:=$( $REALPATH "${BASH_SOURCE[0]%/*}/../src/lib"; )}"; 14 | export FLOCO_LIBDIR; 15 | 16 | 17 | # ---------------------------------------------------------------------------- # 18 | 19 | # Load common helpers 20 | 21 | #shellcheck source-path=SCRIPTDIR 22 | #shellcheck source=../src/lib/common.sh 23 | . "$FLOCO_LIBDIR/common.sh"; 24 | 25 | # ---------------------------------------------------------------------------- # 26 | 27 | echo "SPATH: $SPATH"; 28 | echo "SDIR: $SDIR"; 29 | echo "_as_me: $_as_me"; 30 | echo "system: $( nixSystem; )"; 31 | 32 | 33 | # ---------------------------------------------------------------------------- # 34 | 35 | flocoRef; 36 | 37 | 38 | # ---------------------------------------------------------------------------- # 39 | 40 | mktmmpAuto -d; 41 | ( 42 | cd "$_tmpAuto" >/dev/null||exit; 43 | echo '{ 44 | inputs.floco.url = "github:aakropotkin/floco"; 45 | outputs = _: {}; 46 | }' > flake.nix; 47 | $NIX flake lock; 48 | unset _floco_ref; 49 | flocoRef; 50 | ); 51 | 52 | 53 | # ---------------------------------------------------------------------------- # 54 | # 55 | # 56 | # 57 | # ============================================================================ # 58 | -------------------------------------------------------------------------------- /pkgs/lib/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib ? import ../../lib { inherit (nixpkgs) lib; } 8 | , nixpkgs ? ( import ../../inputs ).nixpkgs.flake 9 | , system ? args.pkgsFor.system or builtins.currentSystem 10 | , pkgsFor ? nixpkgs.legacyPackages.${system}.extend ( import ../../overlay.nix ) 11 | , semver ? pkgsFor.semver 12 | , nodejs ? pkgsFor.nodejs 13 | , treeFor ? pkgsFor.semver 14 | , bash ? pkgsFor.bash 15 | , ... 16 | } @ args: { 17 | 18 | semver = import ./semver { 19 | inherit lib nixpkgs system pkgsFor semver nodejs bash; 20 | }; 21 | 22 | treeFor = src: import ./tree-for.nix { inherit lib system bash treeFor src; }; 23 | 24 | } 25 | 26 | 27 | # ---------------------------------------------------------------------------- # 28 | # 29 | # 30 | # 31 | # ============================================================================ # 32 | -------------------------------------------------------------------------------- /pkgs/lib/semver/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib ? import ../../../lib { inherit (nixpkgs) lib; } 8 | , nixpkgs ? ( import ../../../inputs ).nixpkgs.flake 9 | , system ? args.pkgsFor.system or builtins.currentSystem 10 | , pkgsFor ? 11 | nixpkgs.legacyPackages.${system}.extend ( import ../../../overlay.nix ) 12 | , semver ? pkgsFor.semver 13 | , nodejs ? pkgsFor.nodejs 14 | , bash ? pkgsFor.bash 15 | , ... 16 | } @ args: { 17 | 18 | # Filter a list of versions to only those that satisfy a given semver range. 19 | rangeFilter = range: versions: import ./range-filt.nix { 20 | inherit system bash semver range versions; 21 | }; 22 | 23 | # Validate and normalize a version range. 24 | # This will convert `node-semver' extensions to the standard format to 25 | # `semver' 2.0.0 complaint ranges. 26 | # - '~1.0.0' -> '>=1.0.0 <1.1.0-0' 27 | # - '^1.0.0' -> '>=1.0.0 <2.0.0-0' 28 | rangeValid = range: import ./valid.nix { 29 | inherit system bash semver nodejs range; 30 | }; 31 | 32 | # Do `rangeA' and `rangeB' overlap? 33 | rangeIntersects = rangeA: rangeB: import ./intersects.nix { 34 | inherit system bash semver nodejs rangeA rangeB; 35 | }; 36 | 37 | # Is `rangeA' a subset of `rangeB'? 38 | rangeSubset = rangeA: rangeB: import ./subset.nix { 39 | inherit system bash semver nodejs rangeA rangeB; 40 | }; 41 | 42 | } 43 | 44 | 45 | # ---------------------------------------------------------------------------- # 46 | # 47 | # 48 | # 49 | # ============================================================================ # 50 | -------------------------------------------------------------------------------- /pkgs/lib/semver/intersects.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { system 8 | , bash 9 | , semver 10 | , nodejs 11 | 12 | , rangeA 13 | , rangeB 14 | }: let 15 | 16 | # ---------------------------------------------------------------------------- # 17 | 18 | sorted = builtins.sort builtins.lessThan [rangeA rangeB]; 19 | 20 | drv = derivation { 21 | name = "semver-intersects"; 22 | inherit system; 23 | rangeA = builtins.head sorted; 24 | rangeB = builtins.elemAt sorted 1; 25 | builder = "${bash}/bin/bash"; 26 | PATH = "${nodejs}/bin"; 27 | NODE_PATH = "${semver}/lib/node_modules"; 28 | args = ["-eu" "-o" "pipefail" "-c" '' 29 | node -e ' 30 | const semver = require("semver"); 31 | console.log( 32 | semver.intersects( process.env.rangeA, process.env.rangeB ) 33 | ); 34 | ' > "$out"; 35 | '']; 36 | preferLocalBuild = true; 37 | allowSubstitutes = ( builtins.currentSystem or "unknown" ) != system; 38 | }; 39 | 40 | 41 | # ---------------------------------------------------------------------------- # 42 | 43 | f = builtins.readFile drv.outPath; 44 | s = builtins.unsafeDiscardStringContext f; 45 | 46 | # ---------------------------------------------------------------------------- # 47 | 48 | in s == "true\n" 49 | 50 | 51 | # ---------------------------------------------------------------------------- # 52 | # 53 | # 54 | # 55 | # ============================================================================ # 56 | -------------------------------------------------------------------------------- /pkgs/lib/semver/range-filt.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { system 8 | , bash 9 | , semver 10 | , range 11 | , versions 12 | }: let 13 | 14 | # ---------------------------------------------------------------------------- # 15 | 16 | rangeFiltDrv = derivation { 17 | name = "semver-range-filter"; 18 | inherit system range; 19 | versions = builtins.sort builtins.lessThan versions; 20 | builder = "${bash}/bin/bash"; 21 | PATH = "${semver}/bin"; 22 | args = ["-eu" "-o" "pipefail" "-c" '' 23 | semver -r "$range" $versions > "$out"; 24 | '']; 25 | preferLocalBuild = true; 26 | allowSubstitutes = ( builtins.currentSystem or "unknown" ) != system; 27 | }; 28 | 29 | 30 | # ---------------------------------------------------------------------------- # 31 | 32 | f = builtins.readFile rangeFiltDrv.outPath; 33 | s = builtins.split "\n" ( builtins.unsafeDiscardStringContext f ); 34 | 35 | # ---------------------------------------------------------------------------- # 36 | 37 | in builtins.filter ( v: ( builtins.isString v ) && ( v != "" ) ) s 38 | 39 | 40 | # ---------------------------------------------------------------------------- # 41 | # 42 | # 43 | # 44 | # ============================================================================ # 45 | -------------------------------------------------------------------------------- /pkgs/lib/semver/subset.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Is `rangeA' a subset of `rangeB'? 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { system 8 | , bash 9 | , semver 10 | , nodejs 11 | 12 | , rangeA 13 | , rangeB 14 | }: let 15 | 16 | # ---------------------------------------------------------------------------- # 17 | 18 | drv = derivation { 19 | name = "semver-subset"; 20 | inherit system rangeA rangeB; 21 | builder = "${bash}/bin/bash"; 22 | PATH = "${nodejs}/bin"; 23 | NODE_PATH = "${semver}/lib/node_modules"; 24 | args = ["-eu" "-o" "pipefail" "-c" '' 25 | node -e ' 26 | const semver = require("semver"); 27 | console.log( 28 | semver.subset( process.env.rangeA, process.env.rangeB ) 29 | ); 30 | ' > "$out"; 31 | '']; 32 | preferLocalBuild = true; 33 | allowSubstitutes = ( builtins.currentSystem or "unknown" ) != system; 34 | }; 35 | 36 | 37 | # ---------------------------------------------------------------------------- # 38 | 39 | f = builtins.readFile drv.outPath; 40 | s = builtins.unsafeDiscardStringContext f; 41 | 42 | # ---------------------------------------------------------------------------- # 43 | 44 | in s == "true\n" 45 | 46 | 47 | # ---------------------------------------------------------------------------- # 48 | # 49 | # 50 | # 51 | # ============================================================================ # 52 | -------------------------------------------------------------------------------- /pkgs/lib/semver/valid.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { system 8 | , bash 9 | , semver 10 | , nodejs 11 | , range 12 | }: let 13 | 14 | # ---------------------------------------------------------------------------- # 15 | 16 | validRangeDrv = derivation { 17 | name = "semver-valid-range"; 18 | inherit system range; 19 | builder = "${bash}/bin/bash"; 20 | PATH = "${nodejs}/bin"; 21 | NODE_PATH = "${semver}/lib/node_modules"; 22 | args = ["-eu" "-o" "pipefail" "-c" '' 23 | node -e ' 24 | console.log( require( "semver/ranges/valid.js" )( process.env.range ) ); 25 | ' > "$out"; 26 | '']; 27 | preferLocalBuild = true; 28 | allowSubstitutes = ( builtins.currentSystem or "unknown" ) != system; 29 | }; 30 | 31 | 32 | # ---------------------------------------------------------------------------- # 33 | 34 | f = builtins.readFile validRangeDrv.outPath; 35 | s = builtins.unsafeDiscardStringContext f; 36 | l = builtins.stringLength s; 37 | 38 | # ---------------------------------------------------------------------------- # 39 | 40 | in builtins.substring 0 ( l - 1 ) s 41 | 42 | 43 | # ---------------------------------------------------------------------------- # 44 | # 45 | # 46 | # 47 | # ============================================================================ # 48 | -------------------------------------------------------------------------------- /pkgs/lib/tree-for.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib 8 | , system 9 | , treeFor 10 | , bash 11 | , src 12 | }: let 13 | 14 | # ---------------------------------------------------------------------------- # 15 | 16 | timestamp = toString builtins.currentTime; 17 | 18 | drv = derivation { 19 | name = let 20 | suff = if builtins.pathExists ( src + "/package-lock.json" ) then "" else 21 | "-" + timestamp; 22 | in "tree-for${suff}.json"; 23 | inherit system src; 24 | builder = "${bash}/bin/bash"; 25 | PATH = "${treeFor}/bin"; 26 | args = ["-eu" "-o" "pipefail" "-c" '' 27 | treeFor "$src" > "$out"; 28 | '']; 29 | preferLocalBuild = true; 30 | allowSubstitutes = ( builtins.currentSystem or "unknown" ) != system; 31 | }; 32 | 33 | 34 | # ---------------------------------------------------------------------------- # 35 | 36 | in lib.importJSON drv.outPath 37 | 38 | 39 | # ---------------------------------------------------------------------------- # 40 | # 41 | # 42 | # 43 | # ============================================================================ # 44 | -------------------------------------------------------------------------------- /pkgs/nix-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | compile_flags.txt 2 | -------------------------------------------------------------------------------- /pkgs/nix-plugin/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Produces a Nix Plugin with some `floco' extensions. 4 | # 5 | # Example plugin invocation ( for a trivial hello world plugin ) 6 | # NOTE: use `libhello.dylib' on Darwin. 7 | # $ nix --option plugin-files './result/libexec/libhello.so' eval \ 8 | # --expr 'builtins.hello' 9 | # "Hello, World!" 10 | # 11 | # 12 | # ---------------------------------------------------------------------------- # 13 | 14 | { nixpkgs ? ( import ../../inputs ).nixpkgs.flake 15 | , lib ? nixpkgs.lib 16 | , system ? builtins.currentSystem 17 | , pkgsFor ? nixpkgs.legacyPackages.${system} 18 | , stdenv ? pkgsFor.stdenv 19 | , nix-flake ? 20 | builtins.getFlake "github:NixOS/nix/${builtins.nixVersion or "2.14.1"}" 21 | , boost ? pkgsFor.boost 22 | , nlohmann_json ? pkgsFor.nlohmann_json 23 | , pkg-config ? pkgsFor.pkg-config 24 | , treeFor ? import ../treeFor { inherit nixpkgs system pkgsFor; } 25 | , semver ? import ../../fpkgs/semver { inherit nixpkgs system pkgsFor; } 26 | , nodejs ? pkgsFor.nodejs 27 | , npm ? nodejs.pkgs.npm 28 | , bash ? pkgsFor.bash 29 | , nix ? nix-flake.packages.${system}.nix 30 | , darwin ? pkgsFor.darwin 31 | }: import ./pkg-fun.nix { 32 | inherit 33 | stdenv 34 | boost 35 | nlohmann_json 36 | treeFor 37 | semver 38 | nodejs 39 | npm 40 | bash 41 | nix 42 | darwin 43 | pkg-config 44 | ; 45 | } 46 | 47 | 48 | # ---------------------------------------------------------------------------- # 49 | # 50 | # 51 | # 52 | # ============================================================================ # 53 | -------------------------------------------------------------------------------- /pkgs/nix-plugin/progs.hh: -------------------------------------------------------------------------------- 1 | /* ========================================================================== * 2 | * 3 | * Wraps executables allowing them to be run with captured outputs. 4 | * 5 | * -------------------------------------------------------------------------- */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | /* -------------------------------------------------------------------------- */ 12 | 13 | namespace nix { 14 | 15 | /* -------------------------------------------------------------------------- */ 16 | 17 | std::string runNpm( 18 | const Strings & args, const std::optional & input = {} 19 | ); 20 | 21 | std::string npmResolve( const std::string spec ); 22 | 23 | 24 | /* -------------------------------------------------------------------------- */ 25 | 26 | 27 | std::string runTreeFor( 28 | const Strings & args, const std::optional & input = {} 29 | ); 30 | 31 | 32 | std::string runSemver( 33 | const Strings & args, const std::optional & input = {} 34 | ); 35 | 36 | 37 | /* -------------------------------------------------------------------------- */ 38 | 39 | } /* End Namespace `nix' */ 40 | 41 | 42 | /* -------------------------------------------------------------------------- * 43 | * 44 | * 45 | * 46 | * ========================================================================== */ 47 | -------------------------------------------------------------------------------- /pkgs/nix-plugin/tests/parse.cc: -------------------------------------------------------------------------------- 1 | 2 | #include "../parse.hh" 3 | #include 4 | 5 | int 6 | main( int argc, char * argv[], char ** envp ) 7 | { 8 | 9 | std::cerr << "0: "; 10 | floco::parse::ParsedSpec( std::nullopt, "lodash", "4.2.17" ).show(); 11 | std::cerr << "\n"; 12 | 13 | std::cerr << "1: "; 14 | floco::parse::ParsedSpec( "lodash@4.2.17" ).show(); 15 | std::cerr << "\n"; 16 | 17 | std::cerr << "2: "; 18 | floco::parse::ParsedSpec( "lodash", "4.2.17" ).show(); 19 | std::cerr << "\n"; 20 | 21 | std::cerr << "3: "; 22 | floco::parse::ParsedSpec( "@foo/lodash", "4.2.17" ).show(); 23 | std::cerr << "\n"; 24 | 25 | std::cerr << "4: "; 26 | floco::parse::ParsedSpec( "@foo/lodash", "~4.2.17" ).show(); 27 | std::cerr << "\n"; 28 | 29 | std::cerr << "5: "; 30 | floco::parse::ParsedSpec( "@foo/lodash@4.2.17" ).show(); 31 | std::cerr << "\n"; 32 | 33 | std::cerr << "6: "; 34 | floco::parse::ParsedSpec( "@foo/lodash/4.2.17" ).show(); 35 | std::cerr << "\n"; 36 | 37 | std::cerr << "7: "; 38 | floco::parse::ParsedSpec( "lodash/4.2.17" ).show(); 39 | std::cerr << "\n"; 40 | 41 | std::cerr << "8: "; 42 | floco::parse::ParsedSpec( "lodash/~4.2.17" ).show(); 43 | std::cerr << "\n"; 44 | 45 | std::cerr << "9: "; 46 | floco::parse::ParsedSpec( "lodash@~4.2.17" ).show(); 47 | std::cerr << "\n"; 48 | 49 | std::cerr << "10: "; 50 | floco::parse::ParsedSpec( "%40foo%2flodash%404.2.17" ).show(); 51 | std::cerr << "\n"; 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /pkgs/treeFor/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /pkgs/treeFor/bin.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | // USAGE: treeFor PATH-TO-PROJECT-DIR 3 | require( './index.js' ); 4 | -------------------------------------------------------------------------------- /pkgs/treeFor/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { nixpkgs ? ( import ../../inputs ).nixpkgs.flake 8 | , lib ? import ../../lib { inherit (nixpkgs) lib; } 9 | , system ? builtins.currentSystem 10 | , pkgsFor ? nixpkgs.legacyPackages.${system} 11 | , nodePackage ? pkgsFor.nodejs 12 | , extraModules ? [] 13 | }: let 14 | 15 | # ---------------------------------------------------------------------------- # 16 | 17 | fmod = ( lib.evalModules { 18 | modules = [ 19 | ../../modules/top 20 | ../../modules/configs/use-fetchzip.nix 21 | { 22 | config._module.args.pkgs = pkgsFor; 23 | config.floco.settings = { 24 | inherit system nodePackage; 25 | basedir = ./.; 26 | }; 27 | } 28 | ./floco-cfg.nix 29 | ] ++ ( lib.toList extraModules ); 30 | } ).config.floco; 31 | 32 | 33 | # ---------------------------------------------------------------------------- # 34 | 35 | pjs = lib.importJSON ./package.json; 36 | ident = pjs.name; 37 | inherit (pjs) version; 38 | 39 | 40 | # ---------------------------------------------------------------------------- # 41 | 42 | in fmod.packages.${ident}.${version}.global // { 43 | meta = fmod.packages.${ident}.${version}.global.meta // { 44 | mainProgram = "treeFor"; 45 | homepage = "https://github.com/aakropotkin/floco"; 46 | maintainers = ["Alex Ameen\u00e8s "]; 47 | license = lib.licenses.gpl3Only; 48 | }; 49 | } 50 | 51 | 52 | # ---------------------------------------------------------------------------- # 53 | # 54 | # 55 | # 56 | # ============================================================================ # 57 | -------------------------------------------------------------------------------- /pkgs/treeFor/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, config, pkgs, ... }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | pjs = lib.importJSON ./package.json; 12 | cfg = config.floco.packages.${pjs.name}.${pjs.version}; 13 | 14 | # ---------------------------------------------------------------------------- # 15 | 16 | in { 17 | 18 | # ---------------------------------------------------------------------------- # 19 | 20 | imports = [ 21 | ./pdefs.nix 22 | ../../fpkgs/arborist/floco-cfg.nix 23 | ]; 24 | 25 | 26 | # ---------------------------------------------------------------------------- # 27 | 28 | config.floco.buildPlan.deriveTreeInfo = true; 29 | 30 | 31 | # ---------------------------------------------------------------------------- # 32 | 33 | config.floco.packages.${pjs.name}.${pjs.version} = let 34 | arbv = baseNameOf cfg.trees.supported."node_modules/@npmcli/arborist".key; 35 | arbp = config.floco.packages."@npmcli/arborist".${arbv}; 36 | inherit (pkgs) system; 37 | in { 38 | trees.prod = derivation { 39 | inherit system; 40 | name = "node_modules"; 41 | builder = "${pkgs.bash}/bin/bash"; 42 | PATH = "${pkgs.coreutils}/bin"; 43 | arborist = arbp.global.outPath; 44 | args = ["-euc" '' 45 | mkdir -p "$out"; 46 | ln -s "$arborist/lib/node_modules" "$out/node_modules"; 47 | '']; 48 | preferLocalBuild = true; 49 | allowSubstitutes = ( builtins.currentSystem or "unknown" ) != system; 50 | }; 51 | }; 52 | 53 | 54 | # ---------------------------------------------------------------------------- # 55 | 56 | } 57 | 58 | 59 | # ---------------------------------------------------------------------------- # 60 | # 61 | # 62 | # 63 | # ============================================================================ # 64 | -------------------------------------------------------------------------------- /pkgs/treeFor/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/treefor", 3 | "version": "0.1.0", 4 | "bin": { 5 | "treeFor": "./bin.js" 6 | }, 7 | "dependencies": { 8 | "@npmcli/arborist": "^6.1.5" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /pkgs/treeFor/pdefs.nix: -------------------------------------------------------------------------------- 1 | { 2 | floco.pdefs."@floco/treefor"."0.1.0" = { 3 | depInfo = { 4 | "@npmcli/arborist" = { 5 | descriptor = "6.1.5"; 6 | runtime = true; 7 | }; 8 | }; 9 | binInfo = { 10 | binPairs = { 11 | "treeFor" = "./bin.js"; 12 | }; 13 | }; 14 | fetchInfo = { 15 | path = ./.; 16 | }; 17 | ident = "@floco/treefor"; 18 | ltype = "dir"; 19 | treeInfo = { 20 | "node_modules/@npmcli/arborist" = { 21 | key = "@npmcli/arborist/6.1.5"; 22 | link = true; 23 | }; 24 | }; 25 | version = "0.1.0"; 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /setup/functions/isScript: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-shell: bash; -*- 2 | # ============================================================================ # 3 | # 4 | # Identical to `/pkgs/stdenv/generic/setup.sh' 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | isScript() { 9 | local fn="$1"; 10 | local fd; 11 | local magic; 12 | exec {fd}< "$fn"; 13 | read -r -n 2 -u "$fd" magic; 14 | exec {fd}<&- 15 | if [[ "$magic" =~ \#! ]]; then 16 | return 0; 17 | else 18 | return 1; 19 | fi 20 | } 21 | 22 | declare -fx isScript; 23 | 24 | 25 | # ---------------------------------------------------------------------------- # 26 | # 27 | # 28 | # 29 | # ============================================================================ # 30 | -------------------------------------------------------------------------------- /setup/functions/unpatchShebang: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-shell: bash; -*- 2 | # ============================================================================ # 3 | # 4 | # Replace "patched" shebangs pointing to `/nix/store' paths with a regular 5 | # shebang using `/usr/bin/env'. 6 | # 7 | # ---------------------------------------------------------------------------- # 8 | 9 | #require isScript 10 | 11 | # ---------------------------------------------------------------------------- # 12 | 13 | unpatchShebang() { 14 | local timestamp oldInterpreterLine newInterpreterLine oldPath arg0 args; 15 | isScript "$1"||return 0; 16 | read -r oldInterpreterLine < "$1"; 17 | read -r oldPath arg0 args <<< "${oldInterpreterLine:2}"; 18 | case "$oldPath" in 19 | "${NIX_STORE:-/nix/store}/"*) :; ;; 20 | *) return 0; ;; 21 | esac 22 | newInterpreterLine="#! /usr/bin/env ${oldPath##*/}"; 23 | newInterpreterLine="$newInterpreterLine${arg0:+ $arg0}${args:+ $args}"; 24 | timestamp="$( stat --printf '%y' "$1"; )"; 25 | printf '%s' \ 26 | "$1: interpreter directive changed from \"$oldInterpreterLine\"" \ 27 | " to \"${newInterpreterLine:?}\"" >&2; 28 | echo '' >&2; 29 | { 30 | echo "$newInterpreterLine"; 31 | ${TAIL:-tail} -n +2 "$1"; 32 | } > "$1~"; 33 | ${CHMOD:-chmod} 0755 "$1~"; 34 | mv -- "$1~" "$1"; 35 | touch --date "$timestamp" "$1"; 36 | } 37 | 38 | declare -fx unpatchShebang; 39 | 40 | 41 | # ---------------------------------------------------------------------------- # 42 | # 43 | # 44 | # 45 | # ============================================================================ # 46 | -------------------------------------------------------------------------------- /setup/hooks/add-nmdir.sh: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-shell: bash; -*- 2 | # ============================================================================ # 3 | # 4 | # This setup hook copies/symlinks a `node_modules/' directory into the build 5 | # area ( at `$PWD/node_modules' ). 6 | # 7 | # 8 | # ---------------------------------------------------------------------------- # 9 | 10 | addNmDir() { 11 | local _from; 12 | 13 | [[ -z "${NMTREE:-}" ]] && return 0; 14 | 15 | if [[ -e ./node_modules ]]; then 16 | echo "addNmDir(): ERROR: node_modules directory already exists." >&2; 17 | return 1; 18 | fi 19 | 20 | if [[ -d "$NMTREE/node_modules" ]]; then 21 | _from="$NMTREE/node_modules"; 22 | elif [[ -d "$NMTREE/lib/node_modules" ]]; then 23 | _from="$NMTREE/lib/node_modules"; 24 | else 25 | _from="$NMTREE"; 26 | fi 27 | 28 | if [[ "${copyTree:-0}" -ne 1 ]]; then 29 | ln -s -T -- "$_from" ./node_modules; 30 | else 31 | cp -r --reflink=auto -T -- "$_from" ./node_modules; 32 | chmod -R +w ./node_modules; 33 | fi 34 | 35 | if [[ -d ./node_modules/.bin ]]; then 36 | addToSearchPath PATH "$PWD/node_modules/.bin"; 37 | fi 38 | } 39 | 40 | preConfigureHooks+=( addNmDir ); 41 | 42 | 43 | # ---------------------------------------------------------------------------- # 44 | # 45 | # 46 | # 47 | # ============================================================================ # 48 | -------------------------------------------------------------------------------- /setup/hooks/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { nixpkgs ? ( import ../../inputs ).nixpkgs.flake 8 | , lib ? nixpkgs.lib 9 | , system ? builtins.currentSystem 10 | , pkgsFor ? nixpkgs.legacyPackages.${system} 11 | , makeSetupHook ? pkgsFor.makeSetupHook 12 | , jq ? pkgsFor.jq 13 | }: let 14 | 15 | # ---------------------------------------------------------------------------- # 16 | 17 | # Join all hooks into a single file. 18 | # This really demands that each hook be written in such a way that only 19 | # function definitions and appends to hook lists are defined at the top level. 20 | joined = let 21 | hooks = [ 22 | ./run-pjs-script.sh 23 | ./add-nmdir.sh 24 | ./set-node-path.sh 25 | ]; 26 | contents = map builtins.readFile hooks; 27 | body = builtins.concatStringsSep "\n" contents; 28 | in builtins.toFile "joined-hooks.sh" body; 29 | 30 | 31 | # ---------------------------------------------------------------------------- # 32 | 33 | in makeSetupHook { 34 | name = "floco-hooks"; 35 | substitutions.jq = lib.getBin jq; 36 | } joined 37 | 38 | 39 | # ---------------------------------------------------------------------------- # 40 | # 41 | # 42 | # 43 | # ============================================================================ # 44 | -------------------------------------------------------------------------------- /setup/hooks/run-pjs-script.sh: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-shell: bash; -*- 2 | # ============================================================================ # 3 | # 4 | # This is a minimal form of `run-script.sh' optimized for use in derivations. 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | runPjsScript() { 9 | local _body; 10 | case "$1" in 11 | -i|--ignore-missing) IGNORE_MISSING=:; shift; ;; 12 | -I|--no-ignore-missing) IGNORE_MISSING=; shift; ;; 13 | *) :; ;; 14 | esac 15 | #shellcheck disable=SC2016 16 | _body="$( 17 | @jq@/bin/jq -r --arg sname "$1" '.scripts[$sname] // null' ./package.json; 18 | )"; 19 | if [[ "$_body" = 'null' ]]; then 20 | if [[ -z "${IGNORE_MISSING:-}" ]]; then 21 | echo "runPjsScript(): ERROR: script \`$1' is undefined." >&2; 22 | return 1; 23 | fi 24 | return 0; 25 | fi 26 | # TODO: set `npm_config_*' vars 27 | eval "$_body"; 28 | } 29 | 30 | runPjsScripts() { 31 | declare -a _opts; 32 | declare -a _scripts; 33 | _opts=(); 34 | _scripts=(); 35 | while [[ "$#" -gt 0 ]]; do 36 | case "$1" in 37 | -*) _opts+=( "$1" ); ;; 38 | *) _scripts+=( "$1" ); ;; 39 | esac 40 | shift; 41 | done 42 | for s in "${_scripts[@]}"; do 43 | runPjsScript "${_opts[@]}" "$s"; 44 | done 45 | } 46 | 47 | npm() { 48 | case "$1" in 49 | run) runPjsScript "$2"; ;; 50 | *) command npm "$@"; ;; 51 | esac 52 | } 53 | 54 | yarn() { 55 | case "$1" in 56 | run) runPjsScript "$2"; ;; 57 | build) runPjsScripts prebuild build postbuild prepublish; ;; 58 | *) command yarn "$@"; ;; 59 | esac 60 | } 61 | 62 | 63 | 64 | # ---------------------------------------------------------------------------- # 65 | # 66 | # 67 | # 68 | # ============================================================================ # 69 | -------------------------------------------------------------------------------- /setup/hooks/set-node-path.sh: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; sh-shell: bash; -*- 2 | # ============================================================================ # 3 | # 4 | # This setup hook adds every build inputs' `lib/node_modules/' directory 5 | # to `NODE_PATH' 6 | # 7 | # ---------------------------------------------------------------------------- # 8 | 9 | export NODE_PATH; 10 | 11 | addPkgToNodePath() { 12 | if [[ -d "$1/lib/node_modules" ]]; then 13 | addToSearchPath NODE_PATH "$1/lib/node_modules"; 14 | fi 15 | } 16 | 17 | addEnvHooks "$hostOffset" addPkgToNodePath; 18 | 19 | 20 | # ---------------------------------------------------------------------------- # 21 | # 22 | # 23 | # 24 | # ============================================================================ # 25 | -------------------------------------------------------------------------------- /setup/show.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | # NOTE: This script is a draft. 4 | 5 | : "${JQ:=jq}"; 6 | 7 | declare -a fields; 8 | fields=(); 9 | 10 | while [[ "$#" -gt 0 ]]; do 11 | case "$1" in 12 | -d|--deps|--dependencies) 13 | fields+=( dependencies devDependencies ); 14 | : "${JOIN_DEPS=:}"; 15 | ;; 16 | -p|--prod|--prod-deps|--proddeps|--prod-dependencies) 17 | fields+=( dependencies ); 18 | ;; 19 | -D|--dev|--dev-deps|--devdeps|--dev-dependencies) 20 | fields+=( devDependencies ); 21 | ;; 22 | -o|--override|--overrides) 23 | fields+=( overrides ); 24 | ;; 25 | -j|--join-deps) 26 | JOIN_DEPS=:; 27 | ;; 28 | -J|--no-join-deps) 29 | JOIN_DEPS=; 30 | ;; 31 | *) 32 | fields+=( "$1" ); 33 | ;; 34 | esac 35 | shift; 36 | done 37 | 38 | _cmd='{'; 39 | 40 | for f in "${fields[@]}"; do 41 | _cmd+="\"$f\":.[\"$f\"]," 42 | done 43 | _cmd="${_cmd%,}}"; 44 | 45 | if [[ -n "${JOIN_DEPS:-}" ]]; then 46 | _cmd+='|.+={ 47 | dependencies: ( ( .dependencies // {} ) + ( .devDependencies // {} ) ) 48 | }|del( .devDependencies )'; 49 | if [[ "${#fields[@]}" -eq 2 ]]; then 50 | _cmd+='|.dependencies'; 51 | fi 52 | fi 53 | 54 | $JQ "$_cmd" ./package.json; 55 | -------------------------------------------------------------------------------- /templates/basic/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Aggregates configs making them available to `default.nix', `flake.nix', 4 | # or other projects that want to consume this module/package as a dependency. 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | { 9 | imports = let 10 | maybePdefs = 11 | if builtins.pathExists ./pdefs.nix then [./pdefs.nix] else 12 | if builtins.pathExists ./pdefs.json then [{ 13 | _file = ./pdefs.json; 14 | config = let 15 | c = builtins.fromJSON ( builtins.readFile ./pdefs.json ); 16 | in c.config or c; 17 | }] else []; 18 | maybeFoverrides = 19 | if builtins.pathExists ./foverrides.nix then [./foverrides.nix] else 20 | if builtins.pathExists ./foverrides.json then [{ 21 | _file = ./foverrides.json; 22 | config = let 23 | c = builtins.fromJSON ( builtins.readFile ./foverrides.json ); 24 | in c.config or c; 25 | }] else []; 26 | in maybePdefs ++ maybeFoverrides ++ [ 27 | # CHANGEME: If you depend on other `floco' projects, you can import their 28 | # `floco-cfg.nix' files here to make those configs available. 29 | ]; 30 | 31 | # CHANGEME: If your project doesn't have dependency cycles, and you have 32 | # `.depInfo.*.pin' records, you can enable symlinked trees with: 33 | ## config.floco.buildPlan.deriveTreeInfo = true; 34 | } 35 | 36 | 37 | # ---------------------------------------------------------------------------- # 38 | # 39 | # 40 | # 41 | # ============================================================================ # 42 | -------------------------------------------------------------------------------- /templates/basic/shell.nix: -------------------------------------------------------------------------------- 1 | (import ./default.nix {}).devShell -------------------------------------------------------------------------------- /templates/registry/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Package shim exposing installable targets from `floco' modules. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { floco ? builtins.getFlake "github:aakropotkin/floco" 8 | , lib ? floco.lib 9 | , system ? builtins.currentSystem 10 | , extraModules ? [] 11 | }: let 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | inherit (import ./info.nix) ident version; 16 | 17 | # ---------------------------------------------------------------------------- # 18 | 19 | fmod = lib.evalModules { 20 | modules = [ 21 | floco.nixosModules.floco 22 | { config.floco.settings = { inherit system; }; } 23 | ./floco-cfg.nix 24 | ] ++ ( lib.toList extraModules ); 25 | }; 26 | 27 | 28 | # ---------------------------------------------------------------------------- # 29 | 30 | # This attrset holds a few derivations related to our package. 31 | in fmod.config.floco.packages.${ident}.${version} 32 | 33 | 34 | # ---------------------------------------------------------------------------- # 35 | # 36 | # 37 | # 38 | # ============================================================================ # 39 | -------------------------------------------------------------------------------- /templates/registry/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Aggregates configs making them available to `default.nix', `flake.nix', 4 | # or other projects that want to consume this module/package as a dependency. 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | { 9 | imports = let 10 | maybePdefs = 11 | if builtins.pathExists ./pdefs.nix then [./pdefs.nix] else 12 | if builtins.pathExists ./pdefs.json then [{ 13 | _file = ./pdefs.json; 14 | config = let 15 | c = builtins.fromJSON ( builtins.readFile ./pdefs.json ); 16 | in c.config or c; 17 | }] else []; 18 | maybeFoverrides = 19 | if builtins.pathExists ./foverrides.nix then [./foverrides.nix] else 20 | if builtins.pathExists ./foverrides.json then [{ 21 | _file = ./foverrides.json; 22 | config = let 23 | c = builtins.fromJSON ( builtins.readFile ./foverrides.json ); 24 | in c.config or c; 25 | }] else []; 26 | in maybePdefs ++ maybeFoverrides ++ [ 27 | # CHANGEME: If you depend on other `floco' projects, you can import their 28 | # `floco-cfg.nix' files here to make those configs available. 29 | ]; 30 | 31 | # CHANGEME: If your project doesn't have dependency cycles, and you have 32 | # `.depInfo.*.pin' records, you can enable symlinked trees with: 33 | ## config.floco.buildPlan.deriveTreeInfo = true; 34 | } 35 | 36 | 37 | # ---------------------------------------------------------------------------- # 38 | # 39 | # 40 | # 41 | # ============================================================================ # 42 | -------------------------------------------------------------------------------- /templates/registry/foverrides.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Explicit config and overrides. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, config, ... }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | inherit (import ./info.nix) ident version; 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | in { 16 | 17 | # ---------------------------------------------------------------------------- # 18 | 19 | config.floco.packages.${ident}.${version} = let 20 | cfg = config.floco.packages.${ident}.${version}; 21 | in { # Begin target package overrides 22 | 23 | # ---------------------------------------------------------------------------- # 24 | 25 | # CHANGEME: The following provides an example of adding an input from 26 | # Nixpkgs to the "install" phase environment. 27 | # This is useful for linking against libraries when running `node-gyp' 28 | # and providing other utilities that may be required. 29 | # 30 | # Below that segment, you'll see an option to `copyTree' which will cause 31 | # the `node_modules/' directory to be copied and made writable at when 32 | # `install' scripts are run. 33 | # This can help resolve issues with packages such as `esbuild' which 34 | # modify the contents of their `node_modules/' directory at install time. 35 | 36 | ##installed = { pkgs, ... }: { 37 | ## extraBuildInputs = [ 38 | ## pkgs.pkg-config 39 | ## ]; 40 | ## copyTree = true; 41 | ##}; 42 | 43 | 44 | # ---------------------------------------------------------------------------- # 45 | 46 | }; # End target package overrides 47 | 48 | 49 | # ---------------------------------------------------------------------------- # 50 | 51 | } 52 | 53 | 54 | # ---------------------------------------------------------------------------- # 55 | # 56 | # 57 | # 58 | # ============================================================================ # 59 | -------------------------------------------------------------------------------- /templates/registry/info.nix: -------------------------------------------------------------------------------- 1 | { 2 | ident = "CHANGEME"; 3 | version = "CHANGEME"; 4 | } 5 | -------------------------------------------------------------------------------- /tests/cli/show-extra.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | # ============================================================================ # 3 | # 4 | # 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | set -eu; 9 | set -o pipefail; 10 | 11 | 12 | # ---------------------------------------------------------------------------- # 13 | 14 | : "${REALPATH:=realpath}"; 15 | : "${NIX:=nix}"; 16 | : "${JQ:=jq}"; 17 | 18 | # ---------------------------------------------------------------------------- # 19 | 20 | SPATH="$( $REALPATH "${BASH_SOURCE[0]}"; )"; 21 | SDIR="${SPATH%/*}"; 22 | _as_me="${SPATH##*/}"; 23 | 24 | # ---------------------------------------------------------------------------- # 25 | 26 | narHash="$( 27 | _e_floco_cfg='{ 28 | floco.pdefs.lodash."4.17.21" = { ident = "lodash"; version = "4.17.21"; }; 29 | }' $NIX run "$SDIR#floco" -- show lodash 4.17.21 --json \ 30 | |$JQ -r .fetchInfo.narHash; 31 | )"; 32 | 33 | echo "$_as_me: Expect: sha256-amyN064Yh6psvOfLgcpktd5dRNQStUYHHoIqiI6DMek=" >&2; 34 | echo "$_as_me: Got: $narHash" >&2; 35 | 36 | [[ "$narHash" = "sha256-amyN064Yh6psvOfLgcpktd5dRNQStUYHHoIqiI6DMek=" ]]; 37 | 38 | 39 | # ---------------------------------------------------------------------------- # 40 | # 41 | # 42 | # 43 | # ============================================================================ # 44 | 45 | -------------------------------------------------------------------------------- /tests/cli/translate/local-mod1/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Aggregates configs making them available to `default.nix', `flake.nix', 4 | # or other projects that want to consume this module/package as a dependency. 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | { 9 | imports = builtins.filter builtins.pathExists [ 10 | ./pdefs.nix 11 | ./foverrides.nix 12 | ]; 13 | } 14 | 15 | 16 | # ---------------------------------------------------------------------------- # 17 | # 18 | # 19 | # 20 | # ============================================================================ # 21 | -------------------------------------------------------------------------------- /tests/cli/translate/local-mod1/foverrides.nix: -------------------------------------------------------------------------------- 1 | { lib, pkgs, ... }: { 2 | 3 | floco.packages."@floco/phony"."4.2.0".built.extraNativeBuildInputs = [ 4 | pkgs.cowsay 5 | ]; 6 | 7 | floco.pdefs."@floco/phony"."4.2.0".depInfo.lodash = { 8 | runtime = lib.mkForce false; 9 | dev = lib.mkForce true; 10 | }; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /tests/cli/translate/local-mod1/package-2.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/phony", 3 | "version": "4.2.0", 4 | "dependencies": { 5 | "lodash": "^4.17.21", 6 | "pacote": "^13.3.0" 7 | }, 8 | "scripts": { 9 | "build": "cowsay hello > msg.txt" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/cli/translate/local-mod1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/phony", 3 | "version": "4.2.0", 4 | "dependencies": { 5 | "lodash": "^4.17.21" 6 | }, 7 | "scripts": { 8 | "build": "cowsay hello > msg.txt" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/cli/translate/local-mod1/pdefs.nix: -------------------------------------------------------------------------------- 1 | { 2 | floco = { 3 | pdefs = { 4 | "@floco/phony" = { 5 | "4.2.0" = { 6 | depInfo = { 7 | lodash = { 8 | descriptor = "^4.17.21"; 9 | runtime = true; 10 | }; 11 | }; 12 | fetchInfo = "path:."; 13 | ident = "@floco/phony"; 14 | lifecycle = { 15 | build = true; 16 | }; 17 | ltype = "dir"; 18 | treeInfo = { 19 | "node_modules/lodash" = { 20 | key = "lodash/4.17.21"; 21 | }; 22 | }; 23 | version = "4.2.0"; 24 | }; 25 | }; 26 | lodash = { 27 | "4.17.21" = { 28 | fetchInfo = { 29 | narHash = "sha256-amyN064Yh6psvOfLgcpktd5dRNQStUYHHoIqiI6DMek="; 30 | type = "tarball"; 31 | url = "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"; 32 | }; 33 | ident = "lodash"; 34 | ltype = "file"; 35 | treeInfo = { }; 36 | version = "4.17.21"; 37 | }; 38 | }; 39 | }; 40 | }; 41 | } -------------------------------------------------------------------------------- /tests/lib/check.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | # ============================================================================ # 3 | # 4 | # 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | set -eu; 9 | set -o pipefail; 10 | 11 | 12 | # ---------------------------------------------------------------------------- # 13 | 14 | : "${REALPATH:=realpath}"; 15 | : "${NIX:=nix}"; 16 | 17 | # ---------------------------------------------------------------------------- # 18 | 19 | SPATH="$( $REALPATH "${BASH_SOURCE[0]}"; )"; 20 | SDIR="${SPATH%/*}"; 21 | 22 | # ---------------------------------------------------------------------------- # 23 | 24 | [[ "$( $NIX eval --json -f "$SDIR"; )" == '[]' ]]; 25 | 26 | 27 | # ---------------------------------------------------------------------------- # 28 | # 29 | # 30 | # 31 | # ============================================================================ # 32 | -------------------------------------------------------------------------------- /tests/lib/data/pacote/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Package shim exposing installable targets from `floco' modules. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { floco ? builtins.getFlake "github:aakropotkin/floco" 8 | , lib ? floco.lib 9 | , system ? builtins.currentSystem 10 | , extraModules ? [] 11 | }: let 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | inherit (import ./info.nix) ident version; 16 | 17 | # ---------------------------------------------------------------------------- # 18 | 19 | fmod = lib.evalModules { 20 | modules = [ 21 | floco.nixosModules.floco 22 | { config.floco.settings = { inherit system; }; } 23 | ./floco-cfg.nix 24 | ] ++ ( lib.toList extraModules ); 25 | }; 26 | 27 | 28 | # ---------------------------------------------------------------------------- # 29 | 30 | # This attrset holds a few derivations related to our package. 31 | # We'll only expose `global' to the CLI. 32 | in fmod.config.floco.packages.${ident}.${version} 33 | 34 | 35 | # ---------------------------------------------------------------------------- # 36 | # 37 | # 38 | # 39 | # ============================================================================ # 40 | -------------------------------------------------------------------------------- /tests/lib/data/pacote/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Aggregates configs making them available to `default.nix', `flake.nix', 4 | # or other projects that want to consume this module/package as a dependency. 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | { 9 | imports = let 10 | ifExist = builtins.filter builtins.pathExists [ 11 | ./pdefs.nix # Generated `pdefs.nix' 12 | ./foverrides.nix # Explicit config 13 | ]; 14 | in ifExist ++ [ 15 | # CHANGEME: If you depend on other `floco' projects, you can import their 16 | # `floco-cfg.nix' files here to make those configs available. 17 | ]; 18 | 19 | # CHANGEME: If your project doesn't have dependency cycles, and you have 20 | # `.depInfo.*.pin' records, you can enable symlinked trees with: 21 | ## config.floco.buildPlan.deriveTreeInfo = true; 22 | } 23 | 24 | 25 | # ---------------------------------------------------------------------------- # 26 | # 27 | # 28 | # 29 | # ============================================================================ # 30 | -------------------------------------------------------------------------------- /tests/lib/data/pacote/foverrides.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Explicit config and overrides. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, config, ... }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | inherit (import ./info.nix) ident version; 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | in { 16 | 17 | # ---------------------------------------------------------------------------- # 18 | 19 | config.floco.packages.${ident}.${version} = let 20 | cfg = config.floco.packages.${ident}.${version}; 21 | in { # Begin target package overrides 22 | 23 | # ---------------------------------------------------------------------------- # 24 | 25 | # CHANGEME: The following provides an example of adding an input from 26 | # Nixpkgs to the "install" phase environment. 27 | # This is useful for linking against libraries when running `node-gyp' 28 | # and providing other utilities that may be required. 29 | 30 | ##installed = { pkgs, ... }: { 31 | ## extraBuildInputs = [ 32 | ## pkgs.pkg-config 33 | ## ]; 34 | ##}; 35 | 36 | 37 | # ---------------------------------------------------------------------------- # 38 | 39 | }; # End target package overrides 40 | 41 | 42 | # ---------------------------------------------------------------------------- # 43 | 44 | } 45 | 46 | 47 | # ---------------------------------------------------------------------------- # 48 | # 49 | # 50 | # 51 | # ============================================================================ # 52 | -------------------------------------------------------------------------------- /tests/lib/data/pacote/info.nix: -------------------------------------------------------------------------------- 1 | { ident = "pacote"; version = "13.3.0"; } 2 | -------------------------------------------------------------------------------- /tests/lib/data/proj0/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /tests/lib/data/proj0/pdefs.nix: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /tests/lib/data/proj1/foverrides.nix: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /tests/lib/data/proj1/pdefs.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /tests/lib/data/proj1/pdefs.nix: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /tests/lib/data/proj2/pdefs.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /tests/lib/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | let 8 | lib = import ../../lib {}; 9 | in ( import ./util.nix { inherit lib; } ) ++ 10 | ( import ./closures.nix { inherit lib; } ) ++ 11 | ( import ./tree { inherit lib; } ) ++ 12 | ( import ./sys.nix { inherit lib; } ) 13 | 14 | 15 | # ---------------------------------------------------------------------------- # 16 | # 17 | # 18 | # 19 | # ============================================================================ # 20 | -------------------------------------------------------------------------------- /tests/lib/sys.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib ? import ../../lib {} }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | cfgStar = { 12 | sysInfo.cpu = ["*"]; 13 | sysInfo.os = ["*"]; 14 | }; 15 | 16 | 17 | 18 | # ---------------------------------------------------------------------------- # 19 | 20 | in lib.runTests { 21 | 22 | # ---------------------------------------------------------------------------- # 23 | 24 | testSystemSupportFor0 = { 25 | expr = lib.libfloco.checkSystemSupportFor cfgStar { 26 | system = "x86_64-linux"; 27 | }; 28 | expected = true; 29 | }; 30 | 31 | 32 | # ---------------------------------------------------------------------------- # 33 | 34 | testSystemSupportFor1 = { 35 | expr = lib.libfloco.checkSystemSupportFor { 36 | sysInfo.cpu = ["!x86_64"]; 37 | sysInfo.os = ["linux"]; 38 | } { 39 | system = "x86_64-linux"; 40 | }; 41 | expected = false; 42 | }; 43 | 44 | 45 | # ---------------------------------------------------------------------------- # 46 | 47 | # FIXME 48 | #testSystemSupportFor2 = { 49 | # expr = lib.libfloco.checkSystemSupportFor { 50 | # sysInfo.cpu = ["!x86_64"]; 51 | # sysInfo.os = ["linux"]; 52 | # } { 53 | # system = "aarch-linux"; 54 | # }; 55 | # expected = true; 56 | #}; 57 | 58 | 59 | # ---------------------------------------------------------------------------- # 60 | 61 | } 62 | 63 | 64 | # ---------------------------------------------------------------------------- # 65 | # 66 | # 67 | # 68 | # ============================================================================ # 69 | -------------------------------------------------------------------------------- /tests/lib/tree/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib ? import ../../../lib {} }: 8 | ( import ./naive.nix { inherit lib; } ) ++ 9 | ( import ./hoist.nix { inherit lib; } ) 10 | 11 | 12 | # ---------------------------------------------------------------------------- # 13 | # 14 | # 15 | # 16 | # ============================================================================ # 17 | 18 | -------------------------------------------------------------------------------- /tests/lib/tree/hoist.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib ? import ../../../lib {} }: let 8 | 9 | mod = lib.evalModules { 10 | modules = [ 11 | ../../../modules/top 12 | ../data/pacote/floco-cfg.nix 13 | ]; 14 | }; 15 | 16 | info = import ../data/pacote/info.nix; 17 | 18 | 19 | # ---------------------------------------------------------------------------- # 20 | 21 | treeInfo = lib.libfloco.mkTreeInfoHoisted mod info; 22 | 23 | 24 | # ---------------------------------------------------------------------------- # 25 | 26 | in lib.runTests { 27 | testMkTreeInfoHoisted = { 28 | expr = builtins.isAttrs ( builtins.deepSeq treeInfo treeInfo ); 29 | expected = true; 30 | }; 31 | } 32 | 33 | 34 | # ---------------------------------------------------------------------------- # 35 | # 36 | # 37 | # 38 | # ============================================================================ # 39 | -------------------------------------------------------------------------------- /tests/lib/tree/naive.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib ? import ../../../lib {} }: let 8 | 9 | mod = lib.evalModules { 10 | modules = [ 11 | ../../../modules/top 12 | ../data/pacote/floco-cfg.nix 13 | ]; 14 | }; 15 | 16 | info = import ../data/pacote/info.nix; 17 | 18 | 19 | # ---------------------------------------------------------------------------- # 20 | 21 | treeInfo = lib.libfloco.mkTreeInfoWith mod info; 22 | 23 | 24 | # ---------------------------------------------------------------------------- # 25 | 26 | in lib.runTests { 27 | testMkTreeInfoNaive = { 28 | expr = builtins.isAttrs ( builtins.deepSeq treeInfo treeInfo ); 29 | expected = true; 30 | }; 31 | } 32 | 33 | 34 | # ---------------------------------------------------------------------------- # 35 | # 36 | # 37 | # 38 | # ============================================================================ # 39 | -------------------------------------------------------------------------------- /tests/lib/util.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | getBaseName = x: 12 | if ( builtins.isString x ) || ( builtins.isPath x ) then baseNameOf x else 13 | baseNameOf ( x.outPath or x._file or x.file ); 14 | 15 | 16 | # ---------------------------------------------------------------------------- # 17 | 18 | tests = { 19 | 20 | testFlocoConfigsFromDir0 = { 21 | expr = map getBaseName ( lib.libfloco.flocoConfigsFromDir ./data/proj0 ); 22 | expected = ["floco-cfg.nix"]; 23 | }; 24 | 25 | testFlocoConfigsFromDir1 = { 26 | expr = map getBaseName ( lib.libfloco.flocoConfigsFromDir ./data/proj1 ); 27 | expected = ["pdefs.nix" "foverrides.nix"]; 28 | }; 29 | 30 | testFlocoConfigsFromDir2 = { 31 | expr = map getBaseName ( lib.libfloco.flocoConfigsFromDir ./data/proj2 ); 32 | expected = ["pdefs.json"]; 33 | }; 34 | 35 | }; 36 | 37 | 38 | # ---------------------------------------------------------------------------- # 39 | 40 | in lib.runTests tests 41 | 42 | 43 | # ---------------------------------------------------------------------------- # 44 | # 45 | # 46 | # 47 | # ============================================================================ # 48 | -------------------------------------------------------------------------------- /tests/modules/fetchInfo/fetchTarballDrv.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | let 8 | 9 | lib = import ../../../lib {}; 10 | 11 | mod = lib.evalModules { 12 | modules = [ 13 | ../../../modules/fetchers 14 | ( { config, ... }: { 15 | options.input = lib.mkOption { 16 | type = config.fetchers.fetchTarballDrv.fetchInfo; 17 | }; 18 | config.input.url = 19 | "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"; 20 | 21 | config.fetchers.fetchTarball.serializerStyle = "string"; 22 | 23 | } ) 24 | ]; 25 | }; 26 | 27 | in mod.config.input 28 | 29 | 30 | # ---------------------------------------------------------------------------- # 31 | # 32 | # 33 | # 34 | # ============================================================================ # 35 | -------------------------------------------------------------------------------- /tests/modules/fetchInfo/file.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | let 8 | 9 | lib = import ../../../lib {}; 10 | 11 | mod = lib.evalModules { 12 | modules = [ 13 | ../../../modules/fetchers 14 | ( { config, ... }: { 15 | options.input = lib.mkOption { 16 | type = config.fetchers.fetchTree_file.fetchInfo; 17 | }; 18 | config.input.url = 19 | "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"; 20 | } ) 21 | ]; 22 | }; 23 | 24 | in mod.config.input 25 | 26 | 27 | # ---------------------------------------------------------------------------- # 28 | # 29 | # 30 | # 31 | # ============================================================================ # 32 | -------------------------------------------------------------------------------- /tests/modules/fetchInfo/path.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | let 8 | 9 | lib = import ../../../lib {}; 10 | 11 | mod = lib.evalModules { 12 | modules = [ 13 | ../../../modules/fetchers 14 | ( { config, ... }: { 15 | config.input.path = ./.; 16 | options.input = lib.mkOption { 17 | type = config.fetchers.path.fetchInfo; 18 | }; 19 | } ) 20 | ]; 21 | }; 22 | 23 | in removeAttrs mod.config.input ["filter"] 24 | 25 | 26 | # ---------------------------------------------------------------------------- # 27 | # 28 | # 29 | # 30 | # ============================================================================ # 31 | -------------------------------------------------------------------------------- /tests/modules/fetchInfo/tarball.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | let 8 | 9 | lib = import ../../../lib {}; 10 | 11 | mod = lib.evalModules { 12 | modules = [ 13 | ../../../modules/fetchers 14 | ( { config, ... }: { 15 | options.input = lib.mkOption { 16 | type = config.fetchers.fetchTree_tarball.fetchInfo; 17 | }; 18 | config.input.url = 19 | "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"; 20 | } ) 21 | ]; 22 | }; 23 | 24 | in mod.config.input 25 | 26 | 27 | # ---------------------------------------------------------------------------- # 28 | # 29 | # 30 | # 31 | # ============================================================================ # 32 | -------------------------------------------------------------------------------- /tests/modules/packages/check.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | set -eu; 3 | : "${NIX:=nix}"; 4 | : "${REALPATH:=realpath}"; 5 | SPATH="$( $REALPATH "${BASH_SOURCE[0]}"; )"; 6 | SDIR="${SPATH%/*}"; 7 | $NIX eval --impure -f "$SDIR/lodash.nix" --json --apply 'f: f {}'; 8 | -------------------------------------------------------------------------------- /tests/modules/packages/dist/check.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | set -eu; 3 | set -o pipefail; 4 | : "${NIX:=nix}"; 5 | : "${JQ:=jq}"; 6 | : "${TAR:=tar}"; 7 | : "${REALPATH:=realpath}"; 8 | SPATH="$( $REALPATH "${BASH_SOURCE[0]}"; )"; 9 | SDIR="${SPATH%/*}"; 10 | 11 | outpath="$( nix build -f "$SDIR" --no-link --print-out-paths "$@"; )"; 12 | manifest="$( $TAR tzf "$outpath"; )"; 13 | 14 | while read -r line; do 15 | case "$line" in 16 | package/foo|package/package.json) :; ;; 17 | *) echo "Unexpected file: $line" >&2; exit 1; ;; 18 | esac 19 | done <<<"$manifest" 20 | 21 | case "$manifest" in 22 | *package/foo*) :; ;; 23 | *) echo "Failed to package built file: foo" >&2; exit 1; ;; 24 | esac 25 | case "$manifest" in 26 | *package/package.json*) :; ;; 27 | *) echo "Failed to package file: package.json" >&2; exit 1; ;; 28 | esac 29 | 30 | exit 0; 31 | -------------------------------------------------------------------------------- /tests/modules/packages/dist/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Package shim exposing installable targets from `floco` modules. 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { nixpkgs ? ( import ../../../../inputs ).nixpkgs.flake 8 | , lib ? import ../../../../lib { inherit (nixpkgs) lib; } 9 | , system ? builtins.currentSystem 10 | , pkgsFor ? 11 | nixpkgs.legacyPackages.${system}.extend ( import ../../../../overlay.nix ) 12 | }: let 13 | 14 | # ---------------------------------------------------------------------------- # 15 | 16 | fmod = lib.evalModules { 17 | modules = [ 18 | ../../../../modules/top 19 | ./floco-cfg.nix 20 | { config._module.args.pkgs = pkgsFor; } 21 | ]; 22 | }; 23 | 24 | # ---------------------------------------------------------------------------- # 25 | 26 | in fmod.config.floco.packages."@floco/test"."4.2.0".dist 27 | 28 | 29 | # ---------------------------------------------------------------------------- # 30 | # 31 | # 32 | # 33 | # ============================================================================ # 34 | -------------------------------------------------------------------------------- /tests/modules/packages/dist/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | { 2 | config.floco.pdefs."@floco/test"."4.2.0" = { 3 | ident = "@floco/test"; 4 | version = "4.2.0"; 5 | ltype = "dir"; 6 | fetchInfo = { 7 | name = "source"; 8 | path = ./.; 9 | filter = name: type: ( baseNameOf name ) == "package.json"; 10 | }; 11 | lifecycle.build = true; 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /tests/modules/packages/dist/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/test", 3 | "version": "4.2.0", 4 | "scripts": { 5 | "build": "echo 'Howdy' > foo" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/modules/packages/lodash.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Tests evaluation of a package set, which just contains `lodash@4.17.21'. 4 | # 5 | # This essentially exists to force evaluation of all submodules. 6 | # 7 | # Run with: nix eval --impure --json -f ./lodash.nix --apply 'f: f {}'; 8 | # 9 | # ---------------------------------------------------------------------------- # 10 | 11 | { nixpkgs ? ( import ../../../inputs ).nixpkgs.flake 12 | , lib ? import ../../../lib { inherit (nixpkgs) lib; } 13 | , system ? builtins.currentSystem 14 | , pkgsFor ? 15 | nixpkgs.legacyPackages.${system}.extend ( import ../../../overlay.nix ) 16 | }: let 17 | 18 | # ---------------------------------------------------------------------------- # 19 | 20 | module = lib.evalModules { 21 | modules = [ 22 | ../../../modules/top 23 | { 24 | config.floco.pdefs.lodash."4.17.21" = { 25 | ident = "lodash"; 26 | version = "4.17.21"; 27 | }; 28 | config._module.args.pkgs = pkgsFor; 29 | } 30 | ]; 31 | }; 32 | 33 | # ---------------------------------------------------------------------------- # 34 | 35 | in module.config.floco.packages.lodash."4.17.21".key 36 | 37 | 38 | # ---------------------------------------------------------------------------- # 39 | # 40 | # 41 | # 42 | # ============================================================================ # 43 | -------------------------------------------------------------------------------- /tests/modules/packages/nodePackage/bin.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | // bin.js 3 | console.log( process.version ); 4 | -------------------------------------------------------------------------------- /tests/modules/packages/nodePackage/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { nixpkgs ? ( import ../../../../inputs ).nixpkgs.flake 8 | , lib ? import ../../../../lib { inherit (nixpkgs) lib; } 9 | , system ? builtins.currentSystem 10 | , pkgsFor ? nixpkgs.legacyPackages.${system} 11 | }: let 12 | 13 | # ---------------------------------------------------------------------------- # 14 | 15 | fmod = lib.evalModules { 16 | modules = [ 17 | ../../../../modules/top 18 | ./pdefs.nix ./foverrides.nix 19 | { 20 | config.floco.settings = { 21 | inherit system; 22 | nodePackage = pkgsFor.nodejs-18_x; 23 | }; 24 | } 25 | ]; 26 | }; 27 | 28 | 29 | # ---------------------------------------------------------------------------- # 30 | 31 | in fmod.config.floco.packages."@floco/test"."4.2.0".global 32 | 33 | 34 | # ---------------------------------------------------------------------------- # 35 | # 36 | # 37 | # 38 | # ============================================================================ # 39 | -------------------------------------------------------------------------------- /tests/modules/packages/nodePackage/foverrides.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, ... }: { 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | config.floco.packages."@floxo/test"."4.2.0" = { 12 | source = builtins.path { 13 | name = "source"; 14 | path = ./.; 15 | filter = name: type: 16 | builtins.elem ( baseNameOf name ) ["bin.js" "package.json"]; 17 | }; 18 | }; 19 | 20 | 21 | # ---------------------------------------------------------------------------- # 22 | 23 | } 24 | 25 | 26 | # ---------------------------------------------------------------------------- # 27 | # 28 | # 29 | # 30 | # ============================================================================ # 31 | -------------------------------------------------------------------------------- /tests/modules/packages/nodePackage/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/test", 3 | "version": "4.2.0", 4 | "bin": { 5 | "test": "./bin.js" 6 | }, 7 | "scripts": { 8 | "clean": "rm -rf ./node_modules" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/modules/packages/nodePackage/pdefs.nix: -------------------------------------------------------------------------------- 1 | { 2 | floco.pdefs."@floco/test"."4.2.0" = { 3 | ident = "@floco/test"; 4 | version = "4.2.0"; 5 | ltype = "dir"; 6 | binInfo.binPairs.test = "bin.js"; 7 | depInfo = {}; 8 | treeInfo = {}; 9 | fetchInfo = "path:."; 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /tests/modules/packages/overrides/bin.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | // bin.js 3 | require( './index.js' ); 4 | -------------------------------------------------------------------------------- /tests/modules/packages/overrides/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { nixpkgs ? ( import ../../../../inputs ).nixpkgs.flake 8 | , lib ? import ../../../../lib { inherit (nixpkgs) lib; } 9 | , system ? builtins.currentSystem 10 | , pkgsFor ? 11 | nixpkgs.legacyPackages.${system}.extend ( import ../../../../overlay.nix ) 12 | }: let 13 | 14 | # ---------------------------------------------------------------------------- # 15 | 16 | fmod = lib.evalModules { 17 | modules = [ 18 | ../../../../modules/top 19 | ./pdefs.nix ./foverrides.nix 20 | { config._module.args.pkgs = pkgsFor; } 21 | ]; 22 | }; 23 | 24 | 25 | # ---------------------------------------------------------------------------- # 26 | 27 | in fmod.config.floco.packages."@floco/test"."4.2.0".built 28 | 29 | 30 | # ---------------------------------------------------------------------------- # 31 | # 32 | # 33 | # 34 | # ============================================================================ # 35 | -------------------------------------------------------------------------------- /tests/modules/packages/overrides/foverrides.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib, config, pkgs, ... }: { 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | config.floco.packages."@floco/test"."4.2.0" = let 12 | cfg = config.floco.packages."@floco/test"."4.2.0"; 13 | tsVersion = baseNameOf cfg.trees.supported."node_modules/typescript".key; 14 | in { 15 | 16 | source = builtins.path { 17 | name = "source"; 18 | path = ./.; 19 | filter = name: type: 20 | builtins.elem ( baseNameOf name ) ["bin.js" "index.ts" "package.json"]; 21 | }; 22 | 23 | built.tree = cfg.trees.dev.overrideAttrs ( prev: { 24 | treeInfo = removeAttrs prev.treeInfo ["node_modules/typescript"]; 25 | } ); 26 | 27 | built.extraBuildInputs = [ 28 | config.floco.packages.typescript.${tsVersion}.global 29 | ]; 30 | 31 | built.override = { 32 | preBuild = '' 33 | ls -R ./node_modules >&2; 34 | ''; 35 | }; 36 | 37 | built.overrideAttrs = prev: { 38 | preBuild = let 39 | haveTs = builtins.any ( p: p.pname == "typescript" ) prev.buildInputs; 40 | in prev.preBuild + '' 41 | echo 'haveTs: ${lib.boolToString haveTs}' >&2; 42 | ''; 43 | }; 44 | 45 | }; 46 | 47 | 48 | } 49 | 50 | # ---------------------------------------------------------------------------- # 51 | # 52 | # 53 | # 54 | # ============================================================================ # 55 | -------------------------------------------------------------------------------- /tests/modules/packages/overrides/index.ts: -------------------------------------------------------------------------------- 1 | // index.ts 2 | import { 3 | VERSION, flatten, isEqual, last, omit, pick, pickBy, uniq 4 | } from 'lodash'; 5 | 6 | const f : Array = flatten( [[1, 2], [3, 4]] ); 7 | console.log( f ); 8 | const l : number = last( [1, 2, 3, 4] ) 9 | console.log( l ); 10 | const u : Array = uniq( [1, 2, 3, 1, 2, 3, 2] ); 11 | console.log( u ); 12 | console.log( VERSION ); 13 | -------------------------------------------------------------------------------- /tests/modules/packages/overrides/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/test", 3 | "version": "4.2.0", 4 | "bin": { 5 | "test": "./bin.js" 6 | }, 7 | "scripts": { 8 | "clean": "rm -rf ./node_modules ./index.js", 9 | "build": "tsc ./index.ts" 10 | }, 11 | "dependencies": { 12 | "lodash": "^4.17.21" 13 | }, 14 | "devDependencies": { 15 | "@types/lodash": "^4.14.191", 16 | "typescript": "^4.9.4" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/modules/pdef/deserial/depInfoDefaults/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | let 8 | lib = import ../../../../../lib {}; 9 | in import ./test.nix { inherit lib; } 10 | 11 | 12 | # ---------------------------------------------------------------------------- # 13 | # 14 | # 15 | # 16 | # ============================================================================ # 17 | -------------------------------------------------------------------------------- /tests/modules/pdef/deserial/depInfoDefaults/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | { imports = [./pdefs.nix]; } 2 | -------------------------------------------------------------------------------- /tests/modules/pdef/deserial/depInfoDefaults/pdefs.nix: -------------------------------------------------------------------------------- 1 | { 2 | # Show that deserialized form of this sets `dev = true;' ( the default ) for 3 | # omitted fields. 4 | floco.pdefs."@floco/phony"."4.2.0" = { 5 | ident = "@floco/phony"; 6 | version = "4.2.0"; 7 | ltype = "file"; 8 | fetchInfo = { 9 | type = "tarball"; 10 | url = "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"; 11 | narHash = "sha256-amyN064Yh6psvOfLgcpktd5dRNQStUYHHoIqiI6DMek="; 12 | }; 13 | treeInfo = {}; 14 | depInfo = { 15 | lodash = { 16 | descriptor = "^4.17.21"; 17 | pin = "4.17.21"; 18 | runtime = true; 19 | }; 20 | }; 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /tests/modules/pdef/deserial/depInfoDefaults/test.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib ? import ../../../../../lib {} }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | mod = lib.evalModules { 12 | modules = [ 13 | ../../../../../modules/top 14 | ./floco-cfg.nix 15 | ]; 16 | }; 17 | 18 | inherit (mod.config.floco) pdefs; 19 | 20 | 21 | # ---------------------------------------------------------------------------- # 22 | 23 | in lib.runTests { 24 | 25 | testDeserialHasDev = { 26 | expr = pdefs."@floco/phony"."4.2.0".depInfo.lodash.dev; 27 | expected = true; 28 | }; 29 | 30 | } 31 | 32 | 33 | # ---------------------------------------------------------------------------- # 34 | # 35 | # 36 | # 37 | # ============================================================================ # 38 | -------------------------------------------------------------------------------- /tests/modules/pdef/deserial/noFetch/default.nix: -------------------------------------------------------------------------------- 1 | # This test is a timebomb that will explode if any module attempts to fetch 2 | # the source tree. 3 | # This ensures that we are really just using the cached metadata. 4 | let 5 | lib = import ../../../../../lib {}; 6 | mod = lib.evalModules { modules = [./floco-cfg.nix]; }; 7 | rsl = removeAttrs mod.config ["_module" "metaFiles" "sourceInfo" "fetcher"]; 8 | in builtins.deepSeq rsl true 9 | -------------------------------------------------------------------------------- /tests/modules/pdef/deserial/noFetch/floco-cfg.nix: -------------------------------------------------------------------------------- 1 | { lib, ... }: { 2 | imports = [ 3 | ../../../../../modules/records/pdef/deserialize.nix 4 | ../../../../../modules/records/pdef 5 | { 6 | ident = "lodash"; 7 | version = "4.17.21"; 8 | ltype = "file"; 9 | fetchInfo = { 10 | type = "tarball"; 11 | url = "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"; 12 | narHash = "sha256-amyN064Yh6psvOfLgcpktd5dRNQStUYHHoIqiI6DMek="; 13 | }; 14 | treeInfo = {}; 15 | sourceInfo = throw "This shouldn't be referenced"; 16 | } 17 | ]; 18 | } 19 | -------------------------------------------------------------------------------- /tests/modules/pdef/from-registry.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Produces a `pdef' record from the default pipeline, pulling metadata from the 4 | # NPM registry. 5 | # 6 | # ---------------------------------------------------------------------------- # 7 | 8 | let 9 | nixpkgs = ( import ../../../inputs ).nixpkgs.flake; 10 | system = builtins.currentSystem; 11 | lib = import ../../../lib { inherit (nixpkgs) lib; }; 12 | in ( lib.evalModules { 13 | modules = [ 14 | ../../../modules/records/pdef 15 | { 16 | ident = "lodash"; 17 | version = "4.17.21"; 18 | _module.args.pkgs = 19 | nixpkgs.legacyPackages.${system}.extend ( import ../../../overlay.nix ); 20 | } 21 | ]; 22 | } ).config._export 23 | 24 | 25 | # ---------------------------------------------------------------------------- # 26 | # 27 | # 28 | # 29 | # ============================================================================ # 30 | -------------------------------------------------------------------------------- /tests/modules/plock/babel/babel-core.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | let 8 | 9 | lib = import ../../../lib {}; 10 | 11 | pl2pdefs = import ../../../modules/plockToPdefs/implementation.nix { 12 | inherit lib; 13 | lockDir = toString ./.; 14 | plock = lib.importJSON ./babel.core.package-lock.json; 15 | }; 16 | 17 | in pl2pdefs.exports 18 | 19 | 20 | # ---------------------------------------------------------------------------- # 21 | # 22 | # 23 | # 24 | # ============================================================================ # 25 | -------------------------------------------------------------------------------- /tests/modules/plock/babel/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/test", 3 | "version": "4.2.0", 4 | "dependencies": { 5 | "@babel/core": "^7.20.7" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/modules/plock/linked-locks/default.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # 4 | # 5 | # ---------------------------------------------------------------------------- # 6 | 7 | { lib ? import ../../../../lib {} }: let 8 | 9 | # ---------------------------------------------------------------------------- # 10 | 11 | mod = lib.evalModules { 12 | modules = [ 13 | ../../../../modules/top 14 | ../../../../modules/plock 15 | { 16 | config.lockDir = ./.; 17 | } 18 | ]; 19 | }; 20 | 21 | 22 | # ---------------------------------------------------------------------------- # 23 | 24 | in { 25 | inherit (mod.config) plents linkedLocks plock lockDir; 26 | } 27 | 28 | # ---------------------------------------------------------------------------- # 29 | # 30 | # 31 | # 32 | # ============================================================================ # 33 | -------------------------------------------------------------------------------- /tests/modules/plock/linked-locks/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/test-workspace", 3 | "version": "4.2.0", 4 | "workspaces": [ 5 | "./proj0", 6 | "./proj1" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /tests/modules/plock/linked-locks/proj0/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/proj0", 3 | "version": "4.2.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "@floco/proj0", 9 | "version": "4.2.0", 10 | "dependencies": { 11 | "lodash": "^4.17.21" 12 | } 13 | }, 14 | "node_modules/lodash": { 15 | "version": "4.17.21", 16 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", 17 | "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/modules/plock/linked-locks/proj0/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/proj0", 3 | "version": "4.2.0", 4 | "dependencies": { 5 | "lodash": "^4.17.21" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/modules/plock/linked-locks/proj1/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/proj1", 3 | "version": "4.2.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "@floco/proj1", 9 | "version": "4.2.0", 10 | "dependencies": { 11 | "@floco/proj0": "../proj0", 12 | "semver": "^7.3.8" 13 | } 14 | }, 15 | "node_modules/@floco/proj0": { 16 | "version": "4.2.0", 17 | "resolved": "file:../proj0", 18 | "dependencies": { 19 | "lodash": "^4.17.21" 20 | } 21 | }, 22 | "node_modules/lodash": { 23 | "version": "4.17.21", 24 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", 25 | "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" 26 | }, 27 | "node_modules/lru-cache": { 28 | "version": "6.0.0", 29 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", 30 | "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", 31 | "dependencies": { 32 | "yallist": "^4.0.0" 33 | }, 34 | "engines": { 35 | "node": ">=10" 36 | } 37 | }, 38 | "node_modules/semver": { 39 | "version": "7.3.8", 40 | "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", 41 | "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", 42 | "dependencies": { 43 | "lru-cache": "^6.0.0" 44 | }, 45 | "bin": { 46 | "semver": "bin/semver.js" 47 | }, 48 | "engines": { 49 | "node": ">=10" 50 | } 51 | }, 52 | "node_modules/yallist": { 53 | "version": "4.0.0", 54 | "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", 55 | "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/modules/plock/linked-locks/proj1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@floco/proj1", 3 | "version": "4.2.0", 4 | "dependencies": { 5 | "@floco/proj0": "../proj0", 6 | "semver": "^7.3.8" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/setup/lodash-install.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Tests the use of `install-module.sh' on a trivial project: `lodash'. 4 | # 5 | # This test is the "softball" case since this package has no `bin' executables, 6 | # and its default permissions when unpacked are suitable for consumption. 7 | # 8 | # The only real aspect of this test we may want to pay attention to is how 9 | # file modification time and file ownership are treated once installed; however 10 | # this test case will not PASS/FAIL based on these values. 11 | # 12 | # ---------------------------------------------------------------------------- # 13 | 14 | { nixpkgs ? ( import ../../inputs ).nixpkgs.flake 15 | , system ? builtins.currentSystem 16 | , pkgsFor ? nixpkgs.legacyPackages.${system} 17 | , lodash ? builtins.fetchTree { 18 | type = "tarball"; 19 | url = "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"; 20 | narHash = "sha256-amyN064Yh6psvOfLgcpktd5dRNQStUYHHoIqiI6DMek="; 21 | } 22 | , install_module ? ../../setup/install-module.sh 23 | }: derivation { 24 | inherit system install_module lodash; 25 | name = "install-module-lodash"; 26 | builder = "${pkgsFor.bash}/bin/bash"; 27 | PATH = "${pkgsFor.coreutils}/bin:${pkgsFor.findutils}/bin:" + 28 | "${pkgsFor.jq}/bin:${pkgsFor.bash}/bin"; 29 | args = ["-eu" "-o" "pipefail" "-c" '' 30 | bash -eu "$install_module" "$lodash" "$out/node_modules"; 31 | ls -Rla "$out" >&2; 32 | '']; 33 | preferLocalBuild = true; 34 | allowSubstitutes = ( builtins.currentSystem or "unknown" ) != system; 35 | } 36 | 37 | 38 | # ---------------------------------------------------------------------------- # 39 | # 40 | # 41 | # 42 | # ============================================================================ # 43 | -------------------------------------------------------------------------------- /tests/setup/run-script.nix: -------------------------------------------------------------------------------- 1 | # ============================================================================ # 2 | # 3 | # Tests the use of `run-scripts.sh' on a trivial project. 4 | # 5 | # This test does not search for `node_modules/.bin' directories in parent paths, 6 | # but does ensure that the flags `-i' and `-I' for `--[no-]ignore-missing' 7 | # works properly. 8 | # 9 | # ---------------------------------------------------------------------------- # 10 | 11 | { nixpkgs ? ( import ../../inputs ).nixpkgs.flake 12 | , system ? builtins.currentSystem 13 | , pkgsFor ? nixpkgs.legacyPackages.${system} 14 | , run_script ? ../../setup/run-script.sh 15 | }: derivation { 16 | inherit system run_script; 17 | name = "run-script-trivial"; 18 | builder = "${pkgsFor.bash}/bin/bash"; 19 | PATH = "${pkgsFor.coreutils}/bin:${pkgsFor.jq}/bin:${pkgsFor.bash}/bin"; 20 | args = ["-eu" "-o" "pipefail" "-c" '' 21 | cat <package.json 22 | { 23 | "name": "@floco/test", 24 | "version": "4.2.0", 25 | "scripts": { 26 | "build": "touch result", 27 | "test": 28 | "if test -r ./result; then echo PASS; else echo FAIL; exit 1; fi" 29 | } 30 | } 31 | EOF 32 | bash -eu "$run_script" -BPi prebuild build postbuild; 33 | bash -eu "$run_script" -BPI test|tee "$out"; 34 | '']; 35 | preferLocalBuild = true; 36 | allowSubstitutes = ( builtins.currentSystem or "unknown" ) != system; 37 | } 38 | 39 | 40 | # ---------------------------------------------------------------------------- # 41 | # 42 | # 43 | # 44 | # ============================================================================ # 45 | -------------------------------------------------------------------------------- /tests/setup/unpatch/script.sh: -------------------------------------------------------------------------------- 1 | #! /nix/store/yigicnz7r2znh1fq2l184svkb3h4v90g-bash-interactive-5.1-p16/bin/bash -i foo 2 | set -eu; 3 | set -o pipefail; 4 | echo hi; 5 | -------------------------------------------------------------------------------- /tests/setup/unpatch/script2.sh: -------------------------------------------------------------------------------- 1 | #!/nix/store/yigicnz7r2znh1fq2l184svkb3h4v90g-bash-interactive-5.1-p16/bin/bash 2 | set -eu; 3 | set -o pipefail; 4 | echo hi; 5 | -------------------------------------------------------------------------------- /tests/setup/unpatch/script3.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eu; 3 | set -o pipefail; 4 | echo hi; 5 | --------------------------------------------------------------------------------