Compare commits

...

6 commits

Author SHA1 Message Date
72d18c49fe outputs: add updater script 2025-03-18 18:15:14 +01:00
59d6ba8f97 update-list: create
this nix file will store all updaters availabe in my nix dotfiles
2025-03-18 18:13:17 +01:00
476cf36b57 inputs: provide updateScripts 2025-03-18 18:11:09 +01:00
ec12c3eee4 pkgs/den-http-get-updater: init 2025-03-18 18:10:01 +01:00
7ec22b6e52 pkgs/den-update-script: init 2025-03-18 18:09:26 +01:00
3fb3b7771f lock: update 2025-03-17 11:00:31 +01:00
6 changed files with 260 additions and 22 deletions

View file

@ -1,29 +1,84 @@
let self = { let self = {
lock ? import ./lock.nix lock ? import lockFile,
, lib ? import "${(self {}).nixpkgs}/lib" lockFile ? ./lock.nix,
pkgs ? throw "inputs called without pkgs",
}: }:
{ {
inherit lock; inherit lock;
nixos-vscode-server = builtins.fetchTarball { nixos-vscode-server = rec {
name = "nixos-vscode-server";
url = "https://github.com/nix-community/nixos-vscode-server/archive/${lock.nixos-vscode-server.revision}.tar.gz"; url = "https://github.com/nix-community/nixos-vscode-server/archive/${lock.nixos-vscode-server.revision}.tar.gz";
updateScript = pkgs.den-http-get-updater {
fileLocation = lockFile;
previousHash = lock.nixos-vscode-server.sha256;
previousVersion = lock.nixos-vscode-server.revision;
versionUrl = "https://api.github.com/repos/nix-community/nixos-vscode-server/commits";
contentParser = "jq -rc '.[0].sha' <<< \"$newVersion\"";
prefetchUrlLocation = {
file = ./inputs.nix;
attrpath = "nixos-vscode-server.url";
};
};
outPath = builtins.fetchTarball {
inherit url;
name = "nixos-vscode-server";
sha256 = "${lock.nixos-vscode-server.sha256}"; sha256 = "${lock.nixos-vscode-server.sha256}";
}; };
nixpkgs = builtins.fetchTarball { };
name = "nixpkgs"; nixpkgs = rec {
url = "https://github.com/NixOS/nixpkgs/archive/${lock.nixpkgs.revision}.tar.gz"; url = "https://github.com/NixOS/nixpkgs/archive/${lock.nixpkgs.revision}.tar.gz";
updateScript = pkgs.den-http-get-updater {
fileLocation = lockFile;
previousHash = lock.nixpkgs.sha256;
previousVersion = lock.nixpkgs.revision;
versionUrl = "https://channels.nixos.org/nixos-24.11/git-revision";
prefetchUrlLocation = {
file = ./inputs.nix;
attrpath = "nixpkgs.url";
};
};
outPath = builtins.fetchTarball {
inherit url;
name = "nixpkgs";
sha256 = "${lock.nixpkgs.sha256}"; sha256 = "${lock.nixpkgs.sha256}";
}; };
nixpkgs-unstable = builtins.fetchTarball { };
name = "nixpkgs-unstable"; nixpkgs-unstable = rec {
url = "https://github.com/NixOS/nixpkgs/archive/${lock.nixpkgs-unstable.revision}.tar.gz"; url = "https://github.com/NixOS/nixpkgs/archive/${lock.nixpkgs-unstable.revision}.tar.gz";
updateScript = pkgs.den-http-get-updater {
fileLocation = lockFile;
previousHash = lock.nixpkgs-unstable.sha256;
previousVersion = lock.nixpkgs-unstable.revision;
versionUrl = "https://channels.nixos.org/nixos-unstable/git-revision";
prefetchUrlLocation = {
file = ./inputs.nix;
attrpath = "nixpkgs-unstable.url";
};
};
outPath = builtins.fetchTarball {
inherit url;
name = "nixpkgs-unstable";
sha256 = "${lock.nixpkgs-unstable.sha256}"; sha256 = "${lock.nixpkgs-unstable.sha256}";
}; };
cosmic-modules = builtins.fetchTarball { };
name = "cosmic-modules"; cosmic-modules = rec {
url = "https://github.com/lilyinstarlight/nixos-cosmic/archive/${lock.cosmic-modules.revision}.tar.gz"; url = "https://github.com/lilyinstarlight/nixos-cosmic/archive/${lock.cosmic-modules.revision}.tar.gz";
updateScript = pkgs.den-http-get-updater {
fileLocation = lockFile;
previousHash = lock.cosmic-modules.sha256;
previousVersion = lock.cosmic-modules.revision;
versionUrl = "https://api.github.com/repos/lilyinstarlight/nixos-cosmic/commits";
contentParser = "jq -rc '.[0].sha' <<< \"$newVersion\"";
prefetchUrlLocation = {
file = ./inputs.nix;
attrpath = "cosmic-modules.url";
};
};
outPath = builtins.fetchTarball {
inherit url;
name = "cosmic-modules";
sha256 = "${lock.cosmic-modules.sha256}"; sha256 = "${lock.cosmic-modules.sha256}";
}; };
};
}; };
in self in self

