1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-24 22:11:15 +02:00

Format .nix files

... with nixfmt (rfc style)
This commit is contained in:
Robert Hensing 2025-01-24 13:37:47 +01:00
parent ba6425a7d0
commit 96e550efc5
266 changed files with 7460 additions and 5138 deletions

View file

@ -1,10 +1,9 @@
(import (import (
( let
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball { fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash; sha256 = lock.nodes.flake-compat.locked.narHash;
} }
) ) { src = ./.; }).defaultNix
{ src = ./.; }
).defaultNix

View file

@ -5,7 +5,15 @@ in
builtinsInfo: builtinsInfo:
let let
showBuiltin = name: { doc, type ? null, args ? [ ], experimental-feature ? null, impure-only ? false }: showBuiltin =
name:
{
doc,
type ? null,
args ? [ ],
experimental-feature ? null,
impure-only ? false,
}:
let let
type' = optionalString (type != null) " (${type})"; type' = optionalString (type != null) " (${type})";

View file

@ -32,7 +32,13 @@ let
commandInfo = fromJSON commandDump; commandInfo = fromJSON commandDump;
showCommand = { command, details, filename, toplevel }: showCommand =
{
command,
details,
filename,
toplevel,
}:
let let
result = '' result = ''
@ -56,26 +62,27 @@ let
${maybeOptions} ${maybeOptions}
''; '';
showSynopsis = command: args: showSynopsis =
command: args:
let let
showArgument = arg: "*${arg.label}*" + optionalString (!arg ? arity) "..."; showArgument = arg: "*${arg.label}*" + optionalString (!arg ? arity) "...";
arguments = concatStringsSep " " (map showArgument args); arguments = concatStringsSep " " (map showArgument args);
in '' in
''
`${command}` [*option*...] ${arguments} `${command}` [*option*...] ${arguments}
''; '';
maybeSubcommands = optionalString (details ? commands && details.commands != {}) maybeSubcommands = optionalString (details ? commands && details.commands != { }) ''
''
where *subcommand* is one of the following: where *subcommand* is one of the following:
${subcommands} ${subcommands}
''; '';
subcommands = if length categories > 1 subcommands = if length categories > 1 then listCategories else listSubcommands details.commands;
then listCategories
else listSubcommands details.commands;
categories = sort (x: y: x.id < y.id) (unique (map (cmd: cmd.category) (attrValues details.commands))); categories = sort (x: y: x.id < y.id) (
unique (map (cmd: cmd.category) (attrValues details.commands))
);
listCategories = concatStrings (map showCategory categories); listCategories = concatStrings (map showCategory categories);
@ -99,38 +106,39 @@ let
${allStores} ${allStores}
''; '';
index = replaceStrings index =
replaceStrings
[ "@store-types@" "./local-store.md" "./local-daemon-store.md" ] [ "@store-types@" "./local-store.md" "./local-daemon-store.md" ]
[ storesOverview "#local-store" "#local-daemon-store" ] [ storesOverview "#local-store" "#local-daemon-store" ]
details.doc; details.doc;
storesOverview = storesOverview =
let let
showEntry = store: showEntry = store: "- [${store.name}](#${store.slug})";
"- [${store.name}](#${store.slug})";
in in
concatStringsSep "\n" (map showEntry storesList) + "\n"; concatStringsSep "\n" (map showEntry storesList) + "\n";
allStores = concatStringsSep "\n" (attrValues storePages); allStores = concatStringsSep "\n" (attrValues storePages);
storePages = listToAttrs storePages = listToAttrs (
(map (s: { name = s.filename; value = s.page; }) storesList); map (s: {
name = s.filename;
value = s.page;
}) storesList
);
storesList = showStoreDocs { storesList = showStoreDocs {
storeInfo = commandInfo.stores; storeInfo = commandInfo.stores;
inherit inlineHTML; inherit inlineHTML;
}; };
hasInfix = infix: content: hasInfix =
infix: content:
builtins.stringLength content != builtins.stringLength (replaceStrings [ infix ] [ "" ] content); builtins.stringLength content != builtins.stringLength (replaceStrings [ infix ] [ "" ] content);
in in
optionalString (details ? doc) ( optionalString (details ? doc) (
# An alternate implementation with builtins.match stack overflowed on some systems. # An alternate implementation with builtins.match stack overflowed on some systems.
if hasInfix "@store-types@" details.doc if hasInfix "@store-types@" details.doc then help-stores else details.doc
then help-stores
else details.doc
); );
maybeOptions = maybeOptions =
let let
allVisibleOptions = filterAttrs allVisibleOptions = filterAttrs (_: o: !o.hiddenCategory) (details.flags // toplevel.flags);
(_: o: ! o.hiddenCategory)
(details.flags // toplevel.flags);
in in
optionalString (allVisibleOptions != { }) '' optionalString (allVisibleOptions != { }) ''
# Options # Options
@ -142,55 +150,73 @@ let
> See [`man nix.conf`](@docroot@/command-ref/conf-file.md#command-line-flags) for overriding configuration settings with command line flags. > See [`man nix.conf`](@docroot@/command-ref/conf-file.md#command-line-flags) for overriding configuration settings with command line flags.
''; '';
showOptions = inlineHTML: allOptions: showOptions =
inlineHTML: allOptions:
let let
showCategory = cat: opts: '' showCategory = cat: opts: ''
${optionalString (cat != "") "## ${cat}"} ${optionalString (cat != "") "## ${cat}"}
${concatStringsSep "\n" (attrValues (mapAttrs showOption opts))} ${concatStringsSep "\n" (attrValues (mapAttrs showOption opts))}
''; '';
showOption = name: option: showOption =
name: option:
let let
result = trim '' result = trim ''
- ${item} - ${item}
${option.description} ${option.description}
''; '';
item = if inlineHTML item =
then ''<span id="opt-${name}">[`--${name}`](#opt-${name})</span> ${shortName} ${labels}'' if inlineHTML then
else "`--${name}` ${shortName} ${labels}"; ''<span id="opt-${name}">[`--${name}`](#opt-${name})</span> ${shortName} ${labels}''
shortName = optionalString else
(option ? shortName) "`--${name}` ${shortName} ${labels}";
("/ `-${option.shortName}`"); shortName = optionalString (option ? shortName) ("/ `-${option.shortName}`");
labels = optionalString labels = optionalString (option ? labels) (concatStringsSep " " (map (s: "*${s}*") option.labels));
(option ? labels) in
(concatStringsSep " " (map (s: "*${s}*") option.labels)); result;
in result; categories =
categories = mapAttrs mapAttrs
# Convert each group from a list of key-value pairs back to an attrset # Convert each group from a list of key-value pairs back to an attrset
(_: listToAttrs) (_: listToAttrs)
(groupBy (groupBy (cmd: cmd.value.category) (attrsToList allOptions));
(cmd: cmd.value.category) in
(attrsToList allOptions)); concatStrings (attrValues (mapAttrs showCategory categories));
in concatStrings (attrValues (mapAttrs showCategory categories)); in
in squash result; squash result;
appendName = filename: name: (if filename == "nix" then "nix3" else filename) + "-" + name; appendName = filename: name: (if filename == "nix" then "nix3" else filename) + "-" + name;
processCommand = { command, details, filename, toplevel }: processCommand =
{
command,
details,
filename,
toplevel,
}:
let let
cmd = { cmd = {
inherit command; inherit command;
name = filename + ".md"; name = filename + ".md";
value = showCommand { inherit command details filename toplevel; }; value = showCommand {
inherit
command
details
filename
toplevel
;
}; };
subcommand = subCmd: processCommand { };
subcommand =
subCmd:
processCommand {
command = command + " " + subCmd; command = command + " " + subCmd;
details = details.commands.${subCmd}; details = details.commands.${subCmd};
filename = appendName filename subCmd; filename = appendName filename subCmd;
inherit toplevel; inherit toplevel;
}; };
in [ cmd ] ++ concatMap subcommand (attrNames details.commands or {}); in
[ cmd ] ++ concatMap subcommand (attrNames details.commands or { });
manpages = processCommand { manpages = processCommand {
command = "nix"; command = "nix";
@ -199,9 +225,11 @@ let
toplevel = commandInfo.args; toplevel = commandInfo.args;
}; };
tableOfContents = let tableOfContents =
showEntry = page: let
" - [${page.command}](command-ref/new-cli/${page.name})"; showEntry = page: " - [${page.command}](command-ref/new-cli/${page.name})";
in concatStringsSep "\n" (map showEntry manpages) + "\n"; in
concatStringsSep "\n" (map showEntry manpages) + "\n";
in (listToAttrs manpages) // { "SUMMARY.md" = tableOfContents; } in
(listToAttrs manpages) // { "SUMMARY.md" = tableOfContents; }

View file

@ -1,23 +1,49 @@
let let
inherit (builtins) attrValues concatStringsSep isAttrs isBool mapAttrs; inherit (builtins)
inherit (import <nix/utils.nix>) concatStrings indent optionalString squash; attrValues
concatStringsSep
isAttrs
isBool
mapAttrs
;
inherit (import <nix/utils.nix>)
concatStrings
indent
optionalString
squash
;
in in
# `inlineHTML` is a hack to accommodate inconsistent output from `lowdown` # `inlineHTML` is a hack to accommodate inconsistent output from `lowdown`
{ prefix, inlineHTML ? true }: settingsInfo: {
prefix,
inlineHTML ? true,
}:
settingsInfo:
let let
showSetting = prefix: setting: { description, documentDefault, defaultValue, aliases, value, experimentalFeature }: showSetting =
prefix: setting:
{
description,
documentDefault,
defaultValue,
aliases,
value,
experimentalFeature,
}:
let let
result = squash '' result = squash ''
- ${item} - ${item}
${indent " " body} ${indent " " body}
''; '';
item = if inlineHTML item =
then ''<span id="${prefix}-${setting}">[`${setting}`](#${prefix}-${setting})</span>'' if inlineHTML then
else "`${setting}`"; ''<span id="${prefix}-${setting}">[`${setting}`](#${prefix}-${setting})</span>''
else
"`${setting}`";
# separate body to cleanly handle indentation # separate body to cleanly handle indentation
body = '' body = ''
${experimentalFeatureNote} ${experimentalFeatureNote}
@ -46,22 +72,28 @@ let
> ``` > ```
''; '';
showDefault = documentDefault: defaultValue: showDefault =
documentDefault: defaultValue:
if documentDefault then if documentDefault then
# a StringMap value type is specified as a string, but # a StringMap value type is specified as a string, but
# this shows the value type. The empty stringmap is `null` in # this shows the value type. The empty stringmap is `null` in
# JSON, but that converts to `{ }` here. # JSON, but that converts to `{ }` here.
if defaultValue == "" || defaultValue == [] || isAttrs defaultValue if defaultValue == "" || defaultValue == [ ] || isAttrs defaultValue then
then "*empty*" "*empty*"
else if isBool defaultValue then else if isBool defaultValue then
if defaultValue then "`true`" else "`false`" if defaultValue then "`true`" else "`false`"
else "`${toString defaultValue}`" else
else "*machine-specific*"; "`${toString defaultValue}`"
else
"*machine-specific*";
showAliases = aliases: showAliases =
aliases:
optionalString (aliases != [ ]) optionalString (aliases != [ ])
"**Deprecated alias:** ${(concatStringsSep ", " (map (s: "`${s}`") aliases))}"; "**Deprecated alias:** ${(concatStringsSep ", " (map (s: "`${s}`") aliases))}";
in result; in
result;
in concatStrings (attrValues (mapAttrs (showSetting prefix) settingsInfo)) in
concatStrings (attrValues (mapAttrs (showSetting prefix) settingsInfo))

View file

@ -1,6 +1,20 @@
let let
inherit (builtins) attrNames listToAttrs concatStringsSep readFile replaceStrings; inherit (builtins)
inherit (import <nix/utils.nix>) optionalString filterAttrs trim squash toLower unique indent; attrNames
listToAttrs
concatStringsSep
readFile
replaceStrings
;
inherit (import <nix/utils.nix>)
optionalString
filterAttrs
trim
squash
toLower
unique
indent
;
showSettings = import <nix/generate-settings.nix>; showSettings = import <nix/generate-settings.nix>;
in in
@ -14,7 +28,13 @@ in
let let
showStore = { name, slug }: { settings, doc, experimentalFeature }: showStore =
{ name, slug }:
{
settings,
doc,
experimentalFeature,
}:
let let
result = squash '' result = squash ''
# ${name} # ${name}
@ -25,7 +45,10 @@ let
## Settings ## Settings
${showSettings { prefix = "store-${slug}"; inherit inlineHTML; } settings} ${showSettings {
prefix = "store-${slug}";
inherit inlineHTML;
} settings}
''; '';
experimentalFeatureNote = optionalString (experimentalFeature != null) '' experimentalFeatureNote = optionalString (experimentalFeature != null) ''
@ -43,15 +66,15 @@ let
> extra-experimental-features = ${experimentalFeature} > extra-experimental-features = ${experimentalFeature}
> ``` > ```
''; '';
in result; in
result;
storesList = map storesList = map (name: rec {
(name: rec {
inherit name; inherit name;
slug = replaceStrings [ " " ] [ "-" ] (toLower name); slug = replaceStrings [ " " ] [ "-" ] (toLower name);
filename = "${slug}.md"; filename = "${slug}.md";
page = showStore { inherit name slug; } storeInfo.${name}; page = showStore { inherit name slug; } storeInfo.${name};
}) }) (attrNames storeInfo);
(attrNames storeInfo);
in storesList in
storesList

View file

@ -1,5 +1,11 @@
let let
inherit (builtins) attrNames listToAttrs concatStringsSep readFile replaceStrings; inherit (builtins)
attrNames
listToAttrs
concatStringsSep
readFile
replaceStrings
;
showSettings = import <nix/generate-settings.nix>; showSettings = import <nix/generate-settings.nix>;
showStoreDocs = import <nix/generate-store-info.nix>; showStoreDocs = import <nix/generate-store-info.nix>;
in in
@ -14,26 +20,28 @@ let
index = index =
let let
showEntry = store: showEntry = store: "- [${store.name}](./${store.filename})";
"- [${store.name}](./${store.filename})";
in in
concatStringsSep "\n" (map showEntry storesList); concatStringsSep "\n" (map showEntry storesList);
"index.md" = replaceStrings "index.md" =
[ "@store-types@" ] [ index ] replaceStrings [ "@store-types@" ] [ index ]
(readFile ./source/store/types/index.md.in); (readFile ./source/store/types/index.md.in);
tableOfContents = tableOfContents =
let let
showEntry = store: showEntry = store: " - [${store.name}](store/types/${store.filename})";
" - [${store.name}](store/types/${store.filename})";
in in
concatStringsSep "\n" (map showEntry storesList) + "\n"; concatStringsSep "\n" (map showEntry storesList) + "\n";
"SUMMARY.md" = tableOfContents; "SUMMARY.md" = tableOfContents;
storePages = listToAttrs storePages = listToAttrs (
(map (s: { name = s.filename; value = s.page; }) storesList); map (s: {
name = s.filename;
value = s.page;
}) storesList
);
in in
storePages // { inherit "index.md" "SUMMARY.md"; } storePages // { inherit "index.md" "SUMMARY.md"; }

View file

@ -2,8 +2,8 @@ with builtins;
with import <nix/utils.nix>; with import <nix/utils.nix>;
let let
showExperimentalFeature = name: doc: showExperimentalFeature = name: doc: ''
''
- [`${name}`](@docroot@/development/experimental-features.md#xp-feature-${name}) - [`${name}`](@docroot@/development/experimental-features.md#xp-feature-${name})
''; '';
in xps: indent " " (concatStrings (attrValues (mapAttrs showExperimentalFeature xps))) in
xps: indent " " (concatStrings (attrValues (mapAttrs showExperimentalFeature xps)))

View file

@ -2,7 +2,8 @@ with builtins;
with import <nix/utils.nix>; with import <nix/utils.nix>;
let let
showExperimentalFeature = name: doc: showExperimentalFeature =
name: doc:
squash '' squash ''
## [`${name}`]{#xp-feature-${name}} ## [`${name}`]{#xp-feature-${name}}

View file

@ -1,19 +1,20 @@
{ lib {
, mkMesonDerivation lib,
mkMesonDerivation,
, meson meson,
, ninja ninja,
, lowdown-unsandboxed lowdown-unsandboxed,
, mdbook mdbook,
, mdbook-linkcheck mdbook-linkcheck,
, jq jq,
, python3 python3,
, rsync rsync,
, nix-cli nix-cli,
# Configuration Options # Configuration Options
, version version,
}: }:
let let
@ -25,7 +26,8 @@ mkMesonDerivation (finalAttrs: {
inherit version; inherit version;
workDir = ./.; workDir = ./.;
fileset = fileset.difference fileset =
fileset.difference
(fileset.unions [ (fileset.unions [
../../.version ../../.version
# Too many different types of files to filter for now # Too many different types of files to filter for now
@ -36,7 +38,10 @@ mkMesonDerivation (finalAttrs: {
../../doc/manual/package.nix; ../../doc/manual/package.nix;
# TODO the man pages should probably be separate # TODO the man pages should probably be separate
outputs = [ "out" "man" ]; outputs = [
"out"
"man"
];
# Hack for sake of the dev shell # Hack for sake of the dev shell
passthru.externalNativeBuildInputs = [ passthru.externalNativeBuildInputs = [
@ -54,8 +59,7 @@ mkMesonDerivation (finalAttrs: {
nix-cli nix-cli
]; ];
preConfigure = preConfigure = ''
''
chmod u+w ./.version chmod u+w ./.version
echo ${finalAttrs.version} > ./.version echo ${finalAttrs.version} > ./.version
''; '';

View file

@ -11,10 +11,15 @@ rec {
concatStrings = concatStringsSep ""; concatStrings = concatStringsSep "";
attrsToList = a: attrsToList =
map (name: { inherit name; value = a.${name}; }) (builtins.attrNames a); a:
map (name: {
inherit name;
value = a.${name};
}) (builtins.attrNames a);
replaceStringsRec = from: to: string: replaceStringsRec =
from: to: string:
# recursively replace occurrences of `from` with `to` within `string` # recursively replace occurrences of `from` with `to` within `string`
# example: # example:
# replaceStringRec "--" "-" "hello-----world" # replaceStringRec "--" "-" "hello-----world"
@ -28,10 +33,12 @@ rec {
squash = replaceStringsRec "\n\n\n" "\n\n"; squash = replaceStringsRec "\n\n\n" "\n\n";
trim = string: trim =
string:
# trim trailing spaces and squash non-leading spaces # trim trailing spaces and squash non-leading spaces
let let
trimLine = line: trimLine =
line:
let let
# separate leading spaces from the rest # separate leading spaces from the rest
parts = split "(^ *)" line; parts = split "(^ *)" line;
@ -39,19 +46,30 @@ rec {
rest = elemAt parts 2; rest = elemAt parts 2;
# drop trailing spaces # drop trailing spaces
body = head (split " *$" rest); body = head (split " *$" rest);
in spaces + replaceStringsRec " " " " body; in
in concatStringsSep "\n" (map trimLine (splitLines string)); spaces + replaceStringsRec " " " " body;
in
concatStringsSep "\n" (map trimLine (splitLines string));
# FIXME: O(n^2) # FIXME: O(n^2)
unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) [ ]; unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) [ ];
nameValuePair = name: value: { inherit name value; }; nameValuePair = name: value: { inherit name value; };
filterAttrs = pred: set: filterAttrs =
listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [(nameValuePair name v)] else []) (attrNames set)); pred: set:
listToAttrs (
concatMap (
name:
let
v = set.${name};
in
if pred name v then [ (nameValuePair name v) ] else [ ]
) (attrNames set)
);
optionalString = cond: string: if cond then string else ""; optionalString = cond: string: if cond then string else "";
indent = prefix: s: indent =
concatStringsSep "\n" (map (x: if x == "" then x else "${prefix}${x}") (splitLines s)); prefix: s: concatStringsSep "\n" (map (x: if x == "" then x else "${prefix}${x}") (splitLines s));
} }

View file

@ -1,21 +1,24 @@
{ pkgs ? import <nixpkgs> { } {
, lib ? pkgs.lib pkgs ? import <nixpkgs> { },
, name ? "nix" lib ? pkgs.lib,
, tag ? "latest" name ? "nix",
, bundleNixpkgs ? true tag ? "latest",
, channelName ? "nixpkgs" bundleNixpkgs ? true,
, channelURL ? "https://nixos.org/channels/nixpkgs-unstable" channelName ? "nixpkgs",
, extraPkgs ? [] channelURL ? "https://nixos.org/channels/nixpkgs-unstable",
, maxLayers ? 100 extraPkgs ? [ ],
, nixConf ? {} maxLayers ? 100,
, flake-registry ? null nixConf ? { },
, uid ? 0 flake-registry ? null,
, gid ? 0 uid ? 0,
, uname ? "root" gid ? 0,
, gname ? "root" uname ? "root",
gname ? "root",
}: }:
let let
defaultPkgs = with pkgs; [ defaultPkgs =
with pkgs;
[
nix nix
bashInteractive bashInteractive
coreutils-full coreutils-full
@ -32,9 +35,11 @@ let
iana-etc iana-etc
git git
openssh openssh
] ++ extraPkgs; ]
++ extraPkgs;
users = { users =
{
root = { root = {
uid = 0; uid = 0;
@ -54,7 +59,8 @@ let
description = "Unprivileged account (don't use!)"; description = "Unprivileged account (don't use!)";
}; };
} // lib.optionalAttrs (uid != 0) { }
// lib.optionalAttrs (uid != 0) {
"${uname}" = { "${uname}" = {
uid = uid; uid = uid;
shell = "${pkgs.bashInteractive}/bin/bash"; shell = "${pkgs.bashInteractive}/bin/bash";
@ -63,10 +69,9 @@ let
groups = [ "${gname}" ]; groups = [ "${gname}" ];
description = "Nix user"; description = "Nix user";
}; };
} // lib.listToAttrs ( }
map // lib.listToAttrs (
( map (n: {
n: {
name = "nixbld${toString n}"; name = "nixbld${toString n}";
value = { value = {
uid = 30000 + n; uid = 30000 + n;
@ -74,39 +79,35 @@ let
groups = [ "nixbld" ]; groups = [ "nixbld" ];
description = "Nix build user ${toString n}"; description = "Nix build user ${toString n}";
}; };
} }) (lib.lists.range 1 32)
)
(lib.lists.range 1 32)
); );
groups = { groups =
{
root.gid = 0; root.gid = 0;
nixbld.gid = 30000; nixbld.gid = 30000;
nobody.gid = 65534; nobody.gid = 65534;
} // lib.optionalAttrs (gid != 0) { }
// lib.optionalAttrs (gid != 0) {
"${gname}".gid = gid; "${gname}".gid = gid;
}; };
userToPasswd = ( userToPasswd = (
k: k:
{ uid {
, gid ? 65534 uid,
, home ? "/var/empty" gid ? 65534,
, description ? "" home ? "/var/empty",
, shell ? "/bin/false" description ? "",
, groups ? [ ] shell ? "/bin/false",
}: "${k}:x:${toString uid}:${toString gid}:${description}:${home}:${shell}" groups ? [ ],
); }:
passwdContents = ( "${k}:x:${toString uid}:${toString gid}:${description}:${home}:${shell}"
lib.concatStringsSep "\n"
(lib.attrValues (lib.mapAttrs userToPasswd users))
); );
passwdContents = (lib.concatStringsSep "\n" (lib.attrValues (lib.mapAttrs userToPasswd users)));
userToShadow = k: { ... }: "${k}:!:1::::::"; userToShadow = k: { ... }: "${k}:!:1::::::";
shadowContents = ( shadowContents = (lib.concatStringsSep "\n" (lib.attrValues (lib.mapAttrs userToShadow users)));
lib.concatStringsSep "\n"
(lib.attrValues (lib.mapAttrs userToShadow users))
);
# Map groups to members # Map groups to members
# { # {
@ -116,42 +117,35 @@ let
let let
# Create a flat list of user/group mappings # Create a flat list of user/group mappings
mappings = ( mappings = (
builtins.foldl' builtins.foldl' (
(
acc: user: acc: user:
let let
groups = users.${user}.groups or [ ]; groups = users.${user}.groups or [ ];
in in
acc ++ map acc
(group: { ++ map (group: {
inherit user group; inherit user group;
}) }) groups
groups ) [ ] (lib.attrNames users)
)
[ ]
(lib.attrNames users)
); );
in in
( (builtins.foldl' (
builtins.foldl' acc: v:
( acc
acc: v: acc // { // {
${v.group} = acc.${v.group} or [ ] ++ [ v.user ]; ${v.group} = acc.${v.group} or [ ] ++ [ v.user ];
} }
) ) { } mappings)
{ }
mappings)
); );
groupToGroup = k: { gid }: groupToGroup =
k:
{ gid }:
let let
members = groupMemberMap.${k} or [ ]; members = groupMemberMap.${k} or [ ];
in in
"${k}:x:${toString gid}:${lib.concatStringsSep "," members}"; "${k}:x:${toString gid}:${lib.concatStringsSep "," members}";
groupContents = ( groupContents = (lib.concatStringsSep "\n" (lib.attrValues (lib.mapAttrs groupToGroup groups)));
lib.concatStringsSep "\n"
(lib.attrValues (lib.mapAttrs groupToGroup groups))
);
defaultNixConf = { defaultNixConf = {
sandbox = "false"; sandbox = "false";
@ -159,11 +153,17 @@ let
trusted-public-keys = [ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" ]; trusted-public-keys = [ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" ];
}; };
nixConfContents = (lib.concatStringsSep "\n" (lib.mapAttrsFlatten (n: v: nixConfContents =
(lib.concatStringsSep "\n" (
lib.mapAttrsFlatten (
n: v:
let let
vStr = if builtins.isList v then lib.concatStringsSep " " v else v; vStr = if builtins.isList v then lib.concatStringsSep " " v else v;
in in
"${n} = ${vStr}") (defaultNixConf // nixConf))) + "\n"; "${n} = ${vStr}"
) (defaultNixConf // nixConf)
))
+ "\n";
userHome = if uid == 0 then "/root" else "/home/${uname}"; userHome = if uid == 0 then "/root" else "/home/${uname}";
@ -184,13 +184,19 @@ let
manifest = pkgs.buildPackages.runCommand "manifest.nix" { } '' manifest = pkgs.buildPackages.runCommand "manifest.nix" { } ''
cat > $out <<EOF cat > $out <<EOF
[ [
${lib.concatStringsSep "\n" (builtins.map (drv: let ${lib.concatStringsSep "\n" (
builtins.map (
drv:
let
outputs = drv.outputsToInstall or [ "out" ]; outputs = drv.outputsToInstall or [ "out" ];
in '' in
''
{ {
${lib.concatStringsSep "\n" (builtins.map (output: '' ${lib.concatStringsSep "\n" (
builtins.map (output: ''
${output} = { outPath = "${lib.getOutput output drv}"; }; ${output} = { outPath = "${lib.getOutput output drv}"; };
'') outputs)} '') outputs
)}
outputs = [ ${lib.concatStringsSep " " (builtins.map (x: "\"${x}\"") outputs)} ]; outputs = [ ${lib.concatStringsSep " " (builtins.map (x: "\"${x}\"") outputs)} ];
name = "${drv.name}"; name = "${drv.name}";
outPath = "${drv}"; outPath = "${drv}";
@ -198,7 +204,9 @@ let
type = "derivation"; type = "derivation";
meta = { }; meta = { };
} }
'') defaultPkgs)} ''
) defaultPkgs
)}
] ]
EOF EOF
''; '';
@ -207,7 +215,8 @@ let
cp -a ${rootEnv}/* $out/ cp -a ${rootEnv}/* $out/
ln -s ${manifest} $out/manifest.nix ln -s ${manifest} $out/manifest.nix
''; '';
flake-registry-path = if (flake-registry == null) then flake-registry-path =
if (flake-registry == null) then
null null
else if (builtins.readFileType (toString flake-registry)) == "directory" then else if (builtins.readFileType (toString flake-registry)) == "directory" then
"${flake-registry}/flake-registry.json" "${flake-registry}/flake-registry.json"
@ -216,7 +225,12 @@ let
in in
pkgs.runCommand "base-system" pkgs.runCommand "base-system"
{ {
inherit passwdContents groupContents shadowContents nixConfContents; inherit
passwdContents
groupContents
shadowContents
nixConfContents
;
passAsFile = [ passAsFile = [
"passwdContents" "passwdContents"
"groupContents" "groupContents"
@ -225,7 +239,9 @@ let
]; ];
allowSubstitutes = false; allowSubstitutes = false;
preferLocalBuild = true; preferLocalBuild = true;
} ('' }
(
''
env env
set -x set -x
mkdir -p $out/etc mkdir -p $out/etc
@ -272,7 +288,8 @@ let
ln -s ${pkgs.coreutils}/bin/env $out/usr/bin/env ln -s ${pkgs.coreutils}/bin/env $out/usr/bin/env
ln -s ${pkgs.bashInteractive}/bin/bash $out/bin/sh ln -s ${pkgs.bashInteractive}/bin/bash $out/bin/sh
'' + (lib.optionalString (flake-registry-path != null) '' ''
+ (lib.optionalString (flake-registry-path != null) ''
nixCacheDir="${userHome}/.cache/nix" nixCacheDir="${userHome}/.cache/nix"
mkdir -p $out$nixCacheDir mkdir -p $out$nixCacheDir
globalFlakeRegistryPath="$nixCacheDir/flake-registry.json" globalFlakeRegistryPath="$nixCacheDir/flake-registry.json"
@ -280,12 +297,21 @@ let
mkdir -p $out/nix/var/nix/gcroots/auto mkdir -p $out/nix/var/nix/gcroots/auto
rootName=$(${pkgs.nix}/bin/nix --extra-experimental-features nix-command hash file --type sha1 --base32 <(echo -n $globalFlakeRegistryPath)) rootName=$(${pkgs.nix}/bin/nix --extra-experimental-features nix-command hash file --type sha1 --base32 <(echo -n $globalFlakeRegistryPath))
ln -s $globalFlakeRegistryPath $out/nix/var/nix/gcroots/auto/$rootName ln -s $globalFlakeRegistryPath $out/nix/var/nix/gcroots/auto/$rootName
'')); '')
);
in in
pkgs.dockerTools.buildLayeredImageWithNixDb { pkgs.dockerTools.buildLayeredImageWithNixDb {
inherit name tag maxLayers uid gid uname gname; inherit
name
tag
maxLayers
uid
gid
uname
gname
;
contents = [ baseSystem ]; contents = [ baseSystem ];
@ -305,15 +331,19 @@ pkgs.dockerTools.buildLayeredImageWithNixDb {
User = "${toString uid}:${toString gid}"; User = "${toString uid}:${toString gid}";
Env = [ Env = [
"USER=${uname}" "USER=${uname}"
"PATH=${lib.concatStringsSep ":" [ "PATH=${
lib.concatStringsSep ":" [
"${userHome}/.nix-profile/bin" "${userHome}/.nix-profile/bin"
"/nix/var/nix/profiles/default/bin" "/nix/var/nix/profiles/default/bin"
"/nix/var/nix/profiles/default/sbin" "/nix/var/nix/profiles/default/sbin"
]}" ]
"MANPATH=${lib.concatStringsSep ":" [ }"
"MANPATH=${
lib.concatStringsSep ":" [
"${userHome}/.nix-profile/share/man" "${userHome}/.nix-profile/share/man"
"/nix/var/nix/profiles/default/share/man" "/nix/var/nix/profiles/default/share/man"
]}" ]
}"
"SSL_CERT_FILE=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt" "SSL_CERT_FILE=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt"
"GIT_SSL_CAINFO=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt" "GIT_SSL_CAINFO=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt"
"NIX_SSL_CERT_FILE=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt" "NIX_SSL_CERT_FILE=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt"

231
flake.nix
View file

@ -5,7 +5,10 @@
inputs.nixpkgs-regression.url = "github:NixOS/nixpkgs/215d4d0fd80ca5163643b03a33fde804a29cc1e2"; inputs.nixpkgs-regression.url = "github:NixOS/nixpkgs/215d4d0fd80ca5163643b03a33fde804a29cc1e2";
inputs.nixpkgs-23-11.url = "github:NixOS/nixpkgs/a62e6edd6d5e1fa0329b8653c801147986f8d446"; inputs.nixpkgs-23-11.url = "github:NixOS/nixpkgs/a62e6edd6d5e1fa0329b8653c801147986f8d446";
inputs.flake-compat = { url = "github:edolstra/flake-compat"; flake = false; }; inputs.flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
# dev tooling # dev tooling
inputs.flake-parts.url = "github:hercules-ci/flake-parts"; inputs.flake-parts.url = "github:hercules-ci/flake-parts";
@ -19,8 +22,13 @@
inputs.git-hooks-nix.inputs.gitignore.follows = ""; inputs.git-hooks-nix.inputs.gitignore.follows = "";
inputs.nixfmt.url = "github:NixOS/nixfmt"; inputs.nixfmt.url = "github:NixOS/nixfmt";
outputs = inputs@{ self, nixpkgs, nixpkgs-regression, ... }: outputs =
inputs@{
self,
nixpkgs,
nixpkgs-regression,
...
}:
let let
inherit (nixpkgs) lib; inherit (nixpkgs) lib;
@ -28,9 +36,15 @@
officialRelease = false; officialRelease = false;
linux32BitSystems = [ "i686-linux" ]; linux32BitSystems = [ "i686-linux" ];
linux64BitSystems = [ "x86_64-linux" "aarch64-linux" ]; linux64BitSystems = [
"x86_64-linux"
"aarch64-linux"
];
linuxSystems = linux32BitSystems ++ linux64BitSystems; linuxSystems = linux32BitSystems ++ linux64BitSystems;
darwinSystems = [ "x86_64-darwin" "aarch64-darwin" ]; darwinSystems = [
"x86_64-darwin"
"aarch64-darwin"
];
systems = linuxSystems ++ darwinSystems; systems = linuxSystems ++ darwinSystems;
crossSystems = [ crossSystems = [
@ -69,44 +83,57 @@
forAllStdenvs = lib.genAttrs stdenvs; forAllStdenvs = lib.genAttrs stdenvs;
# We don't apply flake-parts to the whole flake so that non-development attributes # We don't apply flake-parts to the whole flake so that non-development attributes
# load without fetching any development inputs. # load without fetching any development inputs.
devFlake = inputs.flake-parts.lib.mkFlake { inherit inputs; } { devFlake = inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ ./maintainers/flake-module.nix ]; imports = [ ./maintainers/flake-module.nix ];
systems = lib.subtractLists crossSystems systems; systems = lib.subtractLists crossSystems systems;
perSystem = { system, ... }: { perSystem =
{ system, ... }:
{
_module.args.pkgs = nixpkgsFor.${system}.native; _module.args.pkgs = nixpkgsFor.${system}.native;
}; };
}; };
# Memoize nixpkgs for different platforms for efficiency. # Memoize nixpkgs for different platforms for efficiency.
nixpkgsFor = forAllSystems nixpkgsFor = forAllSystems (
(system: let system:
make-pkgs = crossSystem: let
forAllStdenvs (stdenv: import nixpkgs { make-pkgs =
crossSystem:
forAllStdenvs (
stdenv:
import nixpkgs {
localSystem = { localSystem = {
inherit system; inherit system;
}; };
crossSystem = if crossSystem == null then null else { crossSystem =
if crossSystem == null then
null
else
{
config = crossSystem; config = crossSystem;
} // lib.optionalAttrs (crossSystem == "x86_64-unknown-freebsd13") { }
// lib.optionalAttrs (crossSystem == "x86_64-unknown-freebsd13") {
useLLVM = true; useLLVM = true;
}; };
overlays = [ overlays = [
(overlayFor (pkgs: pkgs.${stdenv})) (overlayFor (pkgs: pkgs.${stdenv}))
]; ];
}); }
in rec { );
in
rec {
nativeForStdenv = make-pkgs null; nativeForStdenv = make-pkgs null;
crossForStdenv = forAllCrossSystems make-pkgs; crossForStdenv = forAllCrossSystems make-pkgs;
# Alias for convenience # Alias for convenience
native = nativeForStdenv.stdenv; native = nativeForStdenv.stdenv;
cross = forAllCrossSystems (crossSystem: cross = forAllCrossSystems (crossSystem: crossForStdenv.${crossSystem}.stdenv);
crossForStdenv.${crossSystem}.stdenv); }
}); );
overlayFor = getStdenv: final: prev: overlayFor =
getStdenv: final: prev:
let let
stdenv = getStdenv final; stdenv = getStdenv final;
in in
@ -153,12 +180,19 @@
# See https://github.com/NixOS/nixpkgs/pull/214409 # See https://github.com/NixOS/nixpkgs/pull/214409
# Remove when fixed in this flake's nixpkgs # Remove when fixed in this flake's nixpkgs
pre-commit = pre-commit =
if prev.stdenv.hostPlatform.system == "i686-linux" if prev.stdenv.hostPlatform.system == "i686-linux" then
then (prev.pre-commit.override (o: { dotnet-sdk = ""; })).overridePythonAttrs (o: { doCheck = false; }) (prev.pre-commit.override (o: {
else prev.pre-commit; dotnet-sdk = "";
})).overridePythonAttrs
(o: {
doCheck = false;
})
else
prev.pre-commit;
}; };
in { in
{
# A Nixpkgs overlay that overrides the 'nix' and # A Nixpkgs overlay that overrides the 'nix' and
# 'nix-perl-bindings' packages. # 'nix-perl-bindings' packages.
overlays.default = overlayFor (p: p.stdenv); overlays.default = overlayFor (p: p.stdenv);
@ -176,40 +210,53 @@
; ;
}; };
checks = forAllSystems (system: { checks = forAllSystems (
system:
{
installerScriptForGHA = self.hydraJobs.installerScriptForGHA.${system}; installerScriptForGHA = self.hydraJobs.installerScriptForGHA.${system};
installTests = self.hydraJobs.installTests.${system}; installTests = self.hydraJobs.installTests.${system};
nixpkgsLibTests = self.hydraJobs.tests.nixpkgsLibTests.${system}; nixpkgsLibTests = self.hydraJobs.tests.nixpkgsLibTests.${system};
rl-next = rl-next =
let pkgs = nixpkgsFor.${system}.native; let
in pkgs.buildPackages.runCommand "test-rl-next-release-notes" { } '' pkgs = nixpkgsFor.${system}.native;
in
pkgs.buildPackages.runCommand "test-rl-next-release-notes" { } ''
LANG=C.UTF-8 ${pkgs.changelog-d}/bin/changelog-d ${./doc/manual/rl-next} >$out LANG=C.UTF-8 ${pkgs.changelog-d}/bin/changelog-d ${./doc/manual/rl-next} >$out
''; '';
repl-completion = nixpkgsFor.${system}.native.callPackage ./tests/repl-completion.nix { }; repl-completion = nixpkgsFor.${system}.native.callPackage ./tests/repl-completion.nix { };
} // (lib.optionalAttrs (builtins.elem system linux64BitSystems)) { }
// (lib.optionalAttrs (builtins.elem system linux64BitSystems)) {
dockerImage = self.hydraJobs.dockerImage.${system}; dockerImage = self.hydraJobs.dockerImage.${system};
} // (lib.optionalAttrs (!(builtins.elem system linux32BitSystems))) { }
// (lib.optionalAttrs (!(builtins.elem system linux32BitSystems))) {
# Some perl dependencies are broken on i686-linux. # Some perl dependencies are broken on i686-linux.
# Since the support is only best-effort there, disable the perl # Since the support is only best-effort there, disable the perl
# bindings # bindings
perlBindings = self.hydraJobs.perlBindings.${system}; perlBindings = self.hydraJobs.perlBindings.${system};
} }
# Add "passthru" tests # Add "passthru" tests
// flatMapAttrs ({ //
flatMapAttrs
(
{
"" = nixpkgsFor.${system}.native; "" = nixpkgsFor.${system}.native;
} // lib.optionalAttrs (! nixpkgsFor.${system}.native.stdenv.hostPlatform.isDarwin) { }
// lib.optionalAttrs (!nixpkgsFor.${system}.native.stdenv.hostPlatform.isDarwin) {
# TODO: enable static builds for darwin, blocked on: # TODO: enable static builds for darwin, blocked on:
# https://github.com/NixOS/nixpkgs/issues/320448 # https://github.com/NixOS/nixpkgs/issues/320448
# TODO: disabled to speed up GHA CI. # TODO: disabled to speed up GHA CI.
#"static-" = nixpkgsFor.${system}.native.pkgsStatic; #"static-" = nixpkgsFor.${system}.native.pkgsStatic;
}) }
(nixpkgsPrefix: nixpkgs: )
flatMapAttrs nixpkgs.nixComponents (
(pkgName: pkg: nixpkgsPrefix: nixpkgs:
flatMapAttrs pkg.tests or {} flatMapAttrs nixpkgs.nixComponents (
(testName: test: { pkgName: pkg:
flatMapAttrs pkg.tests or { } (
testName: test: {
"${nixpkgsPrefix}${pkgName}-${testName}" = test; "${nixpkgsPrefix}${pkgName}-${testName}" = test;
}) }
)
) )
// lib.optionalAttrs (nixpkgs.stdenv.hostPlatform == nixpkgs.stdenv.buildPlatform) { // lib.optionalAttrs (nixpkgs.stdenv.hostPlatform == nixpkgs.stdenv.buildPlatform) {
"${nixpkgsPrefix}nix-functional-tests" = nixpkgs.nixComponents.nix-functional-tests; "${nixpkgsPrefix}nix-functional-tests" = nixpkgs.nixComponents.nix-functional-tests;
@ -218,11 +265,14 @@
// devFlake.checks.${system} or { } // devFlake.checks.${system} or { }
); );
packages = forAllSystems (system: packages = forAllSystems (
{ # Here we put attributes that map 1:1 into packages.<system>, ie system:
{
# Here we put attributes that map 1:1 into packages.<system>, ie
# for which we don't apply the full build matrix such as cross or static. # for which we don't apply the full build matrix such as cross or static.
inherit (nixpkgsFor.${system}.native) inherit (nixpkgsFor.${system}.native)
changelog-d; changelog-d
;
default = self.packages.${system}.nix; default = self.packages.${system}.nix;
installerScriptForGHA = self.hydraJobs.installerScriptForGHA.${system}; installerScriptForGHA = self.hydraJobs.installerScriptForGHA.${system};
binaryTarball = self.hydraJobs.binaryTarball.${system}; binaryTarball = self.hydraJobs.binaryTarball.${system};
@ -233,8 +283,10 @@
nix-external-api-docs = nixpkgsFor.${system}.native.nixComponents.nix-external-api-docs; nix-external-api-docs = nixpkgsFor.${system}.native.nixComponents.nix-external-api-docs;
} }
# We need to flatten recursive attribute sets of derivations to pass `flake check`. # We need to flatten recursive attribute sets of derivations to pass `flake check`.
// flatMapAttrs //
{ # Components we'll iterate over in the upcoming lambda flatMapAttrs
{
# Components we'll iterate over in the upcoming lambda
"nix-util" = { }; "nix-util" = { };
"nix-util-c" = { }; "nix-util-c" = { };
"nix-util-test-support" = { }; "nix-util-test-support" = { };
@ -265,33 +317,55 @@
"nix-everything" = { }; "nix-everything" = { };
"nix-functional-tests" = { supportsCross = false; }; "nix-functional-tests" = {
supportsCross = false;
};
"nix-perl-bindings" = { supportsCross = false; }; "nix-perl-bindings" = {
supportsCross = false;
};
} }
(pkgName: { supportsCross ? true }: { (
pkgName:
{
supportsCross ? true,
}:
{
# These attributes go right into `packages.<system>`. # These attributes go right into `packages.<system>`.
"${pkgName}" = nixpkgsFor.${system}.native.nixComponents.${pkgName}; "${pkgName}" = nixpkgsFor.${system}.native.nixComponents.${pkgName};
"${pkgName}-static" = nixpkgsFor.${system}.native.pkgsStatic.nixComponents.${pkgName}; "${pkgName}-static" = nixpkgsFor.${system}.native.pkgsStatic.nixComponents.${pkgName};
"${pkgName}-llvm" = nixpkgsFor.${system}.native.pkgsLLVM.nixComponents.${pkgName}; "${pkgName}-llvm" = nixpkgsFor.${system}.native.pkgsLLVM.nixComponents.${pkgName};
} }
// lib.optionalAttrs supportsCross (flatMapAttrs (lib.genAttrs crossSystems (_: { })) (crossSystem: {}: { // lib.optionalAttrs supportsCross (
flatMapAttrs (lib.genAttrs crossSystems (_: { })) (
crossSystem:
{ }:
{
# These attributes go right into `packages.<system>`. # These attributes go right into `packages.<system>`.
"${pkgName}-${crossSystem}" = nixpkgsFor.${system}.cross.${crossSystem}.nixComponents.${pkgName}; "${pkgName}-${crossSystem}" = nixpkgsFor.${system}.cross.${crossSystem}.nixComponents.${pkgName};
})) }
// flatMapAttrs (lib.genAttrs stdenvs (_: { })) (stdenvName: {}: { )
)
// flatMapAttrs (lib.genAttrs stdenvs (_: { })) (
stdenvName:
{ }:
{
# These attributes go right into `packages.<system>`. # These attributes go right into `packages.<system>`.
"${pkgName}-${stdenvName}" = nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.nixComponents.${pkgName}; "${pkgName}-${stdenvName}" =
}) nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.nixComponents.${pkgName};
}
)
) )
// lib.optionalAttrs (builtins.elem system linux64BitSystems) { // lib.optionalAttrs (builtins.elem system linux64BitSystems) {
dockerImage = dockerImage =
let let
pkgs = nixpkgsFor.${system}.native; pkgs = nixpkgsFor.${system}.native;
image = import ./docker.nix { inherit pkgs; tag = pkgs.nix.version; }; image = import ./docker.nix {
inherit pkgs;
tag = pkgs.nix.version;
};
in in
pkgs.runCommand pkgs.runCommand "docker-image-tarball-${pkgs.nix.version}"
"docker-image-tarball-${pkgs.nix.version}"
{ meta.description = "Docker image with Nix for ${system}"; } { meta.description = "Docker image with Nix for ${system}"; }
'' ''
mkdir -p $out/nix-support mkdir -p $out/nix-support
@ -299,28 +373,51 @@
ln -s ${image} $image ln -s ${image} $image
echo "file binary-dist $image" >> $out/nix-support/hydra-build-products echo "file binary-dist $image" >> $out/nix-support/hydra-build-products
''; '';
}); }
);
devShells = let devShells =
let
makeShell = import ./packaging/dev-shell.nix { inherit inputs lib devFlake; }; makeShell = import ./packaging/dev-shell.nix { inherit inputs lib devFlake; };
prefixAttrs = prefix: lib.concatMapAttrs (k: v: { "${prefix}-${k}" = v; }); prefixAttrs = prefix: lib.concatMapAttrs (k: v: { "${prefix}-${k}" = v; });
in in
forAllSystems (system: forAllSystems (
prefixAttrs "native" (forAllStdenvs (stdenvName: makeShell { system:
prefixAttrs "native" (
forAllStdenvs (
stdenvName:
makeShell {
pkgs = nixpkgsFor.${system}.nativeForStdenv.${stdenvName}; pkgs = nixpkgsFor.${system}.nativeForStdenv.${stdenvName};
})) // }
lib.optionalAttrs (!nixpkgsFor.${system}.native.stdenv.isDarwin) ( )
prefixAttrs "static" (forAllStdenvs (stdenvName: makeShell { )
// lib.optionalAttrs (!nixpkgsFor.${system}.native.stdenv.isDarwin) (
prefixAttrs "static" (
forAllStdenvs (
stdenvName:
makeShell {
pkgs = nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.pkgsStatic; pkgs = nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.pkgsStatic;
})) // }
prefixAttrs "llvm" (forAllStdenvs (stdenvName: makeShell { )
)
// prefixAttrs "llvm" (
forAllStdenvs (
stdenvName:
makeShell {
pkgs = nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.pkgsLLVM; pkgs = nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.pkgsLLVM;
})) // }
prefixAttrs "cross" (forAllCrossSystems (crossSystem: makeShell { )
)
// prefixAttrs "cross" (
forAllCrossSystems (
crossSystem:
makeShell {
pkgs = nixpkgsFor.${system}.cross.${crossSystem}; pkgs = nixpkgsFor.${system}.cross.${crossSystem};
})) }
) // )
{ )
)
// {
native = self.devShells.${system}.native-stdenv; native = self.devShells.${system}.native-stdenv;
default = self.devShells.${system}.native; default = self.devShells.${system}.native;
} }

View file

@ -1,11 +1,18 @@
{ lib, getSystem, inputs, ... }: {
lib,
getSystem,
inputs,
...
}:
{ {
imports = [ imports = [
inputs.git-hooks-nix.flakeModule inputs.git-hooks-nix.flakeModule
]; ];
perSystem = { config, pkgs, ... }: { perSystem =
{ config, pkgs, ... }:
{
# https://flake.parts/options/git-hooks-nix#options # https://flake.parts/options/git-hooks-nix#options
pre-commit.settings = { pre-commit.settings = {

View file

@ -1,14 +1,18 @@
{ runCommand {
, system runCommand,
, buildPackages system,
, cacert buildPackages,
, nix cacert,
nix,
}: }:
let let
installerClosureInfo = buildPackages.closureInfo { installerClosureInfo = buildPackages.closureInfo {
rootPaths = [ nix cacert ]; rootPaths = [
nix
cacert
];
}; };
inherit (nix) version; inherit (nix) version;

View file

@ -13,9 +13,11 @@ let
versionSuffix = lib.optionalString (!officialRelease) "pre"; versionSuffix = lib.optionalString (!officialRelease) "pre";
fineVersionSuffix = lib.optionalString fineVersionSuffix =
(!officialRelease) lib.optionalString (!officialRelease)
"pre${builtins.substring 0 8 (src.lastModifiedDate or src.lastModified or "19700101")}_${src.shortRev or "dirty"}"; "pre${
builtins.substring 0 8 (src.lastModifiedDate or src.lastModified or "19700101")
}_${src.shortRev or "dirty"}";
fineVersion = baseVersion + fineVersionSuffix; fineVersion = baseVersion + fineVersionSuffix;
in in
@ -54,7 +56,9 @@ in
nix-cli = callPackage ../src/nix/package.nix { version = fineVersion; }; nix-cli = callPackage ../src/nix/package.nix { version = fineVersion; };
nix-functional-tests = callPackage ../src/nix-functional-tests/package.nix { version = fineVersion; }; nix-functional-tests = callPackage ../src/nix-functional-tests/package.nix {
version = fineVersion;
};
nix-manual = callPackage ../doc/manual/package.nix { version = fineVersion; }; nix-manual = callPackage ../doc/manual/package.nix { version = fineVersion; };
nix-internal-api-docs = callPackage ../src/internal-api-docs/package.nix { version = fineVersion; }; nix-internal-api-docs = callPackage ../src/internal-api-docs/package.nix { version = fineVersion; };

View file

@ -19,9 +19,7 @@ let
root = ../.; root = ../.;
stdenv = if prevStdenv.isDarwin && prevStdenv.isx86_64 stdenv = if prevStdenv.isDarwin && prevStdenv.isx86_64 then darwinStdenv else prevStdenv;
then darwinStdenv
else prevStdenv;
# Fix the following error with the default x86_64-darwin SDK: # Fix the following error with the default x86_64-darwin SDK:
# #
@ -38,11 +36,14 @@ let
# Indirection for Nixpkgs to override when package.nix files are vendored # Indirection for Nixpkgs to override when package.nix files are vendored
filesetToSource = lib.fileset.toSource; filesetToSource = lib.fileset.toSource;
/** Given a set of layers, create a mkDerivation-like function */ /**
mkPackageBuilder = exts: userFn: Given a set of layers, create a mkDerivation-like function
stdenv.mkDerivation (lib.extends (lib.composeManyExtensions exts) userFn); */
mkPackageBuilder =
exts: userFn: stdenv.mkDerivation (lib.extends (lib.composeManyExtensions exts) userFn);
localSourceLayer = finalAttrs: prevAttrs: localSourceLayer =
finalAttrs: prevAttrs:
let let
workDirPath = workDirPath =
# Ideally we'd pick finalAttrs.workDir, but for now `mkDerivation` has # Ideally we'd pick finalAttrs.workDir, but for now `mkDerivation` has
@ -51,8 +52,13 @@ let
prevAttrs.workDir; prevAttrs.workDir;
workDirSubpath = lib.path.removePrefix root workDirPath; workDirSubpath = lib.path.removePrefix root workDirPath;
sources = assert prevAttrs.fileset._type == "fileset"; prevAttrs.fileset; sources =
src = lib.fileset.toSource { fileset = sources; inherit root; }; assert prevAttrs.fileset._type == "fileset";
prevAttrs.fileset;
src = lib.fileset.toSource {
fileset = sources;
inherit root;
};
in in
{ {
@ -64,8 +70,7 @@ let
workDir = null; workDir = null;
}; };
mesonLayer = finalAttrs: prevAttrs: mesonLayer = finalAttrs: prevAttrs: {
{
# NOTE: # NOTE:
# As of https://github.com/NixOS/nixpkgs/blob/8baf8241cea0c7b30e0b8ae73474cb3de83c1a30/pkgs/by-name/me/meson/setup-hook.sh#L26, # As of https://github.com/NixOS/nixpkgs/blob/8baf8241cea0c7b30e0b8ae73474cb3de83c1a30/pkgs/by-name/me/meson/setup-hook.sh#L26,
# `mesonBuildType` defaults to `plain` if not specified. We want our Nix-built binaries to be optimized by default. # `mesonBuildType` defaults to `plain` if not specified. We want our Nix-built binaries to be optimized by default.
@ -75,13 +80,18 @@ let
# Users who are debugging Nix builds are expected to set the environment variable `mesonBuildType`, per the # Users who are debugging Nix builds are expected to set the environment variable `mesonBuildType`, per the
# guidance in https://github.com/NixOS/nix/blob/8a3fc27f1b63a08ac983ee46435a56cf49ebaf4a/doc/manual/source/development/debugging.md?plain=1#L10. # guidance in https://github.com/NixOS/nix/blob/8a3fc27f1b63a08ac983ee46435a56cf49ebaf4a/doc/manual/source/development/debugging.md?plain=1#L10.
# For this reason, we don't want to refer to `finalAttrs.mesonBuildType` here, but rather use the environment variable. # For this reason, we don't want to refer to `finalAttrs.mesonBuildType` here, but rather use the environment variable.
preConfigure = prevAttrs.preConfigure or "" + lib.optionalString ( preConfigure =
prevAttrs.preConfigure or ""
+
lib.optionalString
(
!stdenv.hostPlatform.isWindows !stdenv.hostPlatform.isWindows
# build failure # build failure
&& !stdenv.hostPlatform.isStatic && !stdenv.hostPlatform.isStatic
# LTO breaks exception handling on x86-64-darwin. # LTO breaks exception handling on x86-64-darwin.
&& stdenv.system != "x86_64-darwin" && stdenv.system != "x86_64-darwin"
) '' )
''
case "$mesonBuildType" in case "$mesonBuildType" in
release|minsize) appendToVar mesonFlags "-Db_lto=true" ;; release|minsize) appendToVar mesonFlags "-Db_lto=true" ;;
*) appendToVar mesonFlags "-Db_lto=false" ;; *) appendToVar mesonFlags "-Db_lto=false" ;;
@ -96,35 +106,34 @@ let
]; ];
}; };
mesonBuildLayer = finalAttrs: prevAttrs: mesonBuildLayer = finalAttrs: prevAttrs: {
{
nativeBuildInputs = prevAttrs.nativeBuildInputs or [ ] ++ [ nativeBuildInputs = prevAttrs.nativeBuildInputs or [ ] ++ [
pkgs.buildPackages.pkg-config pkgs.buildPackages.pkg-config
]; ];
separateDebugInfo = !stdenv.hostPlatform.isStatic; separateDebugInfo = !stdenv.hostPlatform.isStatic;
hardeningDisable = lib.optional stdenv.hostPlatform.isStatic "pie"; hardeningDisable = lib.optional stdenv.hostPlatform.isStatic "pie";
env = prevAttrs.env or {} env =
// lib.optionalAttrs prevAttrs.env or { }
(stdenv.isLinux // lib.optionalAttrs (
stdenv.isLinux
&& !(stdenv.hostPlatform.isStatic && stdenv.system == "aarch64-linux") && !(stdenv.hostPlatform.isStatic && stdenv.system == "aarch64-linux")
&& !(stdenv.hostPlatform.useLLVM or false)) && !(stdenv.hostPlatform.useLLVM or false)
{ LDFLAGS = "-fuse-ld=gold"; }; ) { LDFLAGS = "-fuse-ld=gold"; };
}; };
mesonLibraryLayer = finalAttrs: prevAttrs: mesonLibraryLayer = finalAttrs: prevAttrs: {
{
outputs = prevAttrs.outputs or [ "out" ] ++ [ "dev" ]; outputs = prevAttrs.outputs or [ "out" ] ++ [ "dev" ];
}; };
# Work around weird `--as-needed` linker behavior with BSD, see # Work around weird `--as-needed` linker behavior with BSD, see
# https://github.com/mesonbuild/meson/issues/3593 # https://github.com/mesonbuild/meson/issues/3593
bsdNoLinkAsNeeded = finalAttrs: prevAttrs: bsdNoLinkAsNeeded =
finalAttrs: prevAttrs:
lib.optionalAttrs stdenv.hostPlatform.isBSD { lib.optionalAttrs stdenv.hostPlatform.isBSD {
mesonFlags = [ (lib.mesonBool "b_asneeded" false) ] ++ prevAttrs.mesonFlags or [ ]; mesonFlags = [ (lib.mesonBool "b_asneeded" false) ] ++ prevAttrs.mesonFlags or [ ];
}; };
miscGoodPractice = finalAttrs: prevAttrs: miscGoodPractice = finalAttrs: prevAttrs: {
{
strictDeps = prevAttrs.strictDeps or true; strictDeps = prevAttrs.strictDeps or true;
enableParallelBuilding = true; enableParallelBuilding = true;
}; };
@ -132,10 +141,15 @@ in
scope: { scope: {
inherit stdenv; inherit stdenv;
aws-sdk-cpp = (pkgs.aws-sdk-cpp.override { aws-sdk-cpp =
apis = [ "s3" "transfer" ]; (pkgs.aws-sdk-cpp.override {
apis = [
"s3"
"transfer"
];
customMemoryManagement = false; customMemoryManagement = false;
}).overrideAttrs { }).overrideAttrs
{
# only a stripped down version is built, which takes a lot less resources # only a stripped down version is built, which takes a lot less resources
# to build, so we don't need a "big-parallel" machine. # to build, so we don't need a "big-parallel" machine.
requiredSystemFeatures = [ ]; requiredSystemFeatures = [ ];
@ -146,35 +160,39 @@ scope: {
}; };
# TODO Hack until https://github.com/NixOS/nixpkgs/issues/45462 is fixed. # TODO Hack until https://github.com/NixOS/nixpkgs/issues/45462 is fixed.
boost = (pkgs.boost.override { boost =
(pkgs.boost.override {
extraB2Args = [ extraB2Args = [
"--with-container" "--with-container"
"--with-context" "--with-context"
"--with-coroutine" "--with-coroutine"
]; ];
}).overrideAttrs (old: { }).overrideAttrs
(old: {
# Need to remove `--with-*` to use `--with-libraries=...` # Need to remove `--with-*` to use `--with-libraries=...`
buildPhase = lib.replaceStrings [ "--without-python" ] [ "" ] old.buildPhase; buildPhase = lib.replaceStrings [ "--without-python" ] [ "" ] old.buildPhase;
installPhase = lib.replaceStrings [ "--without-python" ] [ "" ] old.installPhase; installPhase = lib.replaceStrings [ "--without-python" ] [ "" ] old.installPhase;
}); });
libgit2 = pkgs.libgit2.overrideAttrs (attrs: { libgit2 = pkgs.libgit2.overrideAttrs (attrs: {
cmakeFlags = attrs.cmakeFlags or [] cmakeFlags = attrs.cmakeFlags or [ ] ++ [ "-DUSE_SSH=exec" ];
++ [ "-DUSE_SSH=exec" ]; nativeBuildInputs =
nativeBuildInputs = attrs.nativeBuildInputs or [] attrs.nativeBuildInputs or [ ]
# gitMinimal does not build on Windows. See packbuilder patch. # gitMinimal does not build on Windows. See packbuilder patch.
++ lib.optionals (!stdenv.hostPlatform.isWindows) [ ++ lib.optionals (!stdenv.hostPlatform.isWindows) [
# Needed for `git apply`; see `prePatch` # Needed for `git apply`; see `prePatch`
pkgs.buildPackages.gitMinimal pkgs.buildPackages.gitMinimal
]; ];
# Only `git apply` can handle git binary patches # Only `git apply` can handle git binary patches
prePatch = attrs.prePatch or "" prePatch =
attrs.prePatch or ""
+ lib.optionalString (!stdenv.hostPlatform.isWindows) '' + lib.optionalString (!stdenv.hostPlatform.isWindows) ''
patch() { patch() {
git apply git apply
} }
''; '';
patches = attrs.patches or [] patches =
attrs.patches or [ ]
++ [ ++ [
./patches/libgit2-mempack-thin-packfile.patch ./patches/libgit2-mempack-thin-packfile.patch
] ]
@ -188,22 +206,19 @@ scope: {
inherit resolvePath filesetToSource; inherit resolvePath filesetToSource;
mkMesonDerivation = mkMesonDerivation = mkPackageBuilder [
mkPackageBuilder [
miscGoodPractice miscGoodPractice
localSourceLayer localSourceLayer
mesonLayer mesonLayer
]; ];
mkMesonExecutable = mkMesonExecutable = mkPackageBuilder [
mkPackageBuilder [
miscGoodPractice miscGoodPractice
bsdNoLinkAsNeeded bsdNoLinkAsNeeded
localSourceLayer localSourceLayer
mesonLayer mesonLayer
mesonBuildLayer mesonBuildLayer
]; ];
mkMesonLibrary = mkMesonLibrary = mkPackageBuilder [
mkPackageBuilder [
miscGoodPractice miscGoodPractice
bsdNoLinkAsNeeded bsdNoLinkAsNeeded
localSourceLayer localSourceLayer

View file

@ -1,14 +1,20 @@
{ lib, inputs, devFlake }: {
lib,
inputs,
devFlake,
}:
{ pkgs }: { pkgs }:
pkgs.nixComponents.nix-util.overrideAttrs (attrs: pkgs.nixComponents.nix-util.overrideAttrs (
attrs:
let let
stdenv = pkgs.nixDependencies.stdenv; stdenv = pkgs.nixDependencies.stdenv;
buildCanExecuteHost = stdenv.buildPlatform.canExecute stdenv.hostPlatform; buildCanExecuteHost = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
modular = devFlake.getSystem stdenv.buildPlatform.system; modular = devFlake.getSystem stdenv.buildPlatform.system;
transformFlag = prefix: flag: transformFlag =
prefix: flag:
assert builtins.isString flag; assert builtins.isString flag;
let let
rest = builtins.substring 2 (builtins.stringLength flag) flag; rest = builtins.substring 2 (builtins.stringLength flag) flag;
@ -16,7 +22,8 @@ let
"-D${prefix}:${rest}"; "-D${prefix}:${rest}";
havePerl = stdenv.buildPlatform == stdenv.hostPlatform && stdenv.hostPlatform.isUnix; havePerl = stdenv.buildPlatform == stdenv.hostPlatform && stdenv.hostPlatform.isUnix;
ignoreCrossFile = flags: builtins.filter (flag: !(lib.strings.hasInfix "cross-file" flag)) flags; ignoreCrossFile = flags: builtins.filter (flag: !(lib.strings.hasInfix "cross-file" flag)) flags;
in { in
{
pname = "shell-for-" + attrs.pname; pname = "shell-for-" + attrs.pname;
# Remove the version suffix to avoid unnecessary attempts to substitute in nix develop # Remove the version suffix to avoid unnecessary attempts to substitute in nix develop
@ -71,20 +78,23 @@ in {
BOOST_INCLUDEDIR = "${lib.getDev pkgs.nixDependencies.boost}/include"; BOOST_INCLUDEDIR = "${lib.getDev pkgs.nixDependencies.boost}/include";
BOOST_LIBRARYDIR = "${lib.getLib pkgs.nixDependencies.boost}/lib"; BOOST_LIBRARYDIR = "${lib.getLib pkgs.nixDependencies.boost}/lib";
# For `make format`, to work without installing pre-commit # For `make format`, to work without installing pre-commit
_NIX_PRE_COMMIT_HOOKS_CONFIG = _NIX_PRE_COMMIT_HOOKS_CONFIG = "${(pkgs.formats.yaml { }).generate "pre-commit-config.yaml"
"${(pkgs.formats.yaml { }).generate "pre-commit-config.yaml" modular.pre-commit.settings.rawConfig}"; modular.pre-commit.settings.rawConfig
}";
}; };
mesonFlags = mesonFlags =
map (transformFlag "libutil") (ignoreCrossFile pkgs.nixComponents.nix-util.mesonFlags) map (transformFlag "libutil") (ignoreCrossFile pkgs.nixComponents.nix-util.mesonFlags)
++ map (transformFlag "libstore") (ignoreCrossFile pkgs.nixComponents.nix-store.mesonFlags) ++ map (transformFlag "libstore") (ignoreCrossFile pkgs.nixComponents.nix-store.mesonFlags)
++ map (transformFlag "libfetchers") (ignoreCrossFile pkgs.nixComponents.nix-fetchers.mesonFlags) ++ map (transformFlag "libfetchers") (ignoreCrossFile pkgs.nixComponents.nix-fetchers.mesonFlags)
++ lib.optionals havePerl (map (transformFlag "perl") (ignoreCrossFile pkgs.nixComponents.nix-perl-bindings.mesonFlags)) ++ lib.optionals havePerl (
map (transformFlag "perl") (ignoreCrossFile pkgs.nixComponents.nix-perl-bindings.mesonFlags)
)
++ map (transformFlag "libexpr") (ignoreCrossFile pkgs.nixComponents.nix-expr.mesonFlags) ++ map (transformFlag "libexpr") (ignoreCrossFile pkgs.nixComponents.nix-expr.mesonFlags)
++ map (transformFlag "libcmd") (ignoreCrossFile pkgs.nixComponents.nix-cmd.mesonFlags) ++ map (transformFlag "libcmd") (ignoreCrossFile pkgs.nixComponents.nix-cmd.mesonFlags);
;
nativeBuildInputs = attrs.nativeBuildInputs or [] nativeBuildInputs =
attrs.nativeBuildInputs or [ ]
++ pkgs.nixComponents.nix-util.nativeBuildInputs ++ pkgs.nixComponents.nix-util.nativeBuildInputs
++ pkgs.nixComponents.nix-store.nativeBuildInputs ++ pkgs.nixComponents.nix-store.nativeBuildInputs
++ pkgs.nixComponents.nix-fetchers.nativeBuildInputs ++ pkgs.nixComponents.nix-fetchers.nativeBuildInputs
@ -94,28 +104,30 @@ in {
++ pkgs.nixComponents.nix-internal-api-docs.nativeBuildInputs ++ pkgs.nixComponents.nix-internal-api-docs.nativeBuildInputs
++ pkgs.nixComponents.nix-external-api-docs.nativeBuildInputs ++ pkgs.nixComponents.nix-external-api-docs.nativeBuildInputs
++ pkgs.nixComponents.nix-functional-tests.externalNativeBuildInputs ++ pkgs.nixComponents.nix-functional-tests.externalNativeBuildInputs
++ lib.optional ++ lib.optional (
(!buildCanExecuteHost !buildCanExecuteHost
# Hack around https://github.com/nixos/nixpkgs/commit/bf7ad8cfbfa102a90463433e2c5027573b462479 # Hack around https://github.com/nixos/nixpkgs/commit/bf7ad8cfbfa102a90463433e2c5027573b462479
&& !(stdenv.hostPlatform.isWindows && stdenv.buildPlatform.isDarwin) && !(stdenv.hostPlatform.isWindows && stdenv.buildPlatform.isDarwin)
&& stdenv.hostPlatform.emulatorAvailable pkgs.buildPackages && stdenv.hostPlatform.emulatorAvailable pkgs.buildPackages
&& lib.meta.availableOn stdenv.buildPlatform (stdenv.hostPlatform.emulator pkgs.buildPackages)) && lib.meta.availableOn stdenv.buildPlatform (stdenv.hostPlatform.emulator pkgs.buildPackages)
pkgs.buildPackages.mesonEmulatorHook ) pkgs.buildPackages.mesonEmulatorHook
++ [ ++ [
pkgs.buildPackages.cmake pkgs.buildPackages.cmake
pkgs.buildPackages.shellcheck pkgs.buildPackages.shellcheck
pkgs.buildPackages.changelog-d pkgs.buildPackages.changelog-d
modular.pre-commit.settings.package modular.pre-commit.settings.package
(pkgs.writeScriptBin "pre-commit-hooks-install" (pkgs.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript)
modular.pre-commit.settings.installationScript)
inputs.nixfmt.packages.${pkgs.hostPlatform.system}.default inputs.nixfmt.packages.${pkgs.hostPlatform.system}.default
] ]
# TODO: Remove the darwin check once # TODO: Remove the darwin check once
# https://github.com/NixOS/nixpkgs/pull/291814 is available # https://github.com/NixOS/nixpkgs/pull/291814 is available
++ lib.optional (stdenv.cc.isClang && !stdenv.buildPlatform.isDarwin) pkgs.buildPackages.bear ++ lib.optional (stdenv.cc.isClang && !stdenv.buildPlatform.isDarwin) pkgs.buildPackages.bear
++ lib.optional (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) (lib.hiPrio pkgs.buildPackages.clang-tools); ++ lib.optional (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) (
lib.hiPrio pkgs.buildPackages.clang-tools
);
buildInputs = attrs.buildInputs or [] buildInputs =
attrs.buildInputs or [ ]
++ pkgs.nixComponents.nix-util.buildInputs ++ pkgs.nixComponents.nix-util.buildInputs
++ pkgs.nixComponents.nix-store.buildInputs ++ pkgs.nixComponents.nix-store.buildInputs
++ pkgs.nixComponents.nix-store-tests.externalBuildInputs ++ pkgs.nixComponents.nix-store-tests.externalBuildInputs
@ -124,6 +136,6 @@ in {
++ pkgs.nixComponents.nix-expr.externalPropagatedBuildInputs ++ pkgs.nixComponents.nix-expr.externalPropagatedBuildInputs
++ pkgs.nixComponents.nix-cmd.buildInputs ++ pkgs.nixComponents.nix-cmd.buildInputs
++ lib.optionals havePerl pkgs.nixComponents.nix-perl-bindings.externalBuildInputs ++ lib.optionals havePerl pkgs.nixComponents.nix-perl-bindings.externalBuildInputs
++ lib.optional havePerl pkgs.perl ++ lib.optional havePerl pkgs.perl;
; }
}) )

View file

@ -42,7 +42,8 @@
}: }:
let let
libs = { libs =
{
inherit inherit
nix-util nix-util
nix-util-c nix-util-c
@ -57,7 +58,10 @@ let
nix-main-c nix-main-c
nix-cmd nix-cmd
; ;
} // lib.optionalAttrs (!stdenv.hostPlatform.isStatic && stdenv.buildPlatform.canExecute stdenv.hostPlatform) { }
// lib.optionalAttrs
(!stdenv.hostPlatform.isStatic && stdenv.buildPlatform.canExecute stdenv.hostPlatform)
{
# Currently fails in static build # Currently fails in static build
inherit inherit
nix-perl-bindings nix-perl-bindings
@ -77,8 +81,7 @@ let
''; '';
passthru = { passthru = {
tests = { tests = {
pkg-config = pkg-config = testers.hasPkgConfigModules {
testers.hasPkgConfigModules {
package = finalAttrs.finalPackage; package = finalAttrs.finalPackage;
}; };
}; };
@ -123,11 +126,14 @@ in
]; ];
meta.mainProgram = "nix"; meta.mainProgram = "nix";
}).overrideAttrs (finalAttrs: prevAttrs: { }).overrideAttrs
(
finalAttrs: prevAttrs: {
doCheck = true; doCheck = true;
doInstallCheck = true; doInstallCheck = true;
checkInputs = [ checkInputs =
[
# Make sure the unit tests have passed # Make sure the unit tests have passed
nix-util-tests.tests.run nix-util-tests.tests.run
nix-store-tests.tests.run nix-store-tests.tests.run
@ -141,7 +147,10 @@ in
# dev bundle is ok # dev bundle is ok
# (checkInputs must be empty paths??) # (checkInputs must be empty paths??)
(runCommand "check-pkg-config" { checked = dev.tests.pkg-config; } "mkdir $out") (runCommand "check-pkg-config" { checked = dev.tests.pkg-config; } "mkdir $out")
] ++ lib.optionals (!stdenv.hostPlatform.isStatic && stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ ]
++ lib.optionals
(!stdenv.hostPlatform.isStatic && stdenv.buildPlatform.canExecute stdenv.hostPlatform)
[
# Perl currently fails in static build # Perl currently fails in static build
# TODO: Split out tests into a separate derivation? # TODO: Split out tests into a separate derivation?
nix-perl-bindings nix-perl-bindings
@ -182,11 +191,19 @@ in
inherit dev; inherit dev;
inherit devdoc; inherit devdoc;
doc = nix-manual; doc = nix-manual;
outputs = [ "out" "dev" "devdoc" "doc" ]; outputs = [
all = lib.attrValues (lib.genAttrs finalAttrs.passthru.outputs (outName: finalAttrs.finalPackage.${outName})); "out"
"dev"
"devdoc"
"doc"
];
all = lib.attrValues (
lib.genAttrs finalAttrs.passthru.outputs (outName: finalAttrs.finalPackage.${outName})
);
}; };
meta = prevAttrs.meta // { meta = prevAttrs.meta // {
description = "The Nix package manager"; description = "The Nix package manager";
pkgConfigModules = dev.meta.pkgConfigModules; pkgConfigModules = dev.meta.pkgConfigModules;
}; };
}) }
)

View file

@ -1,21 +1,24 @@
{ inputs {
, forAllCrossSystems inputs,
, forAllSystems forAllCrossSystems,
, lib forAllSystems,
, linux64BitSystems lib,
, nixpkgsFor linux64BitSystems,
, self nixpkgsFor,
, officialRelease self,
officialRelease,
}: }:
let let
inherit (inputs) nixpkgs nixpkgs-regression; inherit (inputs) nixpkgs nixpkgs-regression;
installScriptFor = tarballs: installScriptFor =
tarballs:
nixpkgsFor.x86_64-linux.native.callPackage ./installer { nixpkgsFor.x86_64-linux.native.callPackage ./installer {
inherit tarballs; inherit tarballs;
}; };
testNixVersions = pkgs: daemon: testNixVersions =
pkgs: daemon:
pkgs.nixComponents.nix-functional-tests.override { pkgs.nixComponents.nix-functional-tests.override {
pname = "nix-daemon-compat-tests"; pname = "nix-daemon-compat-tests";
version = "${pkgs.nix.version}-with-daemon-${daemon.version}"; version = "${pkgs.nix.version}-with-daemon-${daemon.version}";
@ -53,44 +56,72 @@ let
in in
{ {
# Binary package for various platforms. # Binary package for various platforms.
build = forAllPackages (pkgName: build = forAllPackages (
forAllSystems (system: nixpkgsFor.${system}.native.nixComponents.${pkgName})); pkgName: forAllSystems (system: nixpkgsFor.${system}.native.nixComponents.${pkgName})
shellInputs = removeAttrs
(forAllSystems (system: self.devShells.${system}.default.inputDerivation))
[ "i686-linux" ];
buildStatic = forAllPackages (pkgName:
lib.genAttrs linux64BitSystems (system: nixpkgsFor.${system}.native.pkgsStatic.nixComponents.${pkgName}));
buildCross = forAllPackages (pkgName:
# Hack to avoid non-evaling package
(if pkgName == "nix-functional-tests" then lib.flip builtins.removeAttrs ["x86_64-w64-mingw32"] else lib.id)
(forAllCrossSystems (crossSystem:
lib.genAttrs [ "x86_64-linux" ] (system: nixpkgsFor.${system}.cross.${crossSystem}.nixComponents.${pkgName}))));
buildNoGc = let
components = forAllSystems (system:
nixpkgsFor.${system}.native.nixComponents.overrideScope (self: super: {
nix-expr = super.nix-expr.override { enableGC = false; };
})
); );
in forAllPackages (pkgName: forAllSystems (system: components.${system}.${pkgName}));
shellInputs = removeAttrs (forAllSystems (
system: self.devShells.${system}.default.inputDerivation
)) [ "i686-linux" ];
buildStatic = forAllPackages (
pkgName:
lib.genAttrs linux64BitSystems (
system: nixpkgsFor.${system}.native.pkgsStatic.nixComponents.${pkgName}
)
);
buildCross = forAllPackages (
pkgName:
# Hack to avoid non-evaling package
(
if pkgName == "nix-functional-tests" then
lib.flip builtins.removeAttrs [ "x86_64-w64-mingw32" ]
else
lib.id
)
(
forAllCrossSystems (
crossSystem:
lib.genAttrs [ "x86_64-linux" ] (
system: nixpkgsFor.${system}.cross.${crossSystem}.nixComponents.${pkgName}
)
)
)
);
buildNoGc =
let
components = forAllSystems (
system:
nixpkgsFor.${system}.native.nixComponents.overrideScope (
self: super: {
nix-expr = super.nix-expr.override { enableGC = false; };
}
)
);
in
forAllPackages (pkgName: forAllSystems (system: components.${system}.${pkgName}));
buildNoTests = forAllSystems (system: nixpkgsFor.${system}.native.nixComponents.nix-cli); buildNoTests = forAllSystems (system: nixpkgsFor.${system}.native.nixComponents.nix-cli);
# Toggles some settings for better coverage. Windows needs these # Toggles some settings for better coverage. Windows needs these
# library combinations, and Debian build Nix with GNU readline too. # library combinations, and Debian build Nix with GNU readline too.
buildReadlineNoMarkdown = let buildReadlineNoMarkdown =
components = forAllSystems (system: let
nixpkgsFor.${system}.native.nixComponents.overrideScope (self: super: { components = forAllSystems (
system:
nixpkgsFor.${system}.native.nixComponents.overrideScope (
self: super: {
nix-cmd = super.nix-cmd.override { nix-cmd = super.nix-cmd.override {
enableMarkdown = false; enableMarkdown = false;
readlineFlavor = "readline"; readlineFlavor = "readline";
}; };
}) }
)
); );
in forAllPackages (pkgName: forAllSystems (system: components.${system}.${pkgName})); in
forAllPackages (pkgName: forAllSystems (system: components.${system}.${pkgName}));
# Perl bindings for various platforms. # Perl bindings for various platforms.
perlBindings = forAllSystems (system: nixpkgsFor.${system}.native.nixComponents.nix-perl-bindings); perlBindings = forAllSystems (system: nixpkgsFor.${system}.native.nixComponents.nix-perl-bindings);
@ -98,12 +129,16 @@ in
# Binary tarball for various platforms, containing a Nix store # Binary tarball for various platforms, containing a Nix store
# with the closure of 'nix' package, and the second half of # with the closure of 'nix' package, and the second half of
# the installation script. # the installation script.
binaryTarball = forAllSystems (system: binaryTarball = forAllSystems (
nixpkgsFor.${system}.native.callPackage ./binary-tarball.nix {}); system: nixpkgsFor.${system}.native.callPackage ./binary-tarball.nix { }
);
binaryTarballCross = lib.genAttrs [ "x86_64-linux" ] (system: binaryTarballCross = lib.genAttrs [ "x86_64-linux" ] (
forAllCrossSystems (crossSystem: system:
nixpkgsFor.${system}.cross.${crossSystem}.callPackage ./binary-tarball.nix {})); forAllCrossSystems (
crossSystem: nixpkgsFor.${system}.cross.${crossSystem}.callPackage ./binary-tarball.nix { }
)
);
# The first half of the installation script. This is uploaded # The first half of the installation script. This is uploaded
# to https://nixos.org/nix/install. It downloads the binary # to https://nixos.org/nix/install. It downloads the binary
@ -122,9 +157,12 @@ in
self.hydraJobs.binaryTarballCross."x86_64-linux"."riscv64-unknown-linux-gnu" self.hydraJobs.binaryTarballCross."x86_64-linux"."riscv64-unknown-linux-gnu"
]; ];
installerScriptForGHA = forAllSystems (system: nixpkgsFor.${system}.native.callPackage ./installer { installerScriptForGHA = forAllSystems (
system:
nixpkgsFor.${system}.native.callPackage ./installer {
tarballs = [ self.hydraJobs.binaryTarball.${system} ]; tarballs = [ self.hydraJobs.binaryTarball.${system} ];
}); }
);
# docker image with Nix inside # docker image with Nix inside
dockerImage = lib.genAttrs linux64BitSystems (system: self.packages.${system}.dockerImage); dockerImage = lib.genAttrs linux64BitSystems (system: self.packages.${system}.dockerImage);
@ -145,10 +183,12 @@ in
external-api-docs = nixpkgsFor.x86_64-linux.native.nixComponents.nix-external-api-docs; external-api-docs = nixpkgsFor.x86_64-linux.native.nixComponents.nix-external-api-docs;
# System tests. # System tests.
tests = import ../tests/nixos { tests =
import ../tests/nixos {
inherit lib nixpkgs nixpkgsFor; inherit lib nixpkgs nixpkgsFor;
inherit (self.inputs) nixpkgs-23-11; inherit (self.inputs) nixpkgs-23-11;
} // { }
// {
# Make sure that nix-env still produces the exact same result # Make sure that nix-env still produces the exact same result
# on a particular version of Nixpkgs. # on a particular version of Nixpkgs.
@ -156,8 +196,7 @@ in
let let
inherit (nixpkgsFor.x86_64-linux.native) runCommand nix; inherit (nixpkgsFor.x86_64-linux.native) runCommand nix;
in in
runCommand "eval-nixos" { buildInputs = [ nix ]; } runCommand "eval-nixos" { buildInputs = [ nix ]; } ''
''
type -p nix-env type -p nix-env
# Note: we're filtering out nixos-install-tools because https://github.com/NixOS/nixpkgs/pull/153594#issuecomment-1020530593. # Note: we're filtering out nixos-install-tools because https://github.com/NixOS/nixpkgs/pull/153594#issuecomment-1020530593.
( (
@ -168,10 +207,9 @@ in
mkdir $out mkdir $out
''; '';
nixpkgsLibTests = nixpkgsLibTests = forAllSystems (
forAllSystems (system: system:
import (nixpkgs + "/lib/tests/test-with-nix.nix") import (nixpkgs + "/lib/tests/test-with-nix.nix") {
{
lib = nixpkgsFor.${system}.native.lib; lib = nixpkgsFor.${system}.native.lib;
nix = self.packages.${system}.nix-cli; nix = self.packages.${system}.nix-cli;
pkgs = nixpkgsFor.${system}.native; pkgs = nixpkgsFor.${system}.native;
@ -184,20 +222,21 @@ in
nixpkgs = nixpkgs-regression; nixpkgs = nixpkgs-regression;
}; };
installTests = forAllSystems (system: installTests = forAllSystems (
let pkgs = nixpkgsFor.${system}.native; in system:
pkgs.runCommand "install-tests" let
{ pkgs = nixpkgsFor.${system}.native;
in
pkgs.runCommand "install-tests" {
againstSelf = testNixVersions pkgs pkgs.nix; againstSelf = testNixVersions pkgs pkgs.nix;
againstCurrentLatest = againstCurrentLatest =
# FIXME: temporarily disable this on macOS because of #3605. # FIXME: temporarily disable this on macOS because of #3605.
if system == "x86_64-linux" if system == "x86_64-linux" then testNixVersions pkgs pkgs.nixVersions.latest else null;
then testNixVersions pkgs pkgs.nixVersions.latest
else null;
# Disabled because the latest stable version doesn't handle # Disabled because the latest stable version doesn't handle
# `NIX_DAEMON_SOCKET_PATH` which is required for the tests to work # `NIX_DAEMON_SOCKET_PATH` which is required for the tests to work
# againstLatestStable = testNixVersions pkgs pkgs.nixStable; # againstLatestStable = testNixVersions pkgs pkgs.nixStable;
} "touch $out"); } "touch $out"
);
installerTests = import ../tests/installer { installerTests = import ../tests/installer {
binaryTarballs = self.hydraJobs.binaryTarball; binaryTarballs = self.hydraJobs.binaryTarball;

View file

@ -1,12 +1,15 @@
{ lib {
, runCommand lib,
, nix runCommand,
, tarballs nix,
tarballs,
}: }:
runCommand "installer-script" { runCommand "installer-script"
{
buildInputs = [ nix ]; buildInputs = [ nix ];
} '' }
''
mkdir -p $out/nix-support mkdir -p $out/nix-support
# Converts /nix/store/50p3qk8k...-nix-2.4pre20201102_550e11f/bin/nix to 50p3qk8k.../bin/nix. # Converts /nix/store/50p3qk8k...-nix-2.4pre20201102_550e11f/bin/nix to 50p3qk8k.../bin/nix.
@ -21,15 +24,18 @@ runCommand "installer-script" {
} }
substitute ${./install.in} $out/install \ substitute ${./install.in} $out/install \
${lib.concatMapStrings ${
(tarball: let lib.concatMapStrings (
tarball:
let
inherit (tarball.stdenv.hostPlatform) system; inherit (tarball.stdenv.hostPlatform) system;
in '' \ in
''
\
--replace '@tarballHash_${system}@' $(nix --experimental-features nix-command hash-file --base16 --type sha256 ${tarball}/*.tar.xz) \ --replace '@tarballHash_${system}@' $(nix --experimental-features nix-command hash-file --base16 --type sha256 ${tarball}/*.tar.xz) \
--replace '@tarballPath_${system}@' $(tarballPath ${tarball}/*.tar.xz) \ --replace '@tarballPath_${system}@' $(tarballPath ${tarball}/*.tar.xz) \
'' ''
) ) tarballs
tarballs
} --replace '@nixVersion@' ${nix.version} } --replace '@nixVersion@' ${nix.version}
echo "file installer $out/install" >> $out/nix-support/hydra-build-products echo "file installer $out/install" >> $out/nix-support/hydra-build-products

View file

@ -1,11 +1,12 @@
{ lib {
, mkMesonDerivation lib,
mkMesonDerivation,
, doxygen doxygen,
# Configuration Options # Configuration Options
, version version,
}: }:
let let
@ -39,8 +40,7 @@ mkMesonDerivation (finalAttrs: {
doxygen doxygen
]; ];
preConfigure = preConfigure = ''
''
chmod u+w ./.version chmod u+w ./.version
echo ${finalAttrs.version} > ./.version echo ${finalAttrs.version} > ./.version
''; '';

View file

@ -1,11 +1,12 @@
{ lib {
, mkMesonDerivation lib,
mkMesonDerivation,
, doxygen doxygen,
# Configuration Options # Configuration Options
, version version,
}: }:
let let
@ -17,9 +18,11 @@ mkMesonDerivation (finalAttrs: {
inherit version; inherit version;
workDir = ./.; workDir = ./.;
fileset = let fileset =
let
cpp = fileset.fileFilter (file: file.hasExt "cc" || file.hasExt "hh"); cpp = fileset.fileFilter (file: file.hasExt "cc" || file.hasExt "hh");
in fileset.unions [ in
fileset.unions [
./.version ./.version
../../.version ../../.version
./meson.build ./meson.build
@ -33,8 +36,7 @@ mkMesonDerivation (finalAttrs: {
doxygen doxygen
]; ];
preConfigure = preConfigure = ''
''
chmod u+w ./.version chmod u+w ./.version
echo ${finalAttrs.version} > ./.version echo ${finalAttrs.version} > ./.version
''; '';

View file

@ -1,24 +1,25 @@
{ lib {
, stdenv lib,
, mkMesonLibrary stdenv,
mkMesonLibrary,
, nix-util nix-util,
, nix-store nix-store,
, nix-fetchers nix-fetchers,
, nix-expr nix-expr,
, nix-flake nix-flake,
, nix-main nix-main,
, editline editline,
, readline readline,
, lowdown lowdown,
, nlohmann_json nlohmann_json,
# Configuration Options # Configuration Options
, version version,
# Whether to enable Markdown rendering in the Nix binary. # Whether to enable Markdown rendering in the Nix binary.
, enableMarkdown ? !stdenv.hostPlatform.isWindows enableMarkdown ? !stdenv.hostPlatform.isWindows,
# Which interactive line editor library to use for Nix's repl. # Which interactive line editor library to use for Nix's repl.
# #
@ -26,7 +27,7 @@
# #
# - editline (default) # - editline (default)
# - readline # - readline
, readlineFlavor ? if stdenv.hostPlatform.isWindows then "readline" else "editline" readlineFlavor ? if stdenv.hostPlatform.isWindows then "readline" else "editline",
}: }:
let let

View file

@ -1,12 +1,13 @@
{ lib {
, mkMesonLibrary lib,
mkMesonLibrary,
, nix-store-c nix-store-c,
, nix-expr nix-expr,
# Configuration Options # Configuration Options
, version version,
}: }:
let let

View file

@ -1,15 +1,16 @@
{ lib {
, mkMesonLibrary lib,
mkMesonLibrary,
, nix-store-test-support nix-store-test-support,
, nix-expr nix-expr,
, nix-expr-c nix-expr-c,
, rapidcheck rapidcheck,
# Configuration Options # Configuration Options
, version version,
}: }:
let let

View file

@ -1,20 +1,21 @@
{ lib {
, buildPackages lib,
, stdenv buildPackages,
, mkMesonExecutable stdenv,
mkMesonExecutable,
, nix-expr nix-expr,
, nix-expr-c nix-expr-c,
, nix-expr-test-support nix-expr-test-support,
, rapidcheck rapidcheck,
, gtest gtest,
, runCommand runCommand,
# Configuration Options # Configuration Options
, version version,
, resolvePath resolvePath,
}: }:
let let
@ -58,16 +59,22 @@ mkMesonExecutable (finalAttrs: {
passthru = { passthru = {
tests = { tests = {
run = runCommand "${finalAttrs.pname}-run" { run =
runCommand "${finalAttrs.pname}-run"
{
meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages; meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages;
} (lib.optionalString stdenv.hostPlatform.isWindows '' }
(
lib.optionalString stdenv.hostPlatform.isWindows ''
export HOME="$PWD/home-dir" export HOME="$PWD/home-dir"
mkdir -p "$HOME" mkdir -p "$HOME"
'' + '' ''
+ ''
export _NIX_TEST_UNIT_DATA=${resolvePath ./data} export _NIX_TEST_UNIT_DATA=${resolvePath ./data}
${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage} ${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage}
touch $out touch $out
''); ''
);
}; };
}; };

View file

@ -20,36 +20,33 @@ let
# Resolve a input spec into a node name. An input spec is # Resolve a input spec into a node name. An input spec is
# either a node name, or a 'follows' path from the root # either a node name, or a 'follows' path from the root
# node. # node.
resolveInput = inputSpec: resolveInput =
if builtins.isList inputSpec inputSpec: if builtins.isList inputSpec then getInputByPath lockFile.root inputSpec else inputSpec;
then getInputByPath lockFile.root inputSpec
else inputSpec;
# Follow an input attrpath (e.g. ["dwarffs" "nixpkgs"]) from the # Follow an input attrpath (e.g. ["dwarffs" "nixpkgs"]) from the
# root node, returning the final node. # root node, returning the final node.
getInputByPath = nodeName: path: getInputByPath =
if path == [] nodeName: path:
then nodeName if path == [ ] then
nodeName
else else
getInputByPath getInputByPath
# Since this could be a 'follows' input, call resolveInput. # Since this could be a 'follows' input, call resolveInput.
(resolveInput lockFile.nodes.${nodeName}.inputs.${builtins.head path}) (resolveInput lockFile.nodes.${nodeName}.inputs.${builtins.head path})
(builtins.tail path); (builtins.tail path);
allNodes = allNodes = builtins.mapAttrs (
builtins.mapAttrs key: node:
(key: node:
let let
parentNode = allNodes.${getInputByPath lockFile.root node.parent}; parentNode = allNodes.${getInputByPath lockFile.root node.parent};
sourceInfo = sourceInfo =
if overrides ? ${key} if overrides ? ${key} then
then
overrides.${key}.sourceInfo overrides.${key}.sourceInfo
else if node.locked.type == "path" && builtins.substring 0 1 node.locked.path != "/" else if node.locked.type == "path" && builtins.substring 0 1 node.locked.path != "/" then
then parentNode.sourceInfo
parentNode.sourceInfo // { // {
outPath = parentNode.outPath + ("/" + node.locked.path); outPath = parentNode.outPath + ("/" + node.locked.path);
} }
else else
@ -63,9 +60,9 @@ let
flake = import (outPath + "/flake.nix"); flake = import (outPath + "/flake.nix");
inputs = builtins.mapAttrs inputs = builtins.mapAttrs (inputName: inputSpec: allNodes.${resolveInput inputSpec}) (
(inputName: inputSpec: allNodes.${resolveInput inputSpec}) node.inputs or { }
(node.inputs or {}); );
outputs = flake.outputs (inputs // { self = result; }); outputs = flake.outputs (inputs // { self = result; });
@ -81,7 +78,10 @@ let
# This shadows the sourceInfo.outPath # This shadows the sourceInfo.outPath
inherit outPath; inherit outPath;
inherit inputs; inherit outputs; inherit sourceInfo; _type = "flake"; inherit inputs;
inherit outputs;
inherit sourceInfo;
_type = "flake";
}; };
in in
@ -90,7 +90,7 @@ let
result result
else else
sourceInfo sourceInfo
) ) lockFile.nodes;
lockFile.nodes;
in allNodes.${lockFile.root} in
allNodes.${lockFile.root}

View file

@ -1,27 +1,55 @@
{ system ? "" # obsolete {
, url system ? "", # obsolete
, hash ? "" # an SRI hash url,
hash ? "", # an SRI hash
# Legacy hash specification # Legacy hash specification
, md5 ? "", sha1 ? "", sha256 ? "", sha512 ? "" md5 ? "",
, outputHash ? sha1 ? "",
if hash != "" then hash else if sha512 != "" then sha512 else if sha1 != "" then sha1 else if md5 != "" then md5 else sha256 sha256 ? "",
, outputHashAlgo ? sha512 ? "",
if hash != "" then "" else if sha512 != "" then "sha512" else if sha1 != "" then "sha1" else if md5 != "" then "md5" else "sha256" outputHash ?
if hash != "" then
hash
else if sha512 != "" then
sha512
else if sha1 != "" then
sha1
else if md5 != "" then
md5
else
sha256,
outputHashAlgo ?
if hash != "" then
""
else if sha512 != "" then
"sha512"
else if sha1 != "" then
"sha1"
else if md5 != "" then
"md5"
else
"sha256",
, executable ? false executable ? false,
, unpack ? false unpack ? false,
, name ? baseNameOf (toString url) name ? baseNameOf (toString url),
, impure ? false impure ? false,
}: }:
derivation ({ derivation (
{
builder = "builtin:fetchurl"; builder = "builtin:fetchurl";
# New-style output content requirements. # New-style output content requirements.
outputHashMode = if unpack || executable then "recursive" else "flat"; outputHashMode = if unpack || executable then "recursive" else "flat";
inherit name url executable unpack; inherit
name
url
executable
unpack
;
system = "builtin"; system = "builtin";
@ -30,11 +58,15 @@ derivation ({
# This attribute does nothing; it's here to avoid changing evaluation results. # This attribute does nothing; it's here to avoid changing evaluation results.
impureEnvVars = [ impureEnvVars = [
"http_proxy" "https_proxy" "ftp_proxy" "all_proxy" "no_proxy" "http_proxy"
"https_proxy"
"ftp_proxy"
"all_proxy"
"no_proxy"
]; ];
# To make "nix-prefetch-url" work. # To make "nix-prefetch-url" work.
urls = [ url ]; urls = [ url ];
} // (if impure }
then { __impure = true; } // (if impure then { __impure = true; } else { inherit outputHashAlgo outputHash; })
else { inherit outputHashAlgo outputHash; })) )

View file

@ -1,15 +1,20 @@
attrs @ { drvPath, outputs, name, ... }: attrs@{
drvPath,
outputs,
name,
...
}:
let let
commonAttrs = (builtins.listToAttrs outputsList) // commonAttrs = (builtins.listToAttrs outputsList) // {
{ all = map (x: x.value) outputsList; all = map (x: x.value) outputsList;
inherit drvPath name; inherit drvPath name;
type = "derivation"; type = "derivation";
}; };
outputToAttrListElement = outputName: outputToAttrListElement = outputName: {
{ name = outputName; name = outputName;
value = commonAttrs // { value = commonAttrs // {
outPath = builtins.getAttr outputName attrs; outPath = builtins.getAttr outputName attrs;
inherit outputName; inherit outputName;
@ -18,4 +23,5 @@ let
outputsList = map outputToAttrListElement outputs; outputsList = map outputToAttrListElement outputs;
in (builtins.head outputsList).value in
(builtins.head outputsList).value

View file

@ -1,22 +1,23 @@
{ lib {
, stdenv lib,
, mkMesonLibrary stdenv,
mkMesonLibrary,
, bison bison,
, flex flex,
, cmake # for resolving toml11 dep cmake, # for resolving toml11 dep
, nix-util nix-util,
, nix-store nix-store,
, nix-fetchers nix-fetchers,
, boost boost,
, boehmgc boehmgc,
, nlohmann_json nlohmann_json,
, toml11 toml11,
# Configuration Options # Configuration Options
, version version,
# Whether to use garbage collection for the Nix language evaluator. # Whether to use garbage collection for the Nix language evaluator.
# #
@ -27,7 +28,7 @@
# #
# Temporarily disabled on Windows because the `GC_throw_bad_alloc` # Temporarily disabled on Windows because the `GC_throw_bad_alloc`
# symbol is missing during linking. # symbol is missing during linking.
, enableGC ? !stdenv.hostPlatform.isWindows enableGC ? !stdenv.hostPlatform.isWindows,
}: }:
let let
@ -51,10 +52,7 @@ mkMesonLibrary (finalAttrs: {
(fileset.fileFilter (file: file.hasExt "hh") ./.) (fileset.fileFilter (file: file.hasExt "hh") ./.)
./lexer.l ./lexer.l
./parser.y ./parser.y
(fileset.difference (fileset.difference (fileset.fileFilter (file: file.hasExt "nix") ./.) ./package.nix)
(fileset.fileFilter (file: file.hasExt "nix") ./.)
./package.nix
)
]; ];
nativeBuildInputs = [ nativeBuildInputs = [

View file

@ -26,19 +26,25 @@
Note that `derivation` is very bare-bones, and provides almost no commands during the build. Note that `derivation` is very bare-bones, and provides almost no commands during the build.
Most likely, you'll want to use functions like `stdenv.mkDerivation` in Nixpkgs to set up a basic environment. Most likely, you'll want to use functions like `stdenv.mkDerivation` in Nixpkgs to set up a basic environment.
*/ */
drvAttrs @ { outputs ? [ "out" ], ... }: drvAttrs@{
outputs ? [ "out" ],
...
}:
let let
strict = derivationStrict drvAttrs; strict = derivationStrict drvAttrs;
commonAttrs = drvAttrs // (builtins.listToAttrs outputsList) // commonAttrs =
{ all = map (x: x.value) outputsList; drvAttrs
// (builtins.listToAttrs outputsList)
// {
all = map (x: x.value) outputsList;
inherit drvAttrs; inherit drvAttrs;
}; };
outputToAttrListElement = outputName: outputToAttrListElement = outputName: {
{ name = outputName; name = outputName;
value = commonAttrs // { value = commonAttrs // {
outPath = builtins.getAttr outputName strict; outPath = builtins.getAttr outputName strict;
drvPath = strict.drvPath; drvPath = strict.drvPath;
@ -49,4 +55,5 @@ let
outputsList = map outputToAttrListElement outputs; outputsList = map outputToAttrListElement outputs;
in (builtins.head outputsList).value in
(builtins.head outputsList).value

View file

@ -1,19 +1,20 @@
{ lib {
, buildPackages lib,
, stdenv buildPackages,
, mkMesonExecutable stdenv,
mkMesonExecutable,
, nix-fetchers nix-fetchers,
, nix-store-test-support nix-store-test-support,
, rapidcheck rapidcheck,
, gtest gtest,
, runCommand runCommand,
# Configuration Options # Configuration Options
, version version,
, resolvePath resolvePath,
}: }:
let let
@ -56,16 +57,22 @@ mkMesonExecutable (finalAttrs: {
passthru = { passthru = {
tests = { tests = {
run = runCommand "${finalAttrs.pname}-run" { run =
runCommand "${finalAttrs.pname}-run"
{
meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages; meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages;
} (lib.optionalString stdenv.hostPlatform.isWindows '' }
(
lib.optionalString stdenv.hostPlatform.isWindows ''
export HOME="$PWD/home-dir" export HOME="$PWD/home-dir"
mkdir -p "$HOME" mkdir -p "$HOME"
'' + '' ''
+ ''
export _NIX_TEST_UNIT_DATA=${resolvePath ./data} export _NIX_TEST_UNIT_DATA=${resolvePath ./data}
${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage} ${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage}
touch $out touch $out
''); ''
);
}; };
}; };

View file

@ -1,14 +1,15 @@
{ lib {
, mkMesonLibrary lib,
mkMesonLibrary,
, nix-util nix-util,
, nix-store nix-store,
, nlohmann_json nlohmann_json,
, libgit2 libgit2,
# Configuration Options # Configuration Options
, version version,
}: }:
let let

View file

@ -1,13 +1,14 @@
{ lib {
, mkMesonLibrary lib,
mkMesonLibrary,
, nix-store-c nix-store-c,
, nix-expr-c nix-expr-c,
, nix-flake nix-flake,
# Configuration Options # Configuration Options
, version version,
}: }:
let let

View file

@ -1,20 +1,21 @@
{ lib {
, buildPackages lib,
, stdenv buildPackages,
, mkMesonExecutable stdenv,
mkMesonExecutable,
, nix-flake nix-flake,
, nix-flake-c nix-flake-c,
, nix-expr-test-support nix-expr-test-support,
, rapidcheck rapidcheck,
, gtest gtest,
, runCommand runCommand,
# Configuration Options # Configuration Options
, version version,
, resolvePath resolvePath,
}: }:
let let
@ -58,17 +59,23 @@ mkMesonExecutable (finalAttrs: {
passthru = { passthru = {
tests = { tests = {
run = runCommand "${finalAttrs.pname}-run" { run =
runCommand "${finalAttrs.pname}-run"
{
meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages; meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages;
} (lib.optionalString stdenv.hostPlatform.isWindows '' }
(
lib.optionalString stdenv.hostPlatform.isWindows ''
export HOME="$PWD/home-dir" export HOME="$PWD/home-dir"
mkdir -p "$HOME" mkdir -p "$HOME"
'' + '' ''
+ ''
export _NIX_TEST_UNIT_DATA=${resolvePath ./data} export _NIX_TEST_UNIT_DATA=${resolvePath ./data}
export NIX_CONFIG="extra-experimental-features = flakes" export NIX_CONFIG="extra-experimental-features = flakes"
${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage} ${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage}
touch $out touch $out
''); ''
);
}; };
}; };

View file

@ -1,15 +1,16 @@
{ lib {
, mkMesonLibrary lib,
mkMesonLibrary,
, nix-util nix-util,
, nix-store nix-store,
, nix-fetchers nix-fetchers,
, nix-expr nix-expr,
, nlohmann_json nlohmann_json,
# Configuration Options # Configuration Options
, version version,
}: }:
let let

View file

@ -1,14 +1,15 @@
{ lib {
, mkMesonLibrary lib,
mkMesonLibrary,
, nix-util-c nix-util-c,
, nix-store nix-store,
, nix-store-c nix-store-c,
, nix-main nix-main,
# Configuration Options # Configuration Options
, version version,
}: }:
let let

View file

@ -1,14 +1,15 @@
{ lib {
, mkMesonLibrary lib,
mkMesonLibrary,
, openssl openssl,
, nix-util nix-util,
, nix-store nix-store,
# Configuration Options # Configuration Options
, version version,
}: }:
let let

View file

@ -1,12 +1,13 @@
{ lib {
, mkMesonLibrary lib,
mkMesonLibrary,
, nix-util-c nix-util-c,
, nix-store nix-store,
# Configuration Options # Configuration Options
, version version,
}: }:
let let

View file

@ -1,15 +1,16 @@
{ lib {
, mkMesonLibrary lib,
mkMesonLibrary,
, nix-util-test-support nix-util-test-support,
, nix-store nix-store,
, nix-store-c nix-store-c,
, rapidcheck rapidcheck,
# Configuration Options # Configuration Options
, version version,
}: }:
let let

View file

@ -1,21 +1,22 @@
{ lib {
, buildPackages lib,
, stdenv buildPackages,
, mkMesonExecutable stdenv,
mkMesonExecutable,
, nix-store nix-store,
, nix-store-c nix-store-c,
, nix-store-test-support nix-store-test-support,
, sqlite sqlite,
, rapidcheck rapidcheck,
, gtest gtest,
, runCommand runCommand,
# Configuration Options # Configuration Options
, version version,
, filesetToSource filesetToSource,
}: }:
let let
@ -64,7 +65,8 @@ mkMesonExecutable (finalAttrs: {
passthru = { passthru = {
tests = { tests = {
run = let run =
let
# Some data is shared with the functional tests: they create it, # Some data is shared with the functional tests: they create it,
# we consume it. # we consume it.
data = filesetToSource { data = filesetToSource {
@ -74,16 +76,22 @@ mkMesonExecutable (finalAttrs: {
../../tests/functional/derivation ../../tests/functional/derivation
]; ];
}; };
in runCommand "${finalAttrs.pname}-run" { in
runCommand "${finalAttrs.pname}-run"
{
meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages; meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages;
} (lib.optionalString stdenv.hostPlatform.isWindows '' }
(
lib.optionalString stdenv.hostPlatform.isWindows ''
export HOME="$PWD/home-dir" export HOME="$PWD/home-dir"
mkdir -p "$HOME" mkdir -p "$HOME"
'' + '' ''
+ ''
export _NIX_TEST_UNIT_DATA=${data + "/src/libstore-tests/data"} export _NIX_TEST_UNIT_DATA=${data + "/src/libstore-tests/data"}
${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage} ${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage}
touch $out touch $out
''); ''
);
}; };
}; };

View file

@ -1,25 +1,26 @@
{ lib {
, stdenv lib,
, mkMesonLibrary stdenv,
mkMesonLibrary,
, unixtools unixtools,
, darwin darwin,
, nix-util nix-util,
, boost boost,
, curl curl,
, aws-sdk-cpp aws-sdk-cpp,
, libseccomp libseccomp,
, nlohmann_json nlohmann_json,
, sqlite sqlite,
, busybox-sandbox-shell ? null busybox-sandbox-shell ? null,
# Configuration Options # Configuration Options
, version version,
, embeddedSandboxShell ? stdenv.hostPlatform.isStatic embeddedSandboxShell ? stdenv.hostPlatform.isStatic,
}: }:
let let
@ -48,19 +49,20 @@ mkMesonLibrary (finalAttrs: {
(fileset.fileFilter (file: file.hasExt "sql") ./.) (fileset.fileFilter (file: file.hasExt "sql") ./.)
]; ];
nativeBuildInputs = nativeBuildInputs = lib.optional embeddedSandboxShell unixtools.hexdump;
lib.optional embeddedSandboxShell unixtools.hexdump;
buildInputs = [ buildInputs =
[
boost boost
curl curl
sqlite sqlite
] ++ lib.optional stdenv.hostPlatform.isLinux libseccomp ]
++ lib.optional stdenv.hostPlatform.isLinux libseccomp
# There have been issues building these dependencies # There have been issues building these dependencies
++ lib.optional stdenv.hostPlatform.isDarwin darwin.apple_sdk.libs.sandbox ++ lib.optional stdenv.hostPlatform.isDarwin darwin.apple_sdk.libs.sandbox
++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform && (stdenv.isLinux || stdenv.isDarwin)) ++ lib.optional (
aws-sdk-cpp stdenv.hostPlatform == stdenv.buildPlatform && (stdenv.isLinux || stdenv.isDarwin)
; ) aws-sdk-cpp;
propagatedBuildInputs = [ propagatedBuildInputs = [
nix-util nix-util
@ -75,10 +77,12 @@ mkMesonLibrary (finalAttrs: {
echo ${version} > ../../.version echo ${version} > ../../.version
''; '';
mesonFlags = [ mesonFlags =
[
(lib.mesonEnable "seccomp-sandboxing" stdenv.hostPlatform.isLinux) (lib.mesonEnable "seccomp-sandboxing" stdenv.hostPlatform.isLinux)
(lib.mesonBool "embedded-sandbox-shell" embeddedSandboxShell) (lib.mesonBool "embedded-sandbox-shell" embeddedSandboxShell)
] ++ lib.optionals stdenv.hostPlatform.isLinux [ ]
++ lib.optionals stdenv.hostPlatform.isLinux [
(lib.mesonOption "sandbox-shell" "${busybox-sandbox-shell}/bin/busybox") (lib.mesonOption "sandbox-shell" "${busybox-sandbox-shell}/bin/busybox")
]; ];

View file

@ -1,11 +1,12 @@
{ lib {
, mkMesonLibrary lib,
mkMesonLibrary,
, nix-util nix-util,
# Configuration Options # Configuration Options
, version version,
}: }:
let let

View file

@ -1,14 +1,15 @@
{ lib {
, mkMesonLibrary lib,
mkMesonLibrary,
, nix-util nix-util,
, nix-util-c nix-util-c,
, rapidcheck rapidcheck,
# Configuration Options # Configuration Options
, version version,
}: }:
let let

View file

@ -1,19 +1,20 @@
{ lib {
, buildPackages lib,
, stdenv buildPackages,
, mkMesonExecutable stdenv,
mkMesonExecutable,
, nix-util nix-util,
, nix-util-c nix-util-c,
, nix-util-test-support nix-util-test-support,
, rapidcheck rapidcheck,
, gtest gtest,
, runCommand runCommand,
# Configuration Options # Configuration Options
, version version,
}: }:
let let
@ -57,16 +58,22 @@ mkMesonExecutable (finalAttrs: {
passthru = { passthru = {
tests = { tests = {
run = runCommand "${finalAttrs.pname}-run" { run =
runCommand "${finalAttrs.pname}-run"
{
meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages; meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages;
} (lib.optionalString stdenv.hostPlatform.isWindows '' }
(
lib.optionalString stdenv.hostPlatform.isWindows ''
export HOME="$PWD/home-dir" export HOME="$PWD/home-dir"
mkdir -p "$HOME" mkdir -p "$HOME"
'' + '' ''
+ ''
export _NIX_TEST_UNIT_DATA=${./data} export _NIX_TEST_UNIT_DATA=${./data}
${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage} ${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage}
touch $out touch $out
''); ''
);
}; };
}; };

View file

@ -1,18 +1,19 @@
{ lib {
, stdenv lib,
, mkMesonLibrary stdenv,
mkMesonLibrary,
, boost boost,
, brotli brotli,
, libarchive libarchive,
, libcpuid libcpuid,
, libsodium libsodium,
, nlohmann_json nlohmann_json,
, openssl openssl,
# Configuration Options # Configuration Options
, version version,
}: }:
let let
@ -43,8 +44,7 @@ mkMesonLibrary (finalAttrs: {
brotli brotli
libsodium libsodium
openssl openssl
] ++ lib.optional stdenv.hostPlatform.isx86_64 libcpuid ] ++ lib.optional stdenv.hostPlatform.isx86_64 libcpuid;
;
propagatedBuildInputs = [ propagatedBuildInputs = [
boost boost

View file

@ -1,4 +1,8 @@
{ name, channelName, src }: {
name,
channelName,
src,
}:
derivation { derivation {
builder = "builtin:unpack-channel"; builder = "builtin:unpack-channel";

View file

@ -8,13 +8,15 @@ derivation {
inherit manifest; inherit manifest;
# !!! grmbl, need structured data for passing this in a clean way. # !!! grmbl, need structured data for passing this in a clean way.
derivations = derivations = map (
map (d: d:
[ (d.meta.active or "true") [
(d.meta.active or "true")
(d.meta.priority or 5) (d.meta.priority or 5)
(builtins.length d.outputs) (builtins.length d.outputs)
] ++ map (output: builtins.getAttr output d) d.outputs) ]
derivations; ++ map (output: builtins.getAttr output d) d.outputs
) derivations;
# Building user environments remotely just causes huge amounts of # Building user environments remotely just causes huge amounts of
# network traffic, so don't do that. # network traffic, so don't do that.

View file

@ -1,14 +1,15 @@
{ lib {
, mkMesonExecutable lib,
mkMesonExecutable,
, nix-store nix-store,
, nix-expr nix-expr,
, nix-main nix-main,
, nix-cmd nix-cmd,
# Configuration Options # Configuration Options
, version version,
}: }:
let let
@ -20,7 +21,8 @@ mkMesonExecutable (finalAttrs: {
inherit version; inherit version;
workDir = ./.; workDir = ./.;
fileset = fileset.unions ([ fileset = fileset.unions (
[
../../nix-meson-build-support ../../nix-meson-build-support
./nix-meson-build-support ./nix-meson-build-support
../../.version ../../.version
@ -61,7 +63,9 @@ mkMesonExecutable (finalAttrs: {
../../doc/manual/source/command-ref/files/profiles.md ../../doc/manual/source/command-ref/files/profiles.md
# Files # Files
] ++ lib.concatMap ]
++
lib.concatMap
(dir: [ (dir: [
(fileset.fileFilter (file: file.hasExt "cc") dir) (fileset.fileFilter (file: file.hasExt "cc") dir)
(fileset.fileFilter (file: file.hasExt "hh") dir) (fileset.fileFilter (file: file.hasExt "hh") dir)

View file

@ -1,36 +1,41 @@
{ lib {
, stdenv lib,
, mkMesonDerivation stdenv,
, pkg-config mkMesonDerivation,
, perl pkg-config,
, perlPackages perl,
, nix-store perlPackages,
, version nix-store,
, curl version,
, bzip2 curl,
, libsodium bzip2,
libsodium,
}: }:
let let
inherit (lib) fileset; inherit (lib) fileset;
in in
perl.pkgs.toPerlModule (mkMesonDerivation (finalAttrs: { perl.pkgs.toPerlModule (
mkMesonDerivation (finalAttrs: {
pname = "nix-perl"; pname = "nix-perl";
inherit version; inherit version;
workDir = ./.; workDir = ./.;
fileset = fileset.unions ([ fileset = fileset.unions (
[
./.version ./.version
../../.version ../../.version
./MANIFEST ./MANIFEST
./lib ./lib
./meson.build ./meson.build
./meson.options ./meson.options
] ++ lib.optionals finalAttrs.doCheck [ ]
++ lib.optionals finalAttrs.doCheck [
./.yath.rc.in ./.yath.rc.in
./t ./t
]); ]
);
nativeBuildInputs = [ nativeBuildInputs = [
pkg-config pkg-config
@ -73,4 +78,5 @@ perl.pkgs.toPerlModule (mkMesonDerivation (finalAttrs: {
]; ];
strictDeps = false; strictDeps = false;
})) })
)

View file

@ -1,6 +1,25 @@
let let
sixteenBytes = "0123456789abcdef"; sixteenBytes = "0123456789abcdef";
times16 = s: builtins.concatStringsSep "" [s s s s s s s s s s s s s s s s]; times16 =
s:
builtins.concatStringsSep "" [
s
s
s
s
s
s
s
s
s
s
s
s
s
s
s
s
];
exp = n: x: if n == 1 then x else times16 (exp (n - 1) x); exp = n: x: if n == 1 then x else times16 (exp (n - 1) x);
sixteenMegabyte = exp 6 sixteenBytes; sixteenMegabyte = exp 6 sixteenBytes;
in in

View file

@ -4,18 +4,33 @@ with import ./config.nix;
let let
mkDerivation = args: mkDerivation =
derivation ({ args:
derivation (
{
inherit system; inherit system;
builder = busybox; builder = busybox;
args = ["sh" "-e" args.builder or (builtins.toFile "builder-${args.name}.sh" '' args = [
"sh"
"-e"
args.builder or (builtins.toFile "builder-${args.name}.sh" ''
if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi; if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi;
eval "$buildCommand" eval "$buildCommand"
'')]; '')
];
outputHashMode = "recursive"; outputHashMode = "recursive";
outputHashAlgo = "sha256"; outputHashAlgo = "sha256";
} // removeAttrs args ["builder" "meta" "passthru"]) }
// { meta = args.meta or {}; passthru = args.passthru or {}; }; // removeAttrs args [
"builder"
"meta"
"passthru"
]
)
// {
meta = args.meta or { };
passthru = args.passthru or { };
};
input1 = mkDerivation { input1 = mkDerivation {
shell = busybox; shell = busybox;
@ -51,8 +66,7 @@ in
shell = busybox; shell = busybox;
name = "build-remote"; name = "build-remote";
passthru = { inherit input1 input2 input3; }; passthru = { inherit input1 input2 input3; };
buildCommand = buildCommand = ''
''
read x < ${input1} read x < ${input1}
read y < ${input3} read y < ${input3}
echo "$x $y" > $out echo "$x $y" > $out

View file

@ -1,26 +1,48 @@
{ busybox, contentAddressed ? false }: {
busybox,
contentAddressed ? false,
}:
with import ./config.nix; with import ./config.nix;
let let
caArgs = if contentAddressed then { caArgs =
if contentAddressed then
{
outputHashMode = "recursive"; outputHashMode = "recursive";
outputHashAlgo = "sha256"; outputHashAlgo = "sha256";
__contentAddressed = true; __contentAddressed = true;
} else {}; }
else
{ };
mkDerivation = args: mkDerivation =
derivation ({ args:
derivation (
{
inherit system; inherit system;
builder = busybox; builder = busybox;
args = ["sh" "-e" args.builder or (builtins.toFile "builder-${args.name}.sh" '' args = [
"sh"
"-e"
args.builder or (builtins.toFile "builder-${args.name}.sh" ''
if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi; if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi;
eval "$buildCommand" eval "$buildCommand"
'')]; '')
} // removeAttrs args ["builder" "meta" "passthru"] ];
// caArgs) }
// { meta = args.meta or {}; passthru = args.passthru or {}; }; // removeAttrs args [
"builder"
"meta"
"passthru"
]
// caArgs
)
// {
meta = args.meta or { };
passthru = args.passthru or { };
};
input1 = mkDerivation { input1 = mkDerivation {
shell = busybox; shell = busybox;
@ -53,8 +75,7 @@ in
shell = busybox; shell = busybox;
name = "build-remote"; name = "build-remote";
passthru = { inherit input1 input2 input3; }; passthru = { inherit input1 input2 input3; };
buildCommand = buildCommand = ''
''
read x < ${input1} read x < ${input1}
read y < ${input3} read y < ${input3}
echo "$x $y" > $out echo "$x $y" > $out

View file

@ -1 +1,5 @@
{ inNixShell ? false, ... }@args: import ./shell.nix (args // { contentAddressed = true; }) {
inNixShell ? false,
...
}@args:
import ./shell.nix (args // { contentAddressed = true; })

View file

@ -1,13 +1,21 @@
with import ./config.nix; with import ./config.nix;
let mkCADerivation = args: mkDerivation ({ let
mkCADerivation =
args:
mkDerivation (
{
__contentAddressed = true; __contentAddressed = true;
outputHashMode = "recursive"; outputHashMode = "recursive";
outputHashAlgo = "sha256"; outputHashAlgo = "sha256";
} // args); }
// args
);
in in
{ seed ? 0 }: {
seed ? 0,
}:
# A simple content-addressed derivation. # A simple content-addressed derivation.
# The derivation can be arbitrarily modified by passing a different `seed`, # The derivation can be arbitrarily modified by passing a different `seed`,
# but the output will always be the same # but the output will always be the same
@ -23,7 +31,11 @@ rec {
}; };
rootCA = mkCADerivation { rootCA = mkCADerivation {
name = "rootCA"; name = "rootCA";
outputs = [ "out" "dev" "foo" ]; outputs = [
"out"
"dev"
"foo"
];
buildCommand = '' buildCommand = ''
echo "building a CA derivation" echo "building a CA derivation"
echo "The seed is ${toString seed}" echo "The seed is ${toString seed}"

View file

@ -1,10 +1,16 @@
with import ./config.nix; with import ./config.nix;
let mkCADerivation = args: mkDerivation ({ let
mkCADerivation =
args:
mkDerivation (
{
__contentAddressed = true; __contentAddressed = true;
outputHashMode = "recursive"; outputHashMode = "recursive";
outputHashAlgo = "sha256"; outputHashAlgo = "sha256";
} // args); }
// args
);
in in
rec { rec {
@ -15,7 +21,9 @@ rec {
echo $(date) > $out/current-time echo $(date) > $out/current-time
''; '';
}; };
dep = seed: mkCADerivation { dep =
seed:
mkCADerivation {
name = "dep"; name = "dep";
inherit seed; inherit seed;
buildCommand = '' buildCommand = ''
@ -32,4 +40,3 @@ rec {
''; '';
}; };
} }

View file

@ -1,7 +1,6 @@
# A derivation that would certainly fail if several builders tried to # A derivation that would certainly fail if several builders tried to
# build it at once. # build it at once.
with import ./config.nix; with import ./config.nix;
mkDerivation { mkDerivation {

View file

@ -4,9 +4,14 @@ rec {
dep = import ./dependencies.nix { }; dep = import ./dependencies.nix { };
makeTest = nr: args: mkDerivation ({ makeTest =
nr: args:
mkDerivation (
{
name = "check-refs-" + toString nr; name = "check-refs-" + toString nr;
} // args); }
// args
);
src = builtins.toFile "aux-ref" "bla bla"; src = builtins.toFile "aux-ref" "bla bla";

View file

@ -22,7 +22,9 @@ rec {
''; '';
}; };
makeTest = nr: allowreqs: mkDerivation { makeTest =
nr: allowreqs:
mkDerivation {
name = "check-reqs-" + toString nr; name = "check-reqs-" + toString nr;
inherit deps; inherit deps;
builder = builtins.toFile "builder.sh" '' builder = builtins.toFile "builder.sh" ''
@ -33,11 +35,21 @@ rec {
}; };
# When specifying all the requisites, the build succeeds. # When specifying all the requisites, the build succeeds.
test1 = makeTest 1 [ dep1 dep2 deps ]; test1 = makeTest 1 [
dep1
dep2
deps
];
# But missing anything it fails. # But missing anything it fails.
test2 = makeTest 2 [ dep2 deps ]; test2 = makeTest 2 [
test3 = makeTest 3 [ dep1 deps ]; dep2
deps
];
test3 = makeTest 3 [
dep1
deps
];
test4 = makeTest 4 [ deps ]; test4 = makeTest 4 [ deps ];
test5 = makeTest 5 [ ]; test5 = makeTest 5 [ ];

View file

@ -1,4 +1,6 @@
{checkBuildId ? 0}: {
checkBuildId ? 0,
}:
with import ./config.nix; with import ./config.nix;
@ -6,8 +8,7 @@ with import ./config.nix;
nondeterministic = mkDerivation { nondeterministic = mkDerivation {
inherit checkBuildId; inherit checkBuildId;
name = "nondeterministic"; name = "nondeterministic";
buildCommand = buildCommand = ''
''
mkdir $out mkdir $out
date +%s.%N > $out/date date +%s.%N > $out/date
echo "CHECK_TMPDIR=$TMPDIR" echo "CHECK_TMPDIR=$TMPDIR"
@ -19,8 +20,7 @@ with import ./config.nix;
deterministic = mkDerivation { deterministic = mkDerivation {
inherit checkBuildId; inherit checkBuildId;
name = "deterministic"; name = "deterministic";
buildCommand = buildCommand = ''
''
mkdir $out mkdir $out
echo date > $out/date echo date > $out/date
echo "CHECK_TMPDIR=$TMPDIR" echo "CHECK_TMPDIR=$TMPDIR"
@ -32,8 +32,7 @@ with import ./config.nix;
failed = mkDerivation { failed = mkDerivation {
inherit checkBuildId; inherit checkBuildId;
name = "failed"; name = "failed";
buildCommand = buildCommand = ''
''
mkdir $out mkdir $out
echo date > $out/date echo date > $out/date
echo "CHECK_TMPDIR=$TMPDIR" echo "CHECK_TMPDIR=$TMPDIR"

View file

@ -1,4 +1,6 @@
{ hashInvalidator ? "" }: {
hashInvalidator ? "",
}:
with import ./config.nix; with import ./config.nix;
let let

View file

@ -2,5 +2,8 @@ derivation {
name = "advanced-attributes-defaults"; name = "advanced-attributes-defaults";
system = "my-system"; system = "my-system";
builder = "/bin/bash"; builder = "/bin/bash";
args = [ "-c" "echo hello > $out" ]; args = [
"-c"
"echo hello > $out"
];
} }

View file

@ -2,7 +2,13 @@ derivation {
name = "advanced-attributes-structured-attrs-defaults"; name = "advanced-attributes-structured-attrs-defaults";
system = "my-system"; system = "my-system";
builder = "/bin/bash"; builder = "/bin/bash";
args = [ "-c" "echo hello > $out" ]; args = [
outputs = [ "out" "dev" ]; "-c"
"echo hello > $out"
];
outputs = [
"out"
"dev"
];
__structuredAttrs = true; __structuredAttrs = true;
} }

View file

@ -4,26 +4,39 @@ let
inherit system; inherit system;
name = "foo"; name = "foo";
builder = "/bin/bash"; builder = "/bin/bash";
args = ["-c" "echo foo > $out"]; args = [
"-c"
"echo foo > $out"
];
}; };
bar = derivation { bar = derivation {
inherit system; inherit system;
name = "bar"; name = "bar";
builder = "/bin/bash"; builder = "/bin/bash";
args = ["-c" "echo bar > $out"]; args = [
"-c"
"echo bar > $out"
];
}; };
in in
derivation { derivation {
inherit system; inherit system;
name = "advanced-attributes-structured-attrs"; name = "advanced-attributes-structured-attrs";
builder = "/bin/bash"; builder = "/bin/bash";
args = [ "-c" "echo hello > $out" ]; args = [
"-c"
"echo hello > $out"
];
__sandboxProfile = "sandcastle"; __sandboxProfile = "sandcastle";
__noChroot = true; __noChroot = true;
__impureHostDeps = [ "/usr/bin/ditto" ]; __impureHostDeps = [ "/usr/bin/ditto" ];
impureEnvVars = [ "UNICORN" ]; impureEnvVars = [ "UNICORN" ];
__darwinAllowLocalNetworking = true; __darwinAllowLocalNetworking = true;
outputs = [ "out" "bin" "dev" ]; outputs = [
"out"
"bin"
"dev"
];
__structuredAttrs = true; __structuredAttrs = true;
outputChecks = { outputChecks = {
out = { out = {
@ -39,7 +52,10 @@ derivation {
maxClosureSize = 5909; maxClosureSize = 5909;
}; };
}; };
requiredSystemFeatures = ["rainbow" "uid-range"]; requiredSystemFeatures = [
"rainbow"
"uid-range"
];
preferLocalBuild = true; preferLocalBuild = true;
allowSubstitutes = false; allowSubstitutes = false;
} }

View file

@ -4,20 +4,29 @@ let
inherit system; inherit system;
name = "foo"; name = "foo";
builder = "/bin/bash"; builder = "/bin/bash";
args = ["-c" "echo foo > $out"]; args = [
"-c"
"echo foo > $out"
];
}; };
bar = derivation { bar = derivation {
inherit system; inherit system;
name = "bar"; name = "bar";
builder = "/bin/bash"; builder = "/bin/bash";
args = ["-c" "echo bar > $out"]; args = [
"-c"
"echo bar > $out"
];
}; };
in in
derivation { derivation {
inherit system; inherit system;
name = "advanced-attributes"; name = "advanced-attributes";
builder = "/bin/bash"; builder = "/bin/bash";
args = [ "-c" "echo hello > $out" ]; args = [
"-c"
"echo hello > $out"
];
__sandboxProfile = "sandcastle"; __sandboxProfile = "sandcastle";
__noChroot = true; __noChroot = true;
__impureHostDeps = [ "/usr/bin/ditto" ]; __impureHostDeps = [ "/usr/bin/ditto" ];
@ -27,7 +36,10 @@ derivation {
allowedRequisites = [ foo ]; allowedRequisites = [ foo ];
disallowedReferences = [ bar ]; disallowedReferences = [ bar ];
disallowedRequisites = [ bar ]; disallowedRequisites = [ bar ];
requiredSystemFeatures = ["rainbow" "uid-range"]; requiredSystemFeatures = [
"rainbow"
"uid-range"
];
preferLocalBuild = true; preferLocalBuild = true;
allowSubstitutes = false; allowSubstitutes = false;
} }

View file

@ -1,6 +1,8 @@
with import ./config.nix; with import ./config.nix;
let innerName = "foo"; in let
innerName = "foo";
in
mkDerivation rec { mkDerivation rec {
name = "${innerName}.drv"; name = "${innerName}.drv";

View file

@ -2,8 +2,7 @@ with import ./config.nix;
rec { rec {
printRefs = printRefs = ''
''
echo $exportReferencesGraph echo $exportReferencesGraph
while read path; do while read path; do
read drv read drv
@ -17,13 +16,19 @@ rec {
foo."bar.runtimeGraph" = mkDerivation { foo."bar.runtimeGraph" = mkDerivation {
name = "dependencies"; name = "dependencies";
builder = builtins.toFile "build-graph-builder" "${printRefs}"; builder = builtins.toFile "build-graph-builder" "${printRefs}";
exportReferencesGraph = ["refs" (import ./dependencies.nix {})]; exportReferencesGraph = [
"refs"
(import ./dependencies.nix { })
];
}; };
foo."bar.buildGraph" = mkDerivation { foo."bar.buildGraph" = mkDerivation {
name = "dependencies"; name = "dependencies";
builder = builtins.toFile "build-graph-builder" "${printRefs}"; builder = builtins.toFile "build-graph-builder" "${printRefs}";
exportReferencesGraph = ["refs" (import ./dependencies.nix {}).drvPath]; exportReferencesGraph = [
"refs"
(import ./dependencies.nix { }).drvPath
];
}; };
} }

View file

@ -2,16 +2,29 @@
with import ./config.nix; with import ./config.nix;
let let
mkDerivation = args: mkDerivation =
derivation ({ args:
derivation (
{
inherit system; inherit system;
builder = busybox; builder = busybox;
args = ["sh" "-e" args.builder or (builtins.toFile "builder-${args.name}.sh" '' args = [
"sh"
"-e"
args.builder or (builtins.toFile "builder-${args.name}.sh" ''
if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi; if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi;
eval "$buildCommand" eval "$buildCommand"
'')]; '')
} // removeAttrs args ["builder" "meta"]) ];
// { meta = args.meta or {}; }; }
// removeAttrs args [
"builder"
"meta"
]
)
// {
meta = args.meta or { };
};
in in
{ {

View file

@ -4,9 +4,12 @@ mkDerivation {
name = "filter"; name = "filter";
builder = builtins.toFile "builder" "ln -s $input $out"; builder = builtins.toFile "builder" "ln -s $input $out";
input = input =
let filter = path: type: let
filter =
path: type:
type != "symlink" type != "symlink"
&& baseNameOf path != "foo" && baseNameOf path != "foo"
&& !((import ./lang/lib.nix).hasSuffix ".bak" (baseNameOf path)); && !((import ./lang/lib.nix).hasSuffix ".bak" (baseNameOf path));
in builtins.filterSource filter ((builtins.getEnv "TEST_ROOT") + "/filterin"); in
builtins.filterSource filter ((builtins.getEnv "TEST_ROOT") + "/filterin");
} }

View file

@ -2,14 +2,19 @@ with import ./config.nix;
rec { rec {
f2 = dummy: builder: mode: algo: hash: mkDerivation { f2 =
dummy: builder: mode: algo: hash:
mkDerivation {
name = "fixed"; name = "fixed";
inherit builder; inherit builder;
outputHashMode = mode; outputHashMode = mode;
outputHashAlgo = algo; outputHashAlgo = algo;
outputHash = hash; outputHash = hash;
inherit dummy; inherit dummy;
impureEnvVars = ["IMPURE_VAR1" "IMPURE_VAR2"]; impureEnvVars = [
"IMPURE_VAR1"
"IMPURE_VAR2"
];
}; };
f = f2 ""; f = f2 "";
@ -37,7 +42,8 @@ rec {
]; ];
sameAsAdd = sameAsAdd =
f ./fixed.builder2.sh "recursive" "sha256" "1ixr6yd3297ciyp9im522dfxpqbkhcw0pylkb2aab915278fqaik"; f ./fixed.builder2.sh "recursive" "sha256"
"1ixr6yd3297ciyp9im522dfxpqbkhcw0pylkb2aab915278fqaik";
bad = [ bad = [
(f ./fixed.builder1.sh "flat" "md5" "0ddd8be4b179a529afa5f2ffae4b9858") (f ./fixed.builder1.sh "flat" "md5" "0ddd8be4b179a529afa5f2ffae4b9858")

View file

@ -2,8 +2,7 @@ with import ./config.nix;
rec { rec {
x1 = mkDerivation { x1 = mkDerivation {
name = "x1"; name = "x1";
builder = builtins.toFile "builder.sh" builder = builtins.toFile "builder.sh" ''
''
echo $name > $out echo $name > $out
''; '';
outputHashMode = "recursive"; outputHashMode = "recursive";
@ -11,8 +10,7 @@ rec {
}; };
x2 = mkDerivation { x2 = mkDerivation {
name = "x2"; name = "x2";
builder = builtins.toFile "builder.sh" builder = builtins.toFile "builder.sh" ''
''
echo $name > $out echo $name > $out
''; '';
outputHashMode = "recursive"; outputHashMode = "recursive";
@ -20,8 +18,7 @@ rec {
}; };
x3 = mkDerivation { x3 = mkDerivation {
name = "x3"; name = "x3";
builder = builtins.toFile "builder.sh" builder = builtins.toFile "builder.sh" ''
''
echo $name > $out echo $name > $out
''; '';
outputHashMode = "recursive"; outputHashMode = "recursive";
@ -30,8 +27,7 @@ rec {
x4 = mkDerivation { x4 = mkDerivation {
name = "x4"; name = "x4";
inherit x2 x3; inherit x2 x3;
builder = builtins.toFile "builder.sh" builder = builtins.toFile "builder.sh" ''
''
echo $x2 $x3 echo $x2 $x3
exit 1 exit 1
''; '';

View file

@ -1,6 +1,8 @@
with import ./config.nix; with import ./config.nix;
{ lockFifo ? null }: {
lockFifo ? null,
}:
rec { rec {

View file

@ -4,14 +4,22 @@ let {
name = "dependencies-input-1"; name = "dependencies-input-1";
system = "i086-msdos"; system = "i086-msdos";
builder = "/bar/sh"; builder = "/bar/sh";
args = ["-e" "-x" ./dummy]; args = [
"-e"
"-x"
./dummy
];
}; };
input2 = derivation { input2 = derivation {
name = "dependencies-input-2"; name = "dependencies-input-2";
system = "i086-msdos"; system = "i086-msdos";
builder = "/bar/sh"; builder = "/bar/sh";
args = ["-e" "-x" ./dummy]; args = [
"-e"
"-x"
./dummy
];
outputHashMode = "recursive"; outputHashMode = "recursive";
outputHashAlgo = "md5"; outputHashAlgo = "md5";
outputHash = "ffffffffffffffffffffffffffffffff"; outputHash = "ffffffffffffffffffffffffffffffff";
@ -21,7 +29,11 @@ let {
name = "dependencies"; name = "dependencies";
system = "i086-msdos"; system = "i086-msdos";
builder = "/bar/sh"; builder = "/bar/sh";
args = ["-e" "-x" (./dummy + "/FOOBAR/../.")]; args = [
"-e"
"-x"
(./dummy + "/FOOBAR/../.")
];
input1 = input1 + "/."; input1 = input1 + "/.";
inherit input2; inherit input2;
}; };

View file

@ -1,31 +1,51 @@
{ busybox {
, seed busybox,
seed,
# If we want the final derivation output to have references to its # If we want the final derivation output to have references to its
# dependencies. Some tests need/want this, other don't. # dependencies. Some tests need/want this, other don't.
, withFinalRefs ? false withFinalRefs ? false,
}: }:
with import ./config.nix; with import ./config.nix;
let let
contentAddressedByDefault = builtins.getEnv "NIX_TESTS_CA_BY_DEFAULT" == "1"; contentAddressedByDefault = builtins.getEnv "NIX_TESTS_CA_BY_DEFAULT" == "1";
caArgs = if contentAddressedByDefault then { caArgs =
if contentAddressedByDefault then
{
__contentAddressed = true; __contentAddressed = true;
outputHashMode = "recursive"; outputHashMode = "recursive";
outputHashAlgo = "sha256"; outputHashAlgo = "sha256";
} else {}; }
else
{ };
mkDerivation = args: mkDerivation =
derivation ({ args:
derivation (
{
inherit system; inherit system;
builder = busybox; builder = busybox;
args = ["sh" "-e" args.builder or (builtins.toFile "builder-${args.name}.sh" '' args = [
"sh"
"-e"
args.builder or (builtins.toFile "builder-${args.name}.sh" ''
if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi; if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi;
eval "$buildCommand" eval "$buildCommand"
'')]; '')
} // removeAttrs args ["builder" "meta" "passthru"] ];
// caArgs) }
// { meta = args.meta or {}; passthru = args.passthru or {}; }; // removeAttrs args [
"builder"
"meta"
"passthru"
]
// caArgs
)
// {
meta = args.meta or { };
passthru = args.passthru or { };
};
input1 = mkDerivation { input1 = mkDerivation {
shell = busybox; shell = busybox;
@ -55,10 +75,11 @@ in
shell = busybox; shell = busybox;
name = "hermetic"; name = "hermetic";
passthru = { inherit input1 input2 input3; }; passthru = { inherit input1 input2 input3; };
buildCommand = buildCommand = ''
''
read x < ${input1} read x < ${input1}
read y < ${input3} read y < ${input3}
echo ${if (builtins.trace withFinalRefs withFinalRefs) then "${input1} ${input3}" else ""} "$x $y" > $out echo ${
if (builtins.trace withFinalRefs withFinalRefs) then "${input1} ${input3}" else ""
} "$x $y" > $out
''; '';
} }

View file

@ -1,10 +1,8 @@
with import ./config.nix; with import ./config.nix;
import ( import (mkDerivation {
mkDerivation {
name = "foo"; name = "foo";
bla = import ./dependencies.nix { }; bla = import ./dependencies.nix { };
buildCommand = " buildCommand = "
echo \\\"hi\\\" > $out echo \\\"hi\\\" > $out
"; ";
} })
)

View file

@ -3,8 +3,7 @@ with import <config>;
rec { rec {
bar = mkDerivation { bar = mkDerivation {
name = "bar"; name = "bar";
builder = builtins.toFile "builder.sh" builder = builtins.toFile "builder.sh" ''
''
echo 'builtins.add 123 456' > $out echo 'builtins.add 123 456' > $out
''; '';
}; };
@ -16,8 +15,7 @@ rec {
result = mkDerivation { result = mkDerivation {
name = "foo"; name = "foo";
builder = builtins.toFile "builder.sh" builder = builtins.toFile "builder.sh" ''
''
echo -n FOO${toString value} > $out echo -n FOO${toString value} > $out
''; '';
}; };
@ -25,8 +23,7 @@ rec {
addPath = mkDerivation { addPath = mkDerivation {
name = "add-path"; name = "add-path";
src = builtins.filterSource (path: type: true) result; src = builtins.filterSource (path: type: true) result;
builder = builtins.toFile "builder.sh" builder = builtins.toFile "builder.sh" ''
''
echo -n BLA$(cat $src) > $out echo -n BLA$(cat $src) > $out
''; '';
}; };

View file

@ -4,9 +4,11 @@ rec {
impure = mkDerivation { impure = mkDerivation {
name = "impure"; name = "impure";
outputs = [ "out" "stuff" ]; outputs = [
buildCommand = "out"
'' "stuff"
];
buildCommand = ''
echo impure echo impure
x=$(< $TEST_ROOT/counter) x=$(< $TEST_ROOT/counter)
mkdir $out $stuff mkdir $out $stuff
@ -20,8 +22,7 @@ rec {
impureOnImpure = mkDerivation { impureOnImpure = mkDerivation {
name = "impure-on-impure"; name = "impure-on-impure";
buildCommand = buildCommand = ''
''
echo impure-on-impure echo impure-on-impure
x=$(< ${impure}/n) x=$(< ${impure}/n)
mkdir $out mkdir $out
@ -35,16 +36,14 @@ rec {
# This is not allowed. # This is not allowed.
inputAddressed = mkDerivation { inputAddressed = mkDerivation {
name = "input-addressed"; name = "input-addressed";
buildCommand = buildCommand = ''
''
cat ${impure} > $out cat ${impure} > $out
''; '';
}; };
contentAddressed = mkDerivation { contentAddressed = mkDerivation {
name = "content-addressed"; name = "content-addressed";
buildCommand = buildCommand = ''
''
echo content-addressed echo content-addressed
x=$(< ${impureOnImpure}/n) x=$(< ${impureOnImpure}/n)
printf ''${x:0:1} > $out printf ''${x:0:1} > $out
@ -55,8 +54,7 @@ rec {
inputAddressedAfterCA = mkDerivation { inputAddressedAfterCA = mkDerivation {
name = "input-addressed-after-ca"; name = "input-addressed-after-ca";
buildCommand = buildCommand = ''
''
cat ${contentAddressed} > $out cat ${contentAddressed} > $out
''; '';
}; };

View file

@ -1,4 +1,3 @@
# Run: # Run:
# GC_INITIAL_HEAP_SIZE=$[1024 * 1024] NIX_SHOW_STATS=1 nix eval -f gc-coroutine-test.nix -vvvv # GC_INITIAL_HEAP_SIZE=$[1024 * 1024] NIX_SHOW_STATS=1 nix eval -f gc-coroutine-test.nix -vvvv
@ -11,10 +10,12 @@ let
# Generate a tree of numbers, n deep, such that the numbers add up to (1 + salt) * 10^n. # Generate a tree of numbers, n deep, such that the numbers add up to (1 + salt) * 10^n.
# The salting makes the numbers all different, increasing the likelihood of catching # The salting makes the numbers all different, increasing the likelihood of catching
# any memory corruptions that might be caused by the GC or otherwise. # any memory corruptions that might be caused by the GC or otherwise.
garbage = salt: n: garbage =
if n == 0 salt: n:
then [(1 + salt)] if n == 0 then
else [ [ (1 + salt) ]
else
[
(garbage (10 * salt + 1) (n - 1)) (garbage (10 * salt + 1) (n - 1))
(garbage (10 * salt - 1) (n - 1)) (garbage (10 * salt - 1) (n - 1))
(garbage (10 * salt + 2) (n - 1)) (garbage (10 * salt + 2) (n - 1))
@ -27,39 +28,38 @@ let
(garbage (10 * salt - 5) (n - 1)) (garbage (10 * salt - 5) (n - 1))
]; ];
pow = base: n: pow = base: n: if n == 0 then 1 else base * (pow base (n - 1));
if n == 0
then 1
else base * (pow base (n - 1));
sumNestedLists = l: sumNestedLists = l: if isList l then foldl' (a: b: a + sumNestedLists b) 0 l else l;
if isList l
then foldl' (a: b: a + sumNestedLists b) 0 l
else l;
in in
assert sumNestedLists (garbage 0 3) == pow 10 3; assert sumNestedLists (garbage 0 3) == pow 10 3;
assert sumNestedLists (garbage 0 6) == pow 10 6; assert sumNestedLists (garbage 0 6) == pow 10 6;
builtins.foldl' builtins.foldl'
(a: b: (
a: b:
assert assert
"${ "${builtins.path {
builtins.path {
path = ./src; path = ./src;
filter = path: type: filter =
path: type:
# We're not doing common subexpression elimination, so this reallocates # We're not doing common subexpression elimination, so this reallocates
# the fairly big tree over and over, producing a lot of garbage during # the fairly big tree over and over, producing a lot of garbage during
# source filtering, whose filter runs in a coroutine. # source filtering, whose filter runs in a coroutine.
assert sumNestedLists (garbage 0 3) == pow 10 3; assert sumNestedLists (garbage 0 3) == pow 10 3;
true; true;
} }}" == "${./src}";
}"
== "${./src}";
# These asserts don't seem necessary, as the lambda value get corrupted first # These asserts don't seem necessary, as the lambda value get corrupted first
assert a.okay; assert a.okay;
assert b.okay; assert b.okay;
{ okay = true; } {
okay = true;
}
) )
{ okay = true; } { okay = true; }
[ { okay = true; } { okay = true; } { okay = true; } ] [
{ okay = true; }
{ okay = true; }
{ okay = true; }
]

View file

@ -3,16 +3,23 @@ let
name = "fail"; name = "fail";
builder = "/bin/false"; builder = "/bin/false";
system = "x86_64-linux"; system = "x86_64-linux";
outputs = [ "out" "foo" ]; outputs = [
"out"
"foo"
];
}; };
drv1 = derivation { drv1 = derivation {
name = "fail-2"; name = "fail-2";
builder = "/bin/false"; builder = "/bin/false";
system = "x86_64-linux"; system = "x86_64-linux";
outputs = [ "out" "foo" ]; outputs = [
"out"
"foo"
];
}; };
combo-path = "${drv0.drvPath}${drv1.drvPath}"; combo-path = "${drv0.drvPath}${drv1.drvPath}";
in builtins.addDrvOutputDependencies combo-path in
builtins.addDrvOutputDependencies combo-path

View file

@ -3,7 +3,11 @@ let
name = "fail"; name = "fail";
builder = "/bin/false"; builder = "/bin/false";
system = "x86_64-linux"; system = "x86_64-linux";
outputs = [ "out" "foo" ]; outputs = [
"out"
"foo"
];
}; };
in builtins.addDrvOutputDependencies drv.outPath in
builtins.addDrvOutputDependencies drv.outPath

View file

@ -1,9 +1,9 @@
let let
countDown = n: countDown =
if n == 0 n:
then throw "kaboom" if n == 0 then
throw "kaboom"
else else
builtins.addErrorContext builtins.addErrorContext "while counting down; n = ${toString n}" ("x" + countDown (n - 1));
"while counting down; n = ${toString n}" in
("x" + countDown (n - 1)); countDown 10
in countDown 10

View file

@ -1,2 +1,8 @@
assert { a = true; } == { a = true; b = true; }; assert
{
a = true;
} == {
a = true;
b = true;
};
throw "unreachable" throw "unreachable"

View file

@ -1,2 +1,8 @@
assert { a = true; b = true; } == { a = true; }; assert
{
a = true;
b = true;
} == {
a = true;
};
throw "unreachable" throw "unreachable"

View file

@ -1,5 +1,14 @@
assert assert
{ foo = { type = "derivation"; outPath = "/nix/store/0"; }; } {
== foo = {
{ foo = { type = "derivation"; outPath = "/nix/store/1"; devious = true; }; }; type = "derivation";
outPath = "/nix/store/0";
};
} == {
foo = {
type = "derivation";
outPath = "/nix/store/1";
devious = true;
};
};
throw "unreachable" throw "unreachable"

View file

@ -1,5 +1,15 @@
assert assert
{ foo = { type = "derivation"; outPath = "/nix/store/0"; ignored = abort "not ignored"; }; } {
== foo = {
{ foo = { type = "derivation"; outPath = "/nix/store/1"; ignored = abort "not ignored"; }; }; type = "derivation";
outPath = "/nix/store/0";
ignored = abort "not ignored";
};
} == {
foo = {
type = "derivation";
outPath = "/nix/store/1";
ignored = abort "not ignored";
};
};
throw "unreachable" throw "unreachable"

View file

@ -1,7 +1,4 @@
# Note: functions in nested structures, e.g. attributes, may be optimized away by pointer identity optimization. # Note: functions in nested structures, e.g. attributes, may be optimized away by pointer identity optimization.
# This only compares a direct comparison and makes no claims about functions in nested structures. # This only compares a direct comparison and makes no claims about functions in nested structures.
assert assert (x: x) == (x: x);
(x: x)
==
(x: x);
abort "unreachable" abort "unreachable"

View file

@ -1,2 +1,6 @@
assert [ 1 0 ] == [ 10 ]; assert
[
1
0
] == [ 10 ];
throw "unreachable" throw "unreachable"

View file

@ -1,6 +1,3 @@
assert assert { a.b = [ { c.d = true; } ]; } == { a.b = [ { c.d = false; } ]; };
{ a.b = [ { c.d = true; } ]; }
==
{ a.b = [ { c.d = false; } ]; };
abort "unreachable" abort "unreachable"

View file

@ -1,5 +1,8 @@
let { let {
x = arg: assert arg == "y"; 123; x =
arg:
assert arg == "y";
123;
body = x "x"; body = x "x";
} }

View file

@ -1 +1,8 @@
{ a.b = 1; a = rec { c = d + 2; d = 3; }; }.c {
a.b = 1;
a = rec {
c = d + 2;
d = 3;
};
}
.c

View file

@ -1,6 +1,16 @@
let let
# Basically a "billion laughs" attack, but toned down to simulated `pkgs`. # Basically a "billion laughs" attack, but toned down to simulated `pkgs`.
ha = x: y: { a = x y; b = x y; c = x y; d = x y; e = x y; f = x y; g = x y; h = x y; j = x y; }; ha = x: y: {
a = x y;
b = x y;
c = x y;
d = x y;
e = x y;
f = x y;
g = x y;
h = x y;
j = x y;
};
has = ha (ha (ha (ha (x: x)))) "ha"; has = ha (ha (ha (ha (x: x)))) "ha";
# A large structure that has already been evaluated. # A large structure that has already been evaluated.
pkgs = builtins.deepSeq has has; pkgs = builtins.deepSeq has has;

View file

@ -1,4 +1,8 @@
{ {
set = { "${"" + "b"}" = 1; }; set = {
set = { "${"b" + ""}" = 2; }; "${"" + "b"}" = 1;
};
set = {
"${"b" + ""}" = 2;
};
} }

View file

@ -1,9 +1,6 @@
# Check that we only omit duplicate stack traces when there's a bunch of them. # Check that we only omit duplicate stack traces when there's a bunch of them.
# Here, there's only a couple duplicate entries, so we output them all. # Here, there's only a couple duplicate entries, so we output them all.
let let
throwAfter = n: throwAfter = n: if n > 0 then throwAfter (n - 1) else throw "Uh oh!";
if n > 0
then throwAfter (n - 1)
else throw "Uh oh!";
in in
throwAfter 2 throwAfter 2

View file

@ -1 +1,4 @@
builtins.fetchurl { url = "https://example.com/foo.tar.gz"; name = "~wobble~"; } builtins.fetchurl {
url = "https://example.com/foo.tar.gz";
name = "~wobble~";
}

View file

@ -1,7 +1,12 @@
let n = -1; in builtins.seq n (builtins.flakeRefToString { let
n = -1;
in
builtins.seq n (
builtins.flakeRefToString {
type = "github"; type = "github";
owner = "NixOS"; owner = "NixOS";
repo = n; repo = n;
ref = "23.05"; ref = "23.05";
dir = "lib"; dir = "lib";
}) }
)

View file

@ -1,5 +1,5 @@
# Tests that the result of applying op is forced even if the value is never used # Tests that the result of applying op is forced even if the value is never used
builtins.foldl' builtins.foldl' (_: f: f null) null [
(_: f: f null) (_: throw "Not the final value, but is still forced!")
null (_: 23)
[ (_: throw "Not the final value, but is still forced!") (_: 23) ] ]

View file

@ -1,5 +1,16 @@
let let
paths = [ ./this-file-is-definitely-not-there-7392097 "/and/neither/is/this/37293620" ]; paths = [
./this-file-is-definitely-not-there-7392097
"/and/neither/is/this/37293620"
];
in in
toString (builtins.concatLists (map (hash: map (builtins.hashFile hash) paths) ["md5" "sha1" "sha256" "sha512"])) toString (
builtins.concatLists (
map (hash: map (builtins.hashFile hash) paths) [
"md5"
"sha1"
"sha256"
"sha512"
]
)
)

View file

@ -1 +1,12 @@
({x, y, z}: x + y + z) {x = "foo"; z = "bar";} (
{
x,
y,
z,
}:
x + y + z
)
{
x = "foo";
z = "bar";
}

View file

@ -19,18 +19,22 @@
# - a few frames of A (skip the rest) # - a few frames of A (skip the rest)
# - a few frames of B (skip the rest, _and_ skip the remaining frames of A) # - a few frames of B (skip the rest, _and_ skip the remaining frames of A)
let let
throwAfterB = recurse: n: throwAfterB =
if n > 0 recurse: n:
then throwAfterB recurse (n - 1) if n > 0 then
else if recurse throwAfterB recurse (n - 1)
then throwAfterA false 10 else if recurse then
else throw "Uh oh!"; throwAfterA false 10
else
throw "Uh oh!";
throwAfterA = recurse: n: throwAfterA =
if n > 0 recurse: n:
then throwAfterA recurse (n - 1) if n > 0 then
else if recurse throwAfterA recurse (n - 1)
then throwAfterB true 10 else if recurse then
else throw "Uh oh!"; throwAfterB true 10
else
throw "Uh oh!";
in in
throwAfterA true 10 throwAfterA true 10

View file

@ -8,4 +8,27 @@
# #
# error: cannot coerce a list to a string: [ [ 1 2 3 4 5 6 7 8 ] [ 1 «4294967290 items elided» ] ] # error: cannot coerce a list to a string: [ [ 1 2 3 4 5 6 7 8 ] [ 1 «4294967290 items elided» ] ]
"" + (let v = [ [ 1 2 3 4 5 6 7 8 ] [1 2 3 4]]; in builtins.deepSeq v v) ""
+ (
let
v = [
[
1
2
3
4
5
6
7
8
]
[
1
2
3
4
]
];
in
builtins.deepSeq v v
)

Some files were not shown because too many files have changed in this diff Show more