-
-
Notifications
You must be signed in to change notification settings - Fork 22
Add "Flakeless Parts" template #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f987e50
feat: flake.nix trick for experimental nix cli
theutz 3fc901f
chore: add flake-parts
theutz 65c84db
chore: update other inputs
theutz acd1b8e
feat: invoke mkFlake to load modules
theutz e366a9e
feat: create flakeless-parts variant
theutz f44828e
ci: create test for flakeless-parts
theutz 32212a5
ci: exclude flakeless-parts from matrix test
theutz 662d6c2
ci: exclude actual template
theutz 11a278c
ci: empty to test
theutz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { config, lib, ... }: | ||
| { | ||
| systems = lib.mkDefault lib.systems.flakeExposed; | ||
|
|
||
| perSystem = | ||
| { pkgs, ... }: | ||
| { | ||
| apps.write-npins = { | ||
| program = config.flake-file.apps.write-npins pkgs; | ||
| }; | ||
| }; | ||
| } |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # flakeless-parts (npins w/ flake-parts) | ||
|
|
||
| This template is an example of using `flake-file.inputs` in a non-flakes | ||
| project with [npins](https://github.com/andir/npins), while still using [flake-parts](https://flake.parts). | ||
|
|
||
| It uses npins to pin and fetch inputs defined as options inside `./modules`. | ||
|
|
||
| ## Update npins | ||
|
|
||
| Update the `npins/` directory from your declared inputs: | ||
|
|
||
| ```shell | ||
| nix run .#write-npins | ||
| ``` | ||
|
|
||
| This will run `npins add` for | ||
| each input declared in your modules, using the correct npins subcommand | ||
| (`github`, `tarball`, `git`, etc.) based on the input URL scheme. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| let | ||
| sources = import ./npins; | ||
| with-inputs = import sources.with-inputs sources { | ||
| flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; | ||
| # uncomment on CI for local checkout | ||
| # flake-file = import ./../../modules; | ||
|
theutz marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| outputs = | ||
| inputs@{ flake-parts, import-tree, ... }: | ||
| flake-parts.lib.mkFlake { inherit inputs; } (import-tree ./modules); | ||
| in | ||
| with-inputs outputs | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| { outputs = _: import ./.; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { inputs, ... }: | ||
| { | ||
| imports = [ inputs.flake-file.flakeModules.flakeless-parts ]; | ||
|
|
||
| flake-file.inputs = { | ||
| flake-file.url = "github:vic/flake-file"; | ||
| import-tree.url = "github:vic/import-tree"; | ||
| with-inputs.url = "github:vic/with-inputs"; | ||
| nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; | ||
| flake-parts.url = "github:hercules-ci/flake-parts"; | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,249 @@ | ||
| /* | ||
| This file is provided under the MIT licence: | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| */ | ||
| # Generated by npins. Do not modify; will be overwritten regularly | ||
| let | ||
| # Backwards-compatibly make something that previously didn't take any arguments take some | ||
| # The function must return an attrset, and will unfortunately be eagerly evaluated | ||
| # Same thing, but it catches eval errors on the default argument so that one may still call it with other arguments | ||
| mkFunctor = | ||
| fn: | ||
| let | ||
| e = builtins.tryEval (fn { }); | ||
| in | ||
| (if e.success then e.value else { error = fn { }; }) // { __functor = _self: fn; }; | ||
|
|
||
| # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 | ||
| range = | ||
| first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); | ||
|
|
||
| # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 | ||
| stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); | ||
|
|
||
| # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 | ||
| stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); | ||
| concatStrings = builtins.concatStringsSep ""; | ||
|
|
||
| # If the environment variable NPINS_OVERRIDE_${name} is set, then use | ||
| # the path directly as opposed to the fetched source. | ||
| # (Taken from Niv for compatibility) | ||
| mayOverride = | ||
| name: path: | ||
| let | ||
| envVarName = "NPINS_OVERRIDE_${saneName}"; | ||
| saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; | ||
| ersatz = builtins.getEnv envVarName; | ||
| in | ||
| if ersatz == "" then | ||
| path | ||
| else | ||
| # this turns the string into an actual Nix path (for both absolute and | ||
| # relative paths) | ||
| builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" ( | ||
| if builtins.substring 0 1 ersatz == "/" then | ||
| /. + ersatz | ||
| else | ||
| /. + builtins.getEnv "PWD" + "/${ersatz}" | ||
| ); | ||
|
|
||
| mkSource = | ||
| name: spec: | ||
| { | ||
| pkgs ? null, | ||
| }: | ||
| assert spec ? type; | ||
| let | ||
| # Unify across builtin and pkgs fetchers. | ||
| # `fetchGit` requires a wrapper because of slight API differences. | ||
| fetchers = | ||
| if pkgs == null then | ||
| { | ||
| inherit (builtins) fetchTarball fetchurl; | ||
| # For some fucking reason, fetchGit has a different signature than the other builtin fetchers … | ||
| fetchGit = args: (builtins.fetchGit args).outPath; | ||
| } | ||
| else | ||
| { | ||
| fetchTarball = | ||
| { | ||
| url, | ||
| sha256, | ||
| }: | ||
| pkgs.fetchzip { | ||
| inherit url sha256; | ||
| extension = "tar"; | ||
| }; | ||
| inherit (pkgs) fetchurl; | ||
| fetchGit = | ||
| { | ||
| url, | ||
| submodules, | ||
| rev, | ||
| name, | ||
| narHash, | ||
| }: | ||
| pkgs.fetchgit { | ||
| inherit url rev name; | ||
| fetchSubmodules = submodules; | ||
| hash = narHash; | ||
| }; | ||
| }; | ||
|
|
||
| # Dispatch to the correct code path based on the type | ||
| path = | ||
| if spec.type == "Git" then | ||
| mkGitSource fetchers spec | ||
| else if spec.type == "GitRelease" then | ||
| mkGitSource fetchers spec | ||
| else if spec.type == "PyPi" then | ||
| mkPyPiSource fetchers spec | ||
| else if spec.type == "Channel" then | ||
| mkChannelSource fetchers spec | ||
| else if spec.type == "Tarball" then | ||
| mkTarballSource fetchers spec | ||
| else if spec.type == "Container" then | ||
| mkContainerSource pkgs spec | ||
| else | ||
| builtins.throw "Unknown source type ${spec.type}"; | ||
| in | ||
| spec // { outPath = mayOverride name path; }; | ||
|
|
||
| mkGitSource = | ||
| { | ||
| fetchTarball, | ||
| fetchGit, | ||
| ... | ||
| }: | ||
| { | ||
| repository, | ||
| revision, | ||
| url ? null, | ||
| submodules, | ||
| hash, | ||
| ... | ||
| }: | ||
| assert repository ? type; | ||
| # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository | ||
| # In the latter case, there we will always be an url to the tarball | ||
| if url != null && !submodules then | ||
| fetchTarball { | ||
| inherit url; | ||
| sha256 = hash; | ||
| } | ||
| else | ||
| let | ||
| url = | ||
| if repository.type == "Git" then | ||
| repository.url | ||
| else if repository.type == "GitHub" then | ||
| "https://github.com/${repository.owner}/${repository.repo}.git" | ||
| else if repository.type == "GitLab" then | ||
| "${repository.server}/${repository.repo_path}.git" | ||
| else if repository.type == "Forgejo" then | ||
| "${repository.server}/${repository.owner}/${repository.repo}.git" | ||
| else | ||
| throw "Unrecognized repository type ${repository.type}"; | ||
| urlToName = | ||
| url: rev: | ||
| let | ||
| matched = builtins.match "^.*/([^/]*)(\\.git)?$" url; | ||
|
|
||
| short = builtins.substring 0 7 rev; | ||
|
|
||
| appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else ""; | ||
| in | ||
| "${if matched == null then "source" else builtins.head matched}${appendShort}"; | ||
| name = urlToName url revision; | ||
| in | ||
| fetchGit { | ||
| rev = revision; | ||
| narHash = hash; | ||
|
|
||
| inherit name submodules url; | ||
| }; | ||
|
|
||
| mkPyPiSource = | ||
| { fetchurl, ... }: | ||
| { | ||
| url, | ||
| hash, | ||
| ... | ||
| }: | ||
| fetchurl { | ||
| inherit url; | ||
| sha256 = hash; | ||
| }; | ||
|
|
||
| mkChannelSource = | ||
| { fetchTarball, ... }: | ||
| { | ||
| url, | ||
| hash, | ||
| ... | ||
| }: | ||
| fetchTarball { | ||
| inherit url; | ||
| sha256 = hash; | ||
| }; | ||
|
|
||
| mkTarballSource = | ||
| { fetchTarball, ... }: | ||
| { | ||
| url, | ||
| locked_url ? url, | ||
| hash, | ||
| ... | ||
| }: | ||
| fetchTarball { | ||
| url = locked_url; | ||
| sha256 = hash; | ||
| }; | ||
|
|
||
| mkContainerSource = | ||
| pkgs: | ||
| { | ||
| image_name, | ||
| image_tag, | ||
| image_digest, | ||
| ... | ||
| }: | ||
| if pkgs == null then | ||
| builtins.throw "container sources require passing in a Nixpkgs value: https://github.com/andir/npins/blob/master/README.md#using-the-nixpkgs-fetchers" | ||
| else | ||
| pkgs.dockerTools.pullImage { | ||
| imageName = image_name; | ||
| imageDigest = image_digest; | ||
| finalImageTag = image_tag; | ||
| }; | ||
| in | ||
| mkFunctor ( | ||
| { | ||
| input ? ./sources.json, | ||
| }: | ||
| let | ||
| data = | ||
| if builtins.isPath input then | ||
| # while `readFile` will throw an error anyways if the path doesn't exist, | ||
| # we still need to check beforehand because *our* error can be caught but not the one from the builtin | ||
| # *piegames sighs* | ||
| if builtins.pathExists input then | ||
| builtins.fromJSON (builtins.readFile input) | ||
| else | ||
| throw "Input path ${toString input} does not exist" | ||
| else if builtins.isAttrs input then | ||
| input | ||
| else | ||
| throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset"; | ||
| version = data.version; | ||
| in | ||
| if version == 7 then | ||
| builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins | ||
| else | ||
| throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`" | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.