View file

@ -7,18 +7,18 @@
}; };
nixpkgs = { nixpkgs = {
# https://channels.nixos.org/nixos-24.11/git-revision # https://channels.nixos.org/nixos-24.11/git-revision
revision = "cdd2ef009676ac92b715ff26630164bb88fec4e0"; revision = "a1185f4064c18a5db37c5c84e5638c78b46e3341";
sha256 = "0r5c1l5cagxykyjfh1wsn8wk9vhay5dpwp36318hizn4rcrp9dm6"; sha256 = "0ipjb56fdhfvhgnrw0rvp89g0mplpyhjil29fqdcpmv4ablbadqc";
}; };
nixpkgs-unstable = { nixpkgs-unstable = {
# https://channels.nixos.org/nixos-unstable/git-revision # https://channels.nixos.org/nixos-unstable/git-revision
revision = "6607cf789e541e7873d40d3a8f7815ea92204f32"; revision = "c80f6a7e10b39afcc1894e02ef785b1ad0b0d7e5";
sha256 = "0lad6jan49sywk6xzgcivc4h3ln7grhjhb8q8jv2jwhwlgrfrxvh"; sha256 = "1sfb9g6fmyfligcsd1rmkamfqvy8kgn3p0sy8ickf6swi1zdbf0b";
}; };
cosmic-modules = { cosmic-modules = {
# https://api.github.com/repos/lilyinstarlight/nixos-cosmic/commits # https://api.github.com/repos/lilyinstarlight/nixos-cosmic/commits
# jsonpath: [1].sha # jsonpath: [1].sha
revision = "24785e84d4b3844936caffe2c56994bdef9a9300"; revision = "fcee247f21d21acb738ac208d6ed86e65c2e7240";
sha256 = "18qqbhw5kk5j2i741faamipbga590ywxkax19ny2nz3w2zfq64k4"; sha256 = "18xw0innlpswz35cf8n16myh5a24b4kpw0xckwm42c93zd5rm2zh";
}; };
} }

View file

@ -1,5 +1,6 @@
{ {
inputs ? import ./inputs.nix {}, inputsPath ? ./inputs.nix,
inputs ? import inputsPath {},
selfPath ? ./. selfPath ? ./.
}: }:
@ -16,7 +17,7 @@ systems = [
forEachSystem = lib.genAttrs systems; forEachSystem = lib.genAttrs systems;
self = { self = {
inherit inputs lib self; inherit inputs inputsPath lib self;
outPath = selfPath; outPath = selfPath;
modifiedNixpkgs = import ./pkgs/top-level/impure.nix; modifiedNixpkgs = import ./pkgs/top-level/impure.nix;
modifiedNixpkgsPure = import ./pkgs/top-level/default.nix; modifiedNixpkgsPure = import ./pkgs/top-level/default.nix;
@ -71,6 +72,30 @@ self = {
builtins.attrValues builtins.attrValues
builtins.listToAttrs builtins.listToAttrs
]; ];
# FIXME: currently impure
# NOTE: to run, you need to evaluate outputs.nix instead of default.nix
# nix-shell outputs.nix -A update
update = let
updateScript = (self.packagesForSystem (builtins.currentSystem)).den-update-script;
in updateScript {
path = "";
packages = lib.pipe ./update-list.nix [
import
(x: x self)
lib.attrsToList
(lib.imap1 (i: {name, value}: {
name = builtins.toString i;
value = value // {
# hack to pass isDerivation check in nixpkgs maintainers/scripts/update.nix
# https://github.com/NixOS/nixpkgs/blob/a1185f4064c18a5db37c5c84e5638c78b46e3341/maintainers/scripts/update.nix#L85
type = "derivation";
name = name;
};
}))
builtins.listToAttrs
lib.recurseIntoAttrs
];
};
}; };
in self in self

View file

@ -0,0 +1,106 @@
{
lib,
curl,
gawk,
jq,
nix,
writeScript,
}:
{
# location of file to modify
fileLocation,
previousHash,
previousVersion,
versionUrl,
prefetchUrlLocation ? null,
# change newVersion variable in it, if the contents of the page
# is not plaintext version
# (json for example)
contentParser ? "echo \"$newVersion\"",
unpack ? true,
name ? if unpack then "source" else null,
}:
assert builtins.isNull prefetchUrlLocation || lib.isAttrs prefetchUrlLocation;
assert lib.isAttrs prefetchUrlLocation && (
lib.isString prefetchUrlLocation.file or null ||
lib.isPath prefetchUrlLocation.file or null
);
assert lib.isAttrs prefetchUrlLocation && lib.isString prefetchUrlLocation.attrpath or null;
let
realFileLocation = builtins.toString fileLocation;
mark = builtins.hashString "sha256" previousHash;
mark' = lib.escapeShellArg mark;
prefetchUrlLocation' = lib.mapAttrs (_: lib.escapeShellArg) prefetchUrlLocation;
realFileLocation' = lib.escapeShellArg realFileLocation;
versionUrl' = lib.escapeShellArg versionUrl;
mark'' = lib.escapeShellArg (lib.escapeRegex mark);
previousVersion'' = lib.escapeShellArg (lib.escapeRegex previousVersion);
nixUnpack = lib.optionalString unpack "--unpack";
nixName = lib.optionalString (!builtins.isNull name) "--name \"${lib.escapeShellArg name}\"";
path = lib.makeBinPath [
curl
gawk
jq
nix
];
in
writeScript "den-http-get-updater" (''
PATH="${lib.escapeShellArg path}"
newVersion=$(curl -L "${versionUrl'}")
if [[ "$?" != 0 ]]; then
echo "error: fetching new version failed" 1>&2
exit 1
fi
newVersion=$(${contentParser})
awk -i inplace "{
sub(/${previousVersion''}/, \"$newVersion\")
# invalidate hash
sub(/${previousHash}/, \"${mark'}\")
}1" "${realFileLocation'}"
'' + lib.optionalString (!builtins.isNull prefetchUrlLocation) ''
nixUrlsResult=$(nix-instantiate --eval --json \
"${prefetchUrlLocation'.file}" \
-A "${prefetchUrlLocation'.attrpath}"
)
urlsType=$(jq -rc 'type' <<< "$nixUrlsResult")
if [ "$urlsType" = "array" ]; then
readarray -t prefetchUrls < <(
jq -rc '.[]' <<< "$nixUrlsResult"
)
elif [ "$urlsType" = "string" ]; then
readarray -t prefetchUrls < <(
jq -rc '.' <<< "$nixUrlsResult"
)
fi
prefetchSucceeded=1
for url in "''${prefetchUrls[@]}"; do
echo "trying prefetch '$url'...";
expectedHash=$(nix-prefetch-url "$url" ${nixUnpack} ${nixName})
if [[ -n $expectedHash ]]; then
echo "prefetch succeeded!"
echo "hash: $expectedHash"
awk -i inplace "{
sub(/${mark''}/, \"$expectedHash\")
}1" "${realFileLocation'}"
prefetchSucceeded=
break
fi
done
if [[ -n "$prefetchSucceeded" ]]; then
echo "warning: prefetch failed" 1>&2
exit 1
fi
'')

View file

@ -0,0 +1,39 @@
{
lib,
path,
overlayAttrname ? "den-outputs",
}:
assert lib.assertMsg (!lib.hasInfix "." overlayAttrname) (lib.pipe ''
overlayAttrname must not contain a dot (.),
because dot is used to reference package in a package set
inside nix-update-script.
'' [
lib.lines
(lib.concatStringsSep " ")
]);
let
updateScript = import (path + /maintainers/scripts/update.nix);
functionArgs = lib.functionArgs updateScript;
nameInFunctionArgs = name: lib.elem name (lib.attrNames functionArgs);
in
{
__functionArgs = functionArgs // { packages = false; };
__functor = _: args: let
# args.outputs should be an attrset of packages to update
overlay = _: _: {
"${overlayAttrname}" = args.packages;
};
in updateScript (lib.filterAttrs (name: _: nameInFunctionArgs name) args // {
include-overlays =
if !args ? updateScript then [ overlay ]
else if lib.isList args.updateScript then [ overlay ] ++ args.updateScript
else args.updateScript;
} // lib.optionalAttrs (args ? package) {
package = "${overlayAttrname}.${args.package}";
} // lib.optionalAttrs (args ? path) {
path = if lib.stringLength args.path == 0 then overlayAttrname else "${overlayAttrname}.${args.path}";
});
}

13
update-list.nix Normal file
View file

@ -0,0 +1,13 @@
self:
# MARK: inputs
( let
inputsWithPackages = import self.inputsPath {
pkgs = self.packagesForSystem builtins.currentSystem;
};
in {
"inputs/nixpkgs" = inputsWithPackages.nixpkgs;
"inputs/nixpkgs-unstable" = inputsWithPackages.nixpkgs-unstable;
"inputs/cosmic-modules" = inputsWithPackages.cosmic-modules;
"inputs/nixos-vscode-server" = inputsWithPackages.nixos-vscode-server;
})