From d17be3c12be951c26b9109576df5fd02b2fe6b1e Mon Sep 17 00:00:00 2001 From: Parthiv Seetharaman Date: Sun, 30 Jan 2022 13:30:31 -0800 Subject: [PATCH] Cleanup how polyfill works for digga-use outputs --- checks/default.nix | 7 +- default.nix | 15 ++ flake.lock | 17 ++ flake.nix | 28 ++-- jobs/default.nix | 7 +- jobs/flake.lock | 197 ----------------------- jobs/flake.nix | 33 ---- shell.nix | 9 +- ufr-polyfills/UnofficialFlakesRoadmap.md | 7 - ufr-polyfills/eachSystem.nix | 12 -- ufr-polyfills/flake.lock.nix | 115 ------------- ufr-polyfills/ufrContract.nix | 11 -- 12 files changed, 59 insertions(+), 399 deletions(-) create mode 100644 default.nix delete mode 100644 jobs/flake.lock delete mode 100644 jobs/flake.nix delete mode 100644 ufr-polyfills/UnofficialFlakesRoadmap.md delete mode 100644 ufr-polyfills/eachSystem.nix delete mode 100644 ufr-polyfills/flake.lock.nix delete mode 100644 ufr-polyfills/ufrContract.nix diff --git a/checks/default.nix b/checks/default.nix index 584d1d6..e2a2216 100644 --- a/checks/default.nix +++ b/checks/default.nix @@ -1,12 +1,11 @@ { system ? builtins.currentSystem -, inputs # flake style polyfill not possible, since this depends on digga's internals +, inputs ? (import ../.).inputs }: let - nixpkgs = inputs.nixpkgs; - digga = inputs.digga; + inherit (inputs) digga nixpkgs; lib = nixpkgs.lib // digga.lib; - pkgs = import nixpkgs { inherit system; config = { }; overlays = [ ]; }; + pkgs = nixpkgs.legacyPackages.${system}; in { diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..0e79e60 --- /dev/null +++ b/default.nix @@ -0,0 +1,15 @@ +let + inherit (import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; } + ) defaultNix; +in + # Pass this flake as inputs.digga + defaultNix // { inputs = defaultNix.inputs // { digga = defaultNix; }; } + diff --git a/flake.lock b/flake.lock index c7488bf..bf87399 100644 --- a/flake.lock +++ b/flake.lock @@ -68,6 +68,22 @@ "type": "github" } }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1641205782, + "narHash": "sha256-4jY7RCWUoZ9cKD8co0/4tFARpWB+57+r1bLLvXNJliY=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b7547d3eed6f32d06102ead8991ec52ab0a4f1a7", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "locked": { "lastModified": 1638122382, @@ -210,6 +226,7 @@ "blank": "blank", "deploy": "deploy", "devshell": "devshell", + "flake-compat": "flake-compat_2", "flake-utils-plus": "flake-utils-plus", "home-manager": "home-manager", "latest": "latest", diff --git a/flake.nix b/flake.nix index 9952b78..1cb28e4 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,11 @@ nixos-generators.url = "github:nix-community/nixos-generators"; nixos-generators.inputs.nixpkgs.follows = "blank"; + + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; }; outputs = @@ -69,22 +74,23 @@ }; # Unofficial Flakes Roadmap - Polyfills + # This project is committed to the Unofficial Flakes Roadmap! # .. see: https://demo.hedgedoc.org/s/_W6Ve03GK# - # .. also: /ufr-polyfills # Super Stupid Flakes (ssf) / System As an Input - Style: supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ]; - ufrContract = import ./ufr-polyfills/ufrContract.nix; - - # Dependency Groups - Style - checksInputs = { inherit nixpkgs; digga = self; }; - jobsInputs = { inherit nixpkgs; digga = self; }; - devShellInputs = { inherit nixpkgs devshell; }; + # Pass this flake(self) as "digga" + polyfillInputs = self.inputs // { digga = self; }; + polyfillOutput = loc: nixlib.lib.genAttrs supportedSystems (system: + import loc { inherit system; inputs = polyfillInputs; } + ); # .. we hope you like this style. # .. it's adopted by a growing number of projects. # Please consider adopting it if you want to help to improve flakes. + + # DEPRECATED - will be removed timely deprecated = import ./deprecated.nix { inherit (nixlib) lib; @@ -128,10 +134,10 @@ ''; # digga-local use - jobs = ufrContract supportedSystems ./jobs jobsInputs; - checks = ufrContract supportedSystems ./checks checksInputs; - devShell = ufrContract supportedSystems ./shell.nix devShellInputs; - + # system-space and pass sytem and input to each file + jobs = polyfillOutput ./jobs; + checks = polyfillOutput ./checks; + devShell = polyfillOutput ./shell.nix; }; } diff --git a/jobs/default.nix b/jobs/default.nix index b479b0b..91a10c5 100644 --- a/jobs/default.nix +++ b/jobs/default.nix @@ -1,11 +1,10 @@ { system ? builtins.currentSystem -, inputs ? import ../ufr-polyfills/flake.lock.nix ./. +, inputs ? (import ../.).inputs }: let - nixpkgs = inputs.nixpkgs; - digga = inputs.digga; - pkgs = import nixpkgs { inherit system; config = { }; overlays = [ ]; }; + inherit (inputs) digga; + pkgs = inputs.nixpkgs.legacyPackages.${system}; docOptions = digga.lib.mkFlake.options { self = { }; inputs = { }; }; evaledOptions = (pkgs.lib.evalModules { modules = [ docOptions ]; }).options; diff --git a/jobs/flake.lock b/jobs/flake.lock deleted file mode 100644 index c3ea239..0000000 --- a/jobs/flake.lock +++ /dev/null @@ -1,197 +0,0 @@ -{ - "nodes": { - "deploy": { - "inputs": { - "flake-compat": "flake-compat", - "naersk": "naersk", - "nixpkgs": [ - "digga", - "nixpkgs" - ], - "utils": [ - "digga", - "utils" - ] - }, - "locked": { - "lastModified": 1623011836, - "narHash": "sha256-02M4P3eqUdV+ouZb8n1KDR1CXeZQm17cKpjKZKi0c10=", - "owner": "serokell", - "repo": "deploy-rs", - "rev": "70d71b3027b1793b780f1e2435bdbbe1b0cb9ac6", - "type": "github" - }, - "original": { - "owner": "serokell", - "repo": "deploy-rs", - "type": "github" - } - }, - "devshell": { - "locked": { - "lastModified": 1622013274, - "narHash": "sha256-mK/Lv0lCbl07dI5s7tR/7nb79HunKnJik3KyR6yeI2k=", - "owner": "numtide", - "repo": "devshell", - "rev": "e7faf69e6bf8546517cc936c7f6d31c7eb3abcb2", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, - "digga": { - "inputs": { - "deploy": "deploy", - "devshell": "devshell", - "nixlib": "nixlib", - "nixos-generators": "nixos-generators", - "nixpkgs": [ - "nixpkgs" - ], - "utils": "utils" - }, - "locked": { - "narHash": "sha256-BimhA1sw5W+BnMdLfVrMS+WVDv3vi73OlRCyQI+xQkU=", - "path": "../", - "type": "path" - }, - "original": { - "path": "../", - "type": "path" - } - }, - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1606424373, - "narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-utils": { - "locked": { - "lastModified": 1623660459, - "narHash": "sha256-OTmOsh43po7r5F9s9H6lVCBQ2b0FikWbmiwLbMAGRdw=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "98c8d36b1828009b20f12544214683c7489935a1", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "naersk": { - "inputs": { - "nixpkgs": [ - "digga", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1622810282, - "narHash": "sha256-4wmvM3/xfD0hCdNDIXVzRMfL4yB1J+DjH6Zte2xbAxk=", - "owner": "nmattia", - "repo": "naersk", - "rev": "e8061169e1495871b56be97c5c51d310fae01374", - "type": "github" - }, - "original": { - "owner": "nmattia", - "ref": "master", - "repo": "naersk", - "type": "github" - } - }, - "nixlib": { - "locked": { - "lastModified": 1620519687, - "narHash": "sha256-+6Dd72b2CASuXm2W7KRxZIE7AOy/dj4mU28vaF+zxcs=", - "owner": "divnix", - "repo": "nixpkgs.lib", - "rev": "c7b6169809c5f74dd0c34f3d69e9d12ba4d448de", - "type": "github" - }, - "original": { - "owner": "divnix", - "repo": "nixpkgs.lib", - "type": "github" - } - }, - "nixos-generators": { - "inputs": { - "nixpkgs": [ - "digga", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1624117213, - "narHash": "sha256-hAoBANafVdM/+8Z6PrlPEKPN6LrdkM4qg2Q/ji0XUns=", - "owner": "nix-community", - "repo": "nixos-generators", - "rev": "c64d3c2153274a6ab355e57f5eedfe6f85073d24", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixos-generators", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1624300589, - "narHash": "sha256-anxKmaq18nWRzrgbPOajbjuq1cqsqgSsj1LTwU+7oQ4=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "38d369643e49043923a6d0e66e60b7fe54291d69", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "root": { - "inputs": { - "digga": "digga", - "nixpkgs": "nixpkgs" - } - }, - "utils": { - "inputs": { - "flake-utils": "flake-utils" - }, - "locked": { - "lastModified": 1624128793, - "narHash": "sha256-yZYvpT6i6iRK0x1a8k/LCoS7JGLVk6Yi1eqfhatnDLk=", - "owner": "gytis-ivaskevicius", - "repo": "flake-utils-plus", - "rev": "785e6f13b8c6131d1eee625a713e8475b2b0512b", - "type": "github" - }, - "original": { - "owner": "gytis-ivaskevicius", - "ref": "staging", - "repo": "flake-utils-plus", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/jobs/flake.nix b/jobs/flake.nix deleted file mode 100644 index fc65026..0000000 --- a/jobs/flake.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ - description = "Digga Library Jobs"; - - inputs = { - digga.url = "path:../"; - digga.inputs.nixpkgs.follows = "nixpkgs"; - }; - - outputs = inputs @ { self, nixpkgs, digga }: - let - - # Unofficial Flakes Roadmap - Polyfills - # .. see: https://demo.hedgedoc.org/s/_W6Ve03GK# - # .. also: /ufr-polyfills - - # Super Stupid Flakes / System As an Input - Style: - supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ]; - ufrContract = import ../ufr-polyfills/ufrContract.nix; - - # Dependency Groups - Style - jobsInputs = { inherit nixpkgs digga; }; - - # .. we hope you like this style. - # .. it's adopted by a growing number of projects. - # Please consider adopting it if you want to help to improve flakes. - - in - { - - jobs = ufrContract supportedSystems ./. jobsInputs; - - }; -} diff --git a/shell.nix b/shell.nix index 66d4ed9..0fcd1b9 100644 --- a/shell.nix +++ b/shell.nix @@ -1,10 +1,9 @@ -{ inputs, system ? builtins.currentSystem }: +{ system ? builtins.currentSystem +, inputs ? (import ./.).inputs +}: let - pkgs = import inputs.nixpkgs { - inherit system; config = { }; - overlays = [ ]; - }; + pkgs = inputs.nixpkgs.legacyPackages.${system}; devshell = import inputs.devshell { inherit pkgs system; }; withCategory = category: attrset: attrset // { inherit category; }; diff --git a/ufr-polyfills/UnofficialFlakesRoadmap.md b/ufr-polyfills/UnofficialFlakesRoadmap.md deleted file mode 100644 index 4f6d109..0000000 --- a/ufr-polyfills/UnofficialFlakesRoadmap.md +++ /dev/null @@ -1,7 +0,0 @@ -# Hey! - -This project is committed to the [Unofficial Flakes Roadmap (ufr)](https://demo.hedgedoc.org/s/_W6Ve03GK#). - - -_The future of flakes is bright again._ - diff --git a/ufr-polyfills/eachSystem.nix b/ufr-polyfills/eachSystem.nix deleted file mode 100644 index 6c7338c..0000000 --- a/ufr-polyfills/eachSystem.nix +++ /dev/null @@ -1,12 +0,0 @@ -# Builds a map from value to =value for each system. -# .. adopted from: https://github.com/numtide/flake-utils -# -systems: f: -let - op = attrs: system: - attrs // { - ${system} = f system; - }; -in -builtins.foldl' op { } systems - diff --git a/ufr-polyfills/flake.lock.nix b/ufr-polyfills/flake.lock.nix deleted file mode 100644 index ce9f1e0..0000000 --- a/ufr-polyfills/flake.lock.nix +++ /dev/null @@ -1,115 +0,0 @@ -# Adapted from https://github.com/edolstra/flake-compat/blob/master/default.nix -# -# This version only gives back the inputs. In that mode, flake becomes little -# more than a niv replacement. -src: -let - lockFilePath = src + "/flake.lock"; - - lockFile = builtins.fromJSON (builtins.readFile lockFilePath); - - # Emulate builtins.fetchTree - # - # TODO: only implement polyfill if the builtin doesn't exist? - fetchTree = - info: - if info.type == "github" then - { - outPath = fetchTarball { - url = "https://api.${info.host or "github.com"}/repos/${info.owner}/${info.repo}/tarball/${info.rev}"; - sha256 = info.narHash; - }; - rev = info.rev; - shortRev = builtins.substring 0 7 info.rev; - lastModified = info.lastModified; - narHash = info.narHash; - } - else if info.type == "git" then - { - outPath = - builtins.fetchGit - ({ url = info.url; sha256 = info.narHash; } - // (if info ? rev then { inherit (info) rev; } else { }) - // (if info ? ref then { inherit (info) ref; } else { }) - ); - lastModified = info.lastModified; - narHash = info.narHash; - } // (if info ? rev then { - rev = info.rev; - shortRev = builtins.substring 0 7 info.rev; - } else { }) - else if info.type == "path" then - { - outPath = builtins.path { path = info.path; }; - narHash = info.narHash; - } - else if info.type == "tarball" then - { - outPath = fetchTarball { - url = info.url; - sha256 = info.narHash; - }; - narHash = info.narHash; - } - else if info.type == "gitlab" then - { - inherit (info) rev narHash lastModified; - outPath = fetchTarball { - url = "https://${info.host or "gitlab.com"}/api/v4/projects/${info.owner}%2F${info.repo}/repository/archive.tar.gz?sha=${info.rev}"; - sha256 = info.narHash; - }; - shortRev = builtins.substring 0 7 info.rev; - } - else - # FIXME: add Mercurial, tarball inputs. - throw "flake input has unsupported input type '${info.type}'"; - - allNodes = - builtins.mapAttrs - (key: node: - let - sourceInfo = - if key == lockFile.root - then { } - else fetchTree (node.info or { } // removeAttrs node.locked [ "dir" ]); - - inputs = builtins.mapAttrs - (inputName: inputSpec: allNodes.${resolveInput inputSpec}) - (node.inputs or { }); - - # Resolve a input spec into a node name. An input spec is - # either a node name, or a 'follows' path from the root - # node. - resolveInput = inputSpec: - if builtins.isList inputSpec - then getInputByPath lockFile.root inputSpec - else inputSpec; - - # Follow an input path (e.g. ["dwarffs" "nixpkgs"]) from the - # root node, returning the final node. - getInputByPath = nodeName: path: - if path == [ ] - then nodeName - else - getInputByPath - # Since this could be a 'follows' input, call resolveInput. - (resolveInput lockFile.nodes.${nodeName}.inputs.${builtins.head path}) - (builtins.tail path); - - result = sourceInfo // { inherit inputs; inherit sourceInfo; }; - in - if node.flake or true then - result - else - sourceInfo - ) - lockFile.nodes; - - result = - if lockFile.version >= 5 && lockFile.version <= 7 - then allNodes.${lockFile.root}.inputs - else throw "lock file '${lockFilePath}' has unsupported version ${toString lockFile.version}"; - -in -result - diff --git a/ufr-polyfills/ufrContract.nix b/ufr-polyfills/ufrContract.nix deleted file mode 100644 index ac743fd..0000000 --- a/ufr-polyfills/ufrContract.nix +++ /dev/null @@ -1,11 +0,0 @@ -let - eachSystem = import ./eachSystem.nix; -in - -supportedSystems: -imprt: inputs: -eachSystem supportedSystems (system: - import imprt { - inherit inputs system; # The super stupid flakes contract `{ inputs, system }` - } -)