From f3f76283b33da22e069933addccdeed3a8eaa515 Mon Sep 17 00:00:00 2001 From: brian Date: Wed, 25 Feb 2026 10:51:43 -0500 Subject: [PATCH] local files --- .gitignore | 4 +- local-files/README.md | 0 local-files/build.nix | 27 ++++++ local-files/build.sh | 0 local-files/default.nix | 13 +++ local-files/hello.txt | 1 + local-files/npins/default.nix | 146 +++++++++++++++++++++++++++++++++ local-files/npins/sources.json | 18 ++++ local-files/some-file | 0 local-files/src/select.c | 0 local-files/src/select.h | 0 local-files/src/select.o | 0 local-files/world.txt | 1 + 13 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 local-files/README.md create mode 100644 local-files/build.nix create mode 100644 local-files/build.sh create mode 100644 local-files/default.nix create mode 100644 local-files/hello.txt create mode 100644 local-files/npins/default.nix create mode 100644 local-files/npins/sources.json create mode 100644 local-files/some-file create mode 100644 local-files/src/select.c create mode 100644 local-files/src/select.h create mode 100644 local-files/src/select.o create mode 100644 local-files/world.txt diff --git a/.gitignore b/.gitignore index f891451..33e3b85 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ result -*/result \ No newline at end of file +result* +*/result +*/result* \ No newline at end of file diff --git a/local-files/README.md b/local-files/README.md new file mode 100644 index 0000000..e69de29 diff --git a/local-files/build.nix b/local-files/build.nix new file mode 100644 index 0000000..e77a05d --- /dev/null +++ b/local-files/build.nix @@ -0,0 +1,27 @@ +{ stdenv, lib }: +let + fs = lib.fileset; + sourceFiles = fs.unions [ + ./hello.txt + ./world.txt + ./build.sh + (fs.fileFilter + (file: file.hasExt "c" || file.hasExt "h") + ./src + ) + ]; +in + +fs.trace sourceFiles + +stdenv.mkDerivation { + name = "fileset"; + src = fs.toSource { + root = ./.; + fileset = sourceFiles; + }; + postInstall = '' + cp -vr . $out + ''; +} + diff --git a/local-files/build.sh b/local-files/build.sh new file mode 100644 index 0000000..e69de29 diff --git a/local-files/default.nix b/local-files/default.nix new file mode 100644 index 0000000..d64279b --- /dev/null +++ b/local-files/default.nix @@ -0,0 +1,13 @@ +{ + system ? builtins.currentSystem, + sources ? import ./npins, +}: + +let + pkgs = import sources.nixpkgs { + config = { }; + overlays = [ ]; + inherit system; + }; +in +pkgs.callPackage ./build.nix { } \ No newline at end of file diff --git a/local-files/hello.txt b/local-files/hello.txt new file mode 100644 index 0000000..ce01362 --- /dev/null +++ b/local-files/hello.txt @@ -0,0 +1 @@ +hello diff --git a/local-files/npins/default.nix b/local-files/npins/default.nix new file mode 100644 index 0000000..6592476 --- /dev/null +++ b/local-files/npins/default.nix @@ -0,0 +1,146 @@ +/* + 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 + data = builtins.fromJSON (builtins.readFile ./sources.json); + version = data.version; + + # 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)); + concatMapStrings = f: list: concatStrings (map f list); + 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: + assert spec ? type; + let + path = + if spec.type == "Git" then + mkGitSource spec + else if spec.type == "GitRelease" then + mkGitSource spec + else if spec.type == "PyPi" then + mkPyPiSource spec + else if spec.type == "Channel" then + mkChannelSource spec + else if spec.type == "Tarball" then + mkTarballSource spec + else + builtins.throw "Unknown source type ${spec.type}"; + in + spec // { outPath = mayOverride name path; }; + + mkGitSource = + { + repository, + revision, + url ? null, + submodules, + hash, + branch ? null, + ... + }: + 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 + builtins.fetchTarball { + inherit url; + sha256 = hash; # FIXME: check nix version & use SRI hashes + } + 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 + 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 + builtins.fetchGit { + rev = revision; + inherit name; + # hash = hash; + inherit url submodules; + }; + + mkPyPiSource = + { url, hash, ... }: + builtins.fetchurl { + inherit url; + sha256 = hash; + }; + + mkChannelSource = + { url, hash, ... }: + builtins.fetchTarball { + inherit url; + sha256 = hash; + }; + + mkTarballSource = + { + url, + locked_url ? url, + hash, + ... + }: + builtins.fetchTarball { + url = locked_url; + sha256 = hash; + }; +in +if version == 5 then + builtins.mapAttrs mkSource data.pins +else + throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`" diff --git a/local-files/npins/sources.json b/local-files/npins/sources.json new file mode 100644 index 0000000..1756714 --- /dev/null +++ b/local-files/npins/sources.json @@ -0,0 +1,18 @@ +{ + "pins": { + "nixpkgs": { + "type": "Git", + "repository": { + "type": "GitHub", + "owner": "nixos", + "repo": "nixpkgs" + }, + "branch": "nixos-25.11", + "submodules": false, + "revision": "e764fc9a405871f1f6ca3d1394fb422e0a0c3951", + "url": "https://github.com/nixos/nixpkgs/archive/e764fc9a405871f1f6ca3d1394fb422e0a0c3951.tar.gz", + "hash": "0sch128mp1bcvbixx847ykyhsk5mnqfw1wgwi7igs2hhgdvammmi" + } + }, + "version": 5 +} diff --git a/local-files/some-file b/local-files/some-file new file mode 100644 index 0000000..e69de29 diff --git a/local-files/src/select.c b/local-files/src/select.c new file mode 100644 index 0000000..e69de29 diff --git a/local-files/src/select.h b/local-files/src/select.h new file mode 100644 index 0000000..e69de29 diff --git a/local-files/src/select.o b/local-files/src/select.o new file mode 100644 index 0000000..e69de29 diff --git a/local-files/world.txt b/local-files/world.txt new file mode 100644 index 0000000..cc628cc --- /dev/null +++ b/local-files/world.txt @@ -0,0 +1 @@ +world