diff --git a/default.nix b/default.nix
index 2cccff28d..6466507b7 100644
--- a/default.nix
+++ b/default.nix
@@ -1,10 +1,9 @@
-(import
- (
- let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
- fetchTarball {
- url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
- sha256 = lock.nodes.flake-compat.locked.narHash;
- }
- )
- { src = ./.; }
-).defaultNix
+(import (
+ let
+ lock = builtins.fromJSON (builtins.readFile ./flake.lock);
+ in
+ fetchTarball {
+ url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
+ sha256 = lock.nodes.flake-compat.locked.narHash;
+ }
+) { src = ./.; }).defaultNix
diff --git a/doc/manual/generate-builtin-constants.nix b/doc/manual/generate-builtin-constants.nix
index 8af80a02c..1035fcacc 100644
--- a/doc/manual/generate-builtin-constants.nix
+++ b/doc/manual/generate-builtin-constants.nix
@@ -2,10 +2,15 @@ let
inherit (builtins) concatStringsSep attrValues mapAttrs;
inherit (import ./utils.nix) optionalString squash;
in
-
builtinsInfo:
let
- showBuiltin = name: { doc, type, impure-only }:
+ showBuiltin =
+ name:
+ {
+ doc,
+ type,
+ impure-only,
+ }:
let
type' = optionalString (type != null) " (${type})";
diff --git a/doc/manual/generate-builtins.nix b/doc/manual/generate-builtins.nix
index 813a287f5..968fd3e2e 100644
--- a/doc/manual/generate-builtins.nix
+++ b/doc/manual/generate-builtins.nix
@@ -2,10 +2,16 @@ let
inherit (builtins) concatStringsSep attrValues mapAttrs;
inherit (import ./utils.nix) optionalString squash;
in
-
builtinsInfo:
let
- showBuiltin = name: { doc, args, arity, experimental-feature }:
+ showBuiltin =
+ name:
+ {
+ doc,
+ args,
+ arity,
+ experimental-feature,
+ }:
let
experimentalNotice = optionalString (experimental-feature != null) ''
This function is only available if the [${experimental-feature}](@docroot@/contributing/experimental-features.md#xp-feature-${experimental-feature}) experimental feature is enabled.
diff --git a/doc/manual/generate-manpage.nix b/doc/manual/generate-manpage.nix
index 972def69a..ce9c2a013 100644
--- a/doc/manual/generate-manpage.nix
+++ b/doc/manual/generate-manpage.nix
@@ -1,19 +1,39 @@
let
inherit (builtins)
- attrNames attrValues fromJSON listToAttrs mapAttrs
- concatStringsSep concatMap length lessThan replaceStrings sort;
- inherit (import ./utils.nix) concatStrings optionalString filterAttrs trim squash unique showSettings;
+ attrNames
+ attrValues
+ fromJSON
+ listToAttrs
+ mapAttrs
+ concatStringsSep
+ concatMap
+ length
+ lessThan
+ replaceStrings
+ sort
+ ;
+ inherit (import ./utils.nix)
+ concatStrings
+ optionalString
+ filterAttrs
+ trim
+ squash
+ unique
+ showSettings
+ ;
in
-
inlineHTML: commandDump:
-
let
-
commandInfo = fromJSON commandDump;
- showCommand = { command, details, filename, toplevel }:
+ showCommand =
+ {
+ command,
+ details,
+ filename,
+ toplevel,
+ }:
let
-
result = ''
> **Warning** \
> This program is
@@ -35,26 +55,27 @@ let
${maybeOptions}
'';
- showSynopsis = command: args:
+ showSynopsis =
+ command: args:
let
- showArgument = arg: "*${arg.label}*" + optionalString (! arg ? arity) "...";
+ showArgument = arg: "*${arg.label}*" + optionalString (!arg ? arity) "...";
arguments = concatStringsSep " " (map showArgument args);
- in ''
- `${command}` [*option*...] ${arguments}
+ in
+ ''
+ `${command}` [*option*...] ${arguments}
'';
- maybeSubcommands = optionalString (details ? commands && details.commands != {})
- ''
- where *subcommand* is one of the following:
+ maybeSubcommands = optionalString (details ? commands && details.commands != { }) ''
+ where *subcommand* is one of the following:
- ${subcommands}
- '';
+ ${subcommands}
+ '';
- subcommands = if length categories > 1
- then listCategories
- else listSubcommands details.commands;
+ subcommands = if length categories > 1 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);
@@ -71,11 +92,11 @@ let
'';
# TODO: move this confusing special case out of here when implementing #8496
- maybeStoreDocs = optionalString
- (details ? doc)
- (replaceStrings ["@stores@"] [storeDocs] details.doc);
+ maybeStoreDocs = optionalString (details ? doc) (
+ replaceStrings [ "@stores@" ] [ storeDocs ] details.doc
+ );
- maybeOptions = optionalString (details.flags != {}) ''
+ maybeOptions = optionalString (details.flags != { }) ''
# Options
${showOptions details.flags toplevel.flags}
@@ -85,51 +106,70 @@ let
> See [`man nix.conf`](@docroot@/command-ref/conf-file.md#command-line-flags) for overriding configuration settings with command line flags.
'';
- showOptions = options: commonOptions:
+ showOptions =
+ options: commonOptions:
let
allOptions = options // commonOptions;
showCategory = cat: ''
${optionalString (cat != "") "**${cat}:**"}
${listOptions (filterAttrs (n: v: v.category == cat) allOptions)}
- '';
+ '';
listOptions = opts: concatStringsSep "\n" (attrValues (mapAttrs showOption opts));
- showOption = name: option:
+ showOption =
+ name: option:
let
result = trim ''
- ${item}
${option.description}
'';
- item = if inlineHTML
- then ''[`--${name}`](#opt-${name}) ${shortName} ${labels}''
- else "`--${name}` ${shortName} ${labels}";
- shortName = optionalString
- (option ? shortName)
- ("/ `-${option.shortName}`");
- labels = optionalString
- (option ? labels)
- (concatStringsSep " " (map (s: "*${s}*") option.labels));
- in result;
+ item =
+ if inlineHTML then
+ ''[`--${name}`](#opt-${name}) ${shortName} ${labels}''
+ else
+ "`--${name}` ${shortName} ${labels}";
+ shortName = optionalString (option ? shortName) "/ `-${option.shortName}`";
+ labels = optionalString (option ? labels) (concatStringsSep " " (map (s: "*${s}*") option.labels));
+ in
+ result;
categories = sort lessThan (unique (map (cmd: cmd.category) (attrValues allOptions)));
- in concatStrings (map showCategory categories);
- in squash result;
+ in
+ concatStrings (map showCategory categories);
+ in
+ squash result;
appendName = filename: name: (if filename == "nix" then "nix3" else filename) + "-" + name;
- processCommand = { command, details, filename, toplevel }:
+ processCommand =
+ {
+ command,
+ details,
+ filename,
+ toplevel,
+ }:
let
cmd = {
inherit command;
name = filename + ".md";
- value = showCommand { inherit command details filename toplevel; };
+ value = showCommand {
+ inherit
+ command
+ details
+ filename
+ toplevel
+ ;
+ };
};
- subcommand = subCmd: processCommand {
- command = command + " " + subCmd;
- details = details.commands.${subCmd};
- filename = appendName filename subCmd;
- inherit toplevel;
- };
- in [ cmd ] ++ concatMap subcommand (attrNames details.commands or {});
+ subcommand =
+ subCmd:
+ processCommand {
+ command = command + " " + subCmd;
+ details = details.commands.${subCmd};
+ filename = appendName filename subCmd;
+ inherit toplevel;
+ };
+ in
+ [ cmd ] ++ concatMap subcommand (attrNames details.commands or { });
manpages = processCommand {
command = "nix";
@@ -138,14 +178,21 @@ let
toplevel = commandInfo.args;
};
- tableOfContents = let
- showEntry = page:
- " - [${page.command}](command-ref/new-cli/${page.name})";
- in concatStringsSep "\n" (map showEntry manpages) + "\n";
+ tableOfContents =
+ let
+ showEntry = page: " - [${page.command}](command-ref/new-cli/${page.name})";
+ in
+ concatStringsSep "\n" (map showEntry manpages) + "\n";
storeDocs =
let
- showStore = name: { settings, doc, experimentalFeature }:
+ showStore =
+ name:
+ {
+ settings,
+ doc,
+ experimentalFeature,
+ }:
let
experimentalFeatureNote = optionalString (experimentalFeature != null) ''
> **Warning**
@@ -161,7 +208,8 @@ let
extra-experimental-features = ${experimentalFeature}
```
'';
- in ''
+ in
+ ''
## ${name}
${doc}
@@ -172,6 +220,7 @@ let
${showSettings { inherit inlineHTML; } settings}
'';
- in concatStrings (attrValues (mapAttrs showStore commandInfo.stores));
-
-in (listToAttrs manpages) // { "SUMMARY.md" = tableOfContents; }
+ in
+ concatStrings (attrValues (mapAttrs showStore commandInfo.stores));
+in
+(listToAttrs manpages) // { "SUMMARY.md" = tableOfContents; }
diff --git a/doc/manual/generate-xp-features-shortlist.nix b/doc/manual/generate-xp-features-shortlist.nix
index 30e211c96..1cdc32ac0 100644
--- a/doc/manual/generate-xp-features-shortlist.nix
+++ b/doc/manual/generate-xp-features-shortlist.nix
@@ -1,9 +1,8 @@
with builtins;
with import ./utils.nix;
-
let
- showExperimentalFeature = name: doc:
- ''
- - [`${name}`](@docroot@/contributing/experimental-features.md#xp-feature-${name})
- '';
-in xps: indent " " (concatStrings (attrValues (mapAttrs showExperimentalFeature xps)))
+ showExperimentalFeature = name: doc: ''
+ - [`${name}`](@docroot@/contributing/experimental-features.md#xp-feature-${name})
+ '';
+in
+xps: indent " " (concatStrings (attrValues (mapAttrs showExperimentalFeature xps)))
diff --git a/doc/manual/generate-xp-features.nix b/doc/manual/generate-xp-features.nix
index adb94355c..353d82a03 100644
--- a/doc/manual/generate-xp-features.nix
+++ b/doc/manual/generate-xp-features.nix
@@ -1,11 +1,12 @@
with builtins;
with import ./utils.nix;
-
let
- showExperimentalFeature = name: doc:
+ showExperimentalFeature =
+ name: doc:
squash ''
## [`${name}`]{#xp-feature-${name}}
${doc}
'';
-in xps: (concatStringsSep "\n" (attrValues (mapAttrs showExperimentalFeature xps)))
+in
+xps: (concatStringsSep "\n" (attrValues (mapAttrs showExperimentalFeature xps)))
diff --git a/doc/manual/utils.nix b/doc/manual/utils.nix
index 193c1efc0..5f4b5dc7c 100644
--- a/doc/manual/utils.nix
+++ b/doc/manual/utils.nix
@@ -1,14 +1,18 @@
with builtins;
-
rec {
splitLines = s: filter (x: !isList x) (split "\n" s);
concatStrings = concatStringsSep "";
- attrsToList = a:
- map (name: { inherit name; value = a.${name}; }) (builtins.attrNames a);
+ attrsToList =
+ 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`
# example:
# replaceStringRec "--" "-" "hello-----world"
@@ -16,14 +20,16 @@ rec {
let
replaced = replaceStrings [ from ] [ to ] string;
in
- if replaced == string then string else replaceStringsRec from to replaced;
+ if replaced == string then string else replaceStringsRec from to replaced;
squash = replaceStringsRec "\n\n\n" "\n\n";
- trim = string:
+ trim =
+ string:
# trim trailing spaces and squash non-leading spaces
let
- trimLine = line:
+ trimLine =
+ line:
let
# separate leading spaces from the rest
parts = split "(^ *)" line;
@@ -31,76 +37,102 @@ rec {
rest = elemAt parts 2;
# drop trailing spaces
body = head (split " *$" rest);
- in spaces + replaceStringsRec " " " " body;
- in concatStringsSep "\n" (map trimLine (splitLines string));
+ in
+ spaces + replaceStringsRec " " " " body;
+ in
+ concatStringsSep "\n" (map trimLine (splitLines string));
# 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; };
- filterAttrs = pred: set:
- listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [(nameValuePair name v)] else []) (attrNames set));
+ filterAttrs =
+ 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 "";
- showSetting = { inlineHTML }: name: { description, documentDefault, defaultValue, aliases, value, experimentalFeature }:
+ showSetting =
+ { inlineHTML }:
+ name:
+ {
+ description,
+ documentDefault,
+ defaultValue,
+ aliases,
+ value,
+ experimentalFeature,
+ }:
let
result = squash ''
- - ${if inlineHTML
- then ''[`${name}`](#conf-${name})''
- else ''`${name}`''}
+ - ${
+ if inlineHTML then ''[`${name}`](#conf-${name})'' else ''`${name}`''
+ }
- ${indent " " body}
- '';
+ ${indent " " body}
+ '';
experimentalFeatureNote = optionalString (experimentalFeature != null) ''
- > **Warning**
- > This setting is part of an
- > [experimental feature](@docroot@/contributing/experimental-features.md).
+ > **Warning**
+ > This setting is part of an
+ > [experimental feature](@docroot@/contributing/experimental-features.md).
- To change this setting, you need to make sure the corresponding experimental feature,
- [`${experimentalFeature}`](@docroot@/contributing/experimental-features.md#xp-feature-${experimentalFeature}),
- is enabled.
- For example, include the following in [`nix.conf`](#):
+ To change this setting, you need to make sure the corresponding experimental feature,
+ [`${experimentalFeature}`](@docroot@/contributing/experimental-features.md#xp-feature-${experimentalFeature}),
+ is enabled.
+ For example, include the following in [`nix.conf`](#):
- ```
- extra-experimental-features = ${experimentalFeature}
- ${name} = ...
- ```
- '';
+ ```
+ extra-experimental-features = ${experimentalFeature}
+ ${name} = ...
+ ```
+ '';
# separate body to cleanly handle indentation
body = ''
- ${description}
+ ${description}
- ${experimentalFeatureNote}
+ ${experimentalFeatureNote}
- **Default:** ${showDefault documentDefault defaultValue}
+ **Default:** ${showDefault documentDefault defaultValue}
- ${showAliases aliases}
- '';
+ ${showAliases aliases}
+ '';
- showDefault = documentDefault: defaultValue:
+ showDefault =
+ documentDefault: defaultValue:
if documentDefault then
# a StringMap value type is specified as a string, but
# this shows the value type. The empty stringmap is `null` in
# JSON, but that converts to `{ }` here.
- if defaultValue == "" || defaultValue == [] || isAttrs defaultValue
- then "*empty*"
- else if isBool defaultValue then
- if defaultValue then "`true`" else "`false`"
- else "`${toString defaultValue}`"
- else "*machine-specific*";
+ if defaultValue == "" || defaultValue == [ ] || isAttrs defaultValue then
+ "*empty*"
+ else if isBool defaultValue then
+ if defaultValue then "`true`" else "`false`"
+ else
+ "`${toString defaultValue}`"
+ else
+ "*machine-specific*";
- showAliases = aliases:
- optionalString (aliases != [])
- "**Deprecated alias:** ${(concatStringsSep ", " (map (s: "`${s}`") aliases))}";
+ showAliases =
+ aliases:
+ optionalString (aliases != [ ])
+ "**Deprecated alias:** ${(concatStringsSep ", " (map (s: "`${s}`") aliases))}";
+ in
+ result;
- in result;
+ indent =
+ prefix: s: concatStringsSep "\n" (map (x: if x == "" then x else "${prefix}${x}") (splitLines s));
- indent = prefix: s:
- concatStringsSep "\n" (map (x: if x == "" then x else "${prefix}${x}") (splitLines s));
-
- showSettings = args: settingsInfo: concatStrings (attrValues (mapAttrs (showSetting args) settingsInfo));
+ showSettings =
+ args: settingsInfo: concatStrings (attrValues (mapAttrs (showSetting args) settingsInfo));
}
diff --git a/docker.nix b/docker.nix
index bd16b71cd..27f75f4d0 100644
--- a/docker.nix
+++ b/docker.nix
@@ -1,70 +1,70 @@
-{ pkgs ? import { }
-, lib ? pkgs.lib
-, name ? "nix"
-, tag ? "latest"
-, bundleNixpkgs ? true
-, channelName ? "nixpkgs"
-, channelURL ? "https://nixos.org/channels/nixpkgs-unstable"
-, extraPkgs ? []
-, maxLayers ? 100
-, nixConf ? {}
-, flake-registry ? null
+{
+ pkgs ? import { },
+ lib ? pkgs.lib,
+ name ? "nix",
+ tag ? "latest",
+ bundleNixpkgs ? true,
+ channelName ? "nixpkgs",
+ channelURL ? "https://nixos.org/channels/nixpkgs-unstable",
+ extraPkgs ? [ ],
+ maxLayers ? 100,
+ nixConf ? { },
+ flake-registry ? null,
}:
let
- defaultPkgs = with pkgs; [
- nix
- bashInteractive
- coreutils-full
- gnutar
- gzip
- gnugrep
- which
- curl
- less
- wget
- man
- cacert.out
- findutils
- iana-etc
- git
- openssh
- ] ++ extraPkgs;
+ defaultPkgs =
+ with pkgs;
+ [
+ nix
+ bashInteractive
+ coreutils-full
+ gnutar
+ gzip
+ gnugrep
+ which
+ curl
+ less
+ wget
+ man
+ cacert.out
+ findutils
+ iana-etc
+ git
+ openssh
+ ]
+ ++ extraPkgs;
- users = {
+ users =
+ {
+ root = {
+ uid = 0;
+ shell = "${pkgs.bashInteractive}/bin/bash";
+ home = "/root";
+ gid = 0;
+ groups = [ "root" ];
+ description = "System administrator";
+ };
- root = {
- uid = 0;
- shell = "${pkgs.bashInteractive}/bin/bash";
- home = "/root";
- gid = 0;
- groups = [ "root" ];
- description = "System administrator";
- };
-
- nobody = {
- uid = 65534;
- shell = "${pkgs.shadow}/bin/nologin";
- home = "/var/empty";
- gid = 65534;
- groups = [ "nobody" ];
- description = "Unprivileged account (don't use!)";
- };
-
- } // lib.listToAttrs (
- map
- (
- n: {
- name = "nixbld${toString n}";
- value = {
- uid = 30000 + n;
- gid = 30000;
- groups = [ "nixbld" ];
- description = "Nix build user ${toString n}";
- };
- }
- )
- (lib.lists.range 1 32)
- );
+ nobody = {
+ uid = 65534;
+ shell = "${pkgs.shadow}/bin/nologin";
+ home = "/var/empty";
+ gid = 65534;
+ groups = [ "nobody" ];
+ description = "Unprivileged account (don't use!)";
+ };
+ }
+ // lib.listToAttrs (
+ map (n: {
+ name = "nixbld${toString n}";
+ value = {
+ uid = 30000 + n;
+ gid = 30000;
+ groups = [ "nixbld" ];
+ description = "Nix build user ${toString n}";
+ };
+ }) (lib.lists.range 1 32)
+ );
groups = {
root.gid = 0;
@@ -74,24 +74,20 @@ let
userToPasswd = (
k:
- { uid
- , gid ? 65534
- , home ? "/var/empty"
- , description ? ""
- , shell ? "/bin/false"
- , groups ? [ ]
- }: "${k}:x:${toString uid}:${toString gid}:${description}:${home}:${shell}"
- );
- passwdContents = (
- lib.concatStringsSep "\n"
- (lib.attrValues (lib.mapAttrs userToPasswd users))
+ {
+ uid,
+ gid ? 65534,
+ home ? "/var/empty",
+ description ? "",
+ shell ? "/bin/false",
+ groups ? [ ],
+ }:
+ "${k}:x:${toString uid}:${toString gid}:${description}:${home}:${shell}"
);
+ passwdContents = (lib.concatStringsSep "\n" (lib.attrValues (lib.mapAttrs userToPasswd users)));
userToShadow = k: { ... }: "${k}:!:1::::::";
- shadowContents = (
- lib.concatStringsSep "\n"
- (lib.attrValues (lib.mapAttrs userToShadow users))
- );
+ shadowContents = (lib.concatStringsSep "\n" (lib.attrValues (lib.mapAttrs userToShadow users)));
# Map groups to members
# {
@@ -101,42 +97,28 @@ let
let
# Create a flat list of user/group mappings
mappings = (
- builtins.foldl'
- (
- acc: user:
- let
- groups = users.${user}.groups or [ ];
- in
- acc ++ map
- (group: {
- inherit user group;
- })
- groups
- )
- [ ]
- (lib.attrNames users)
+ builtins.foldl' (
+ acc: user:
+ let
+ groups = users.${user}.groups or [ ];
+ in
+ acc ++ map (group: { inherit user group; }) groups
+ ) [ ] (lib.attrNames users)
);
in
- (
- builtins.foldl'
- (
- acc: v: acc // {
- ${v.group} = acc.${v.group} or [ ] ++ [ v.user ];
- }
- )
- { }
- mappings)
+ (builtins.foldl' (
+ acc: v: acc // { ${v.group} = acc.${v.group} or [ ] ++ [ v.user ]; }
+ ) { } mappings)
);
- groupToGroup = k: { gid }:
+ groupToGroup =
+ k:
+ { gid }:
let
members = groupMemberMap.${k} or [ ];
in
"${k}:x:${toString gid}:${lib.concatStringsSep "," members}";
- groupContents = (
- lib.concatStringsSep "\n"
- (lib.attrValues (lib.mapAttrs groupToGroup groups))
- );
+ groupContents = (lib.concatStringsSep "\n" (lib.attrValues (lib.mapAttrs groupToGroup groups)));
defaultNixConf = {
sandbox = "false";
@@ -144,11 +126,17 @@ let
trusted-public-keys = [ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" ];
};
- nixConfContents = (lib.concatStringsSep "\n" (lib.mapAttrsFlatten (n: v:
- let
- vStr = if builtins.isList v then lib.concatStringsSep " " v else v;
- in
- "${n} = ${vStr}") (defaultNixConf // nixConf))) + "\n";
+ nixConfContents =
+ (lib.concatStringsSep "\n" (
+ lib.mapAttrsFlatten (
+ n: v:
+ let
+ vStr = if builtins.isList v then lib.concatStringsSep " " v else v;
+ in
+ "${n} = ${vStr}"
+ ) (defaultNixConf // nixConf)
+ ))
+ + "\n";
baseSystem =
let
@@ -167,21 +155,31 @@ let
manifest = pkgs.buildPackages.runCommand "manifest.nix" { } ''
cat > $out < $out/etc/passwd
- echo "" >> $out/etc/passwd
+ cat $passwdContentsPath > $out/etc/passwd
+ echo "" >> $out/etc/passwd
- cat $groupContentsPath > $out/etc/group
- echo "" >> $out/etc/group
+ cat $groupContentsPath > $out/etc/group
+ echo "" >> $out/etc/group
- cat $shadowContentsPath > $out/etc/shadow
- echo "" >> $out/etc/shadow
+ cat $shadowContentsPath > $out/etc/shadow
+ echo "" >> $out/etc/shadow
- mkdir -p $out/usr
- ln -s /nix/var/nix/profiles/share $out/usr/
+ mkdir -p $out/usr
+ ln -s /nix/var/nix/profiles/share $out/usr/
- mkdir -p $out/nix/var/nix/gcroots
+ mkdir -p $out/nix/var/nix/gcroots
- mkdir $out/tmp
+ mkdir $out/tmp
- mkdir -p $out/var/tmp
+ mkdir -p $out/var/tmp
- mkdir -p $out/etc/nix
- cat $nixConfContentsPath > $out/etc/nix/nix.conf
+ mkdir -p $out/etc/nix
+ cat $nixConfContentsPath > $out/etc/nix/nix.conf
- mkdir -p $out/root
- mkdir -p $out/nix/var/nix/profiles/per-user/root
+ mkdir -p $out/root
+ mkdir -p $out/nix/var/nix/profiles/per-user/root
- ln -s ${profile} $out/nix/var/nix/profiles/default-1-link
- ln -s $out/nix/var/nix/profiles/default-1-link $out/nix/var/nix/profiles/default
- ln -s /nix/var/nix/profiles/default $out/root/.nix-profile
+ ln -s ${profile} $out/nix/var/nix/profiles/default-1-link
+ ln -s $out/nix/var/nix/profiles/default-1-link $out/nix/var/nix/profiles/default
+ ln -s /nix/var/nix/profiles/default $out/root/.nix-profile
- ln -s ${channel} $out/nix/var/nix/profiles/per-user/root/channels-1-link
- ln -s $out/nix/var/nix/profiles/per-user/root/channels-1-link $out/nix/var/nix/profiles/per-user/root/channels
+ ln -s ${channel} $out/nix/var/nix/profiles/per-user/root/channels-1-link
+ ln -s $out/nix/var/nix/profiles/per-user/root/channels-1-link $out/nix/var/nix/profiles/per-user/root/channels
- mkdir -p $out/root/.nix-defexpr
- ln -s $out/nix/var/nix/profiles/per-user/root/channels $out/root/.nix-defexpr/channels
- echo "${channelURL} ${channelName}" > $out/root/.nix-channels
+ mkdir -p $out/root/.nix-defexpr
+ ln -s $out/nix/var/nix/profiles/per-user/root/channels $out/root/.nix-defexpr/channels
+ echo "${channelURL} ${channelName}" > $out/root/.nix-channels
- mkdir -p $out/bin $out/usr/bin
- ln -s ${pkgs.coreutils}/bin/env $out/usr/bin/env
- ln -s ${pkgs.bashInteractive}/bin/bash $out/bin/sh
-
- '' + (lib.optionalString (flake-registry-path != null) ''
- nixCacheDir="/root/.cache/nix"
- mkdir -p $out$nixCacheDir
- globalFlakeRegistryPath="$nixCacheDir/flake-registry.json"
- ln -s ${flake-registry-path} $out$globalFlakeRegistryPath
- 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))
- ln -s $globalFlakeRegistryPath $out/nix/var/nix/gcroots/auto/$rootName
- ''));
+ mkdir -p $out/bin $out/usr/bin
+ ln -s ${pkgs.coreutils}/bin/env $out/usr/bin/env
+ ln -s ${pkgs.bashInteractive}/bin/bash $out/bin/sh
+ ''
+ + (lib.optionalString (flake-registry-path != null) ''
+ nixCacheDir="/root/.cache/nix"
+ mkdir -p $out$nixCacheDir
+ globalFlakeRegistryPath="$nixCacheDir/flake-registry.json"
+ ln -s ${flake-registry-path} $out$globalFlakeRegistryPath
+ 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))
+ ln -s $globalFlakeRegistryPath $out/nix/var/nix/gcroots/auto/$rootName
+ '')
+ );
in
pkgs.dockerTools.buildLayeredImageWithNixDb {
-
inherit name tag maxLayers;
contents = [ baseSystem ];
@@ -285,20 +291,23 @@ pkgs.dockerTools.buildLayeredImageWithNixDb {
Cmd = [ "/root/.nix-profile/bin/bash" ];
Env = [
"USER=root"
- "PATH=${lib.concatStringsSep ":" [
- "/root/.nix-profile/bin"
- "/nix/var/nix/profiles/default/bin"
- "/nix/var/nix/profiles/default/sbin"
- ]}"
- "MANPATH=${lib.concatStringsSep ":" [
- "/root/.nix-profile/share/man"
- "/nix/var/nix/profiles/default/share/man"
- ]}"
+ "PATH=${
+ lib.concatStringsSep ":" [
+ "/root/.nix-profile/bin"
+ "/nix/var/nix/profiles/default/bin"
+ "/nix/var/nix/profiles/default/sbin"
+ ]
+ }"
+ "MANPATH=${
+ lib.concatStringsSep ":" [
+ "/root/.nix-profile/share/man"
+ "/nix/var/nix/profiles/default/share/man"
+ ]
+ }"
"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"
"NIX_SSL_CERT_FILE=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt"
"NIX_PATH=/nix/var/nix/profiles/per-user/root/channels:/root/.nix-defexpr/channels"
];
};
-
}
diff --git a/flake.nix b/flake.nix
index f22ccde11..92583e49f 100644
--- a/flake.nix
+++ b/flake.nix
@@ -14,11 +14,20 @@
nixpkgs-stable.follows = "nixpkgs";
};
};
- flake-compat = { url = "github:edolstra/flake-compat"; flake = false; };
+ flake-compat = {
+ url = "github:edolstra/flake-compat";
+ flake = false;
+ };
};
- outputs = { self, nixpkgs, nixpkgs-regression, pre-commit-hooks, flake-compat }:
-
+ outputs =
+ {
+ self,
+ nixpkgs,
+ nixpkgs-regression,
+ pre-commit-hooks,
+ flake-compat,
+ }:
let
inherit (nixpkgs) lib;
inherit (lib) fileset;
@@ -30,105 +39,137 @@
version = lib.fileContents ./.version + versionSuffix;
versionSuffix =
- if officialRelease
- then ""
- else "pre${builtins.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}_${self.shortRev or "dirty"}";
+ if officialRelease then
+ ""
+ else
+ "pre${
+ builtins.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")
+ }_${self.shortRev or "dirty"}";
linux32BitSystems = [ "i686-linux" ];
- linux64BitSystems = [ "x86_64-linux" "aarch64-linux" ];
+ linux64BitSystems = [
+ "x86_64-linux"
+ "aarch64-linux"
+ ];
linuxSystems = linux32BitSystems ++ linux64BitSystems;
- darwinSystems = [ "x86_64-darwin" "aarch64-darwin" ];
+ darwinSystems = [
+ "x86_64-darwin"
+ "aarch64-darwin"
+ ];
systems = linuxSystems ++ darwinSystems;
crossSystems = [
- "armv6l-linux" "armv7l-linux"
- "x86_64-freebsd13" "x86_64-netbsd"
+ "armv6l-linux"
+ "armv7l-linux"
+ "x86_64-freebsd13"
+ "x86_64-netbsd"
];
- stdenvs = [ "gccStdenv" "clangStdenv" "stdenv" "libcxxStdenv" "ccacheStdenv" ];
+ stdenvs = [
+ "gccStdenv"
+ "clangStdenv"
+ "stdenv"
+ "libcxxStdenv"
+ "ccacheStdenv"
+ ];
forAllSystems = lib.genAttrs systems;
forAllCrossSystems = lib.genAttrs crossSystems;
- forAllStdenvs = f:
- lib.listToAttrs
- (map
- (stdenvName: {
- name = "${stdenvName}Packages";
- value = f stdenvName;
- })
- stdenvs);
+ forAllStdenvs =
+ f:
+ lib.listToAttrs (
+ map (stdenvName: {
+ name = "${stdenvName}Packages";
+ value = f stdenvName;
+ }) stdenvs
+ );
# Memoize nixpkgs for different platforms for efficiency.
- nixpkgsFor = forAllSystems
- (system: let
- make-pkgs = crossSystem: stdenv: import nixpkgs {
- localSystem = {
- inherit system;
- };
- crossSystem = if crossSystem == null then null else {
- system = crossSystem;
- } // lib.optionalAttrs (crossSystem == "x86_64-freebsd13") {
- useLLVM = true;
- };
- overlays = [
- (overlayFor (p: p.${stdenv}))
- ];
+ nixpkgsFor = forAllSystems (
+ system:
+ let
+ make-pkgs =
+ crossSystem: stdenv:
+ import nixpkgs {
+ localSystem = {
+ inherit system;
+ };
+ crossSystem =
+ if crossSystem == null then
+ null
+ else
+ {
+ system = crossSystem;
+ }
+ // lib.optionalAttrs (crossSystem == "x86_64-freebsd13") { useLLVM = true; };
+ overlays = [
+ (overlayFor (p: p.${stdenv}))
+ (final: prev: { nixfmt = final.callPackage ./nix-support/nixfmt.nix { }; })
+ ];
- config.permittedInsecurePackages = [ "nix-2.13.6" ];
- };
+ config.permittedInsecurePackages = [ "nix-2.13.6" ];
+ };
stdenvs = forAllStdenvs (make-pkgs null);
native = stdenvs.stdenvPackages;
- in {
+ in
+ {
inherit stdenvs native;
static = native.pkgsStatic;
cross = forAllCrossSystems (crossSystem: make-pkgs crossSystem "stdenv");
- });
+ }
+ );
- testNixVersions = pkgs: client: daemon: let
- nix = pkgs.callPackage ./package.nix {
- pname =
- "nix-tests"
- + lib.optionalString
- (lib.versionAtLeast daemon.version "2.4pre20211005" &&
- lib.versionAtLeast client.version "2.4pre20211005")
- "-${client.version}-against-${daemon.version}";
+ testNixVersions =
+ pkgs: client: daemon:
+ let
+ nix = pkgs.callPackage ./package.nix {
+ pname =
+ "nix-tests"
+ + lib.optionalString (
+ lib.versionAtLeast daemon.version "2.4pre20211005"
+ && lib.versionAtLeast client.version "2.4pre20211005"
+ ) "-${client.version}-against-${daemon.version}";
inherit fileset;
- };
- in nix.overrideAttrs (prevAttrs: {
- NIX_DAEMON_PACKAGE = daemon;
- NIX_CLIENT_PACKAGE = client;
+ };
+ in
+ nix.overrideAttrs (prevAttrs: {
+ NIX_DAEMON_PACKAGE = daemon;
+ NIX_CLIENT_PACKAGE = client;
- dontBuild = true;
- doInstallCheck = true;
+ dontBuild = true;
+ doInstallCheck = true;
- configureFlags = prevAttrs.configureFlags ++ [
- # We don't need the actual build here.
- "--disable-build"
- ];
+ configureFlags = prevAttrs.configureFlags ++ [
+ # We don't need the actual build here.
+ "--disable-build"
+ ];
- installPhase = ''
- mkdir -p $out
- '';
+ installPhase = ''
+ mkdir -p $out
+ '';
- installCheckPhase = lib.optionalString pkgs.stdenv.hostPlatform.isDarwin ''
- export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
- '' + ''
- mkdir -p src/nix-channel
- make installcheck -j$NIX_BUILD_CORES -l$NIX_BUILD_CORES
- '';
- });
+ installCheckPhase =
+ lib.optionalString pkgs.stdenv.hostPlatform.isDarwin ''
+ export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
+ ''
+ + ''
+ mkdir -p src/nix-channel
+ make installcheck -j$NIX_BUILD_CORES -l$NIX_BUILD_CORES
+ '';
+ });
- binaryTarball = nix: pkgs:
+ binaryTarball =
+ nix: pkgs:
let
inherit (pkgs) buildPackages;
installerClosureInfo = buildPackages.closureInfo { rootPaths = [ nix ]; };
in
-
buildPackages.runCommand "nix-binary-tarball-${version}"
- { #nativeBuildInputs = lib.optional (system != "aarch64-linux") shellcheck;
+ {
+ #nativeBuildInputs = lib.optional (system != "aarch64-linux") shellcheck;
meta.description = "Distribution-independent Nix bootstrap binaries for ${pkgs.system}";
}
''
@@ -149,25 +190,26 @@
$(cat ${installerClosureInfo}/store-paths)
'';
- overlayFor = getStdenv: final: prev:
+ overlayFor =
+ getStdenv: final: prev:
let
currentStdenv = getStdenv final;
- comDeps = with final; commonDeps {
- inherit pkgs;
- inherit (currentStdenv.hostPlatform) isStatic;
- };
- in {
+ comDeps =
+ with final;
+ commonDeps {
+ inherit pkgs;
+ inherit (currentStdenv.hostPlatform) isStatic;
+ };
+ in
+ {
nixStable = prev.nix;
# Forward from the previous stage as we don’t want it to pick the lowdown override
nixUnstable = prev.nixUnstable;
- build-release-notes =
- final.buildPackages.callPackage ./maintainers/build-release-notes.nix { };
+ build-release-notes = final.buildPackages.callPackage ./maintainers/build-release-notes.nix { };
clangbuildanalyzer = final.buildPackages.callPackage ./misc/clangbuildanalyzer.nix { };
- boehmgc-nix = (final.boehmgc.override {
- enableLargeConfig = true;
- }).overrideAttrs (o: {
+ boehmgc-nix = (final.boehmgc.override { enableLargeConfig = true; }).overrideAttrs (o: {
patches = (o.patches or [ ]) ++ [
./boehmgc-coroutine-sp-fallback.diff
@@ -207,57 +249,65 @@
busybox-sandbox-shell = final.busybox-sandbox-shell or final.default-busybox-sandbox-shell;
};
};
-
- in {
+ in
+ {
# A Nixpkgs overlay that overrides the 'nix' and
# 'nix.perl-bindings' packages.
overlays.default = overlayFor (p: p.stdenv);
hydraJobs = {
-
# Binary package for various platforms.
build = forAllSystems (system: self.packages.${system}.nix);
# FIXME(Qyriad): remove this when the migration to Meson has been completed.
# NOTE: mesonBuildClang depends on mesonBuild depends on build to avoid OOMs
# on aarch64 builders caused by too many parallel compiler/linker processes.
- mesonBuild = forAllSystems (system:
- (self.packages.${system}.nix.override {
- buildWithMeson = true;
- }).overrideAttrs (prev: {
+ mesonBuild = forAllSystems (
+ system:
+ (self.packages.${system}.nix.override { buildWithMeson = true; }).overrideAttrs (prev: {
buildInputs = prev.buildInputs ++ [ self.packages.${system}.nix ];
- }));
- mesonBuildClang = forAllSystems (system:
- (nixpkgsFor.${system}.stdenvs.clangStdenvPackages.nix.override {
- buildWithMeson = true;
- }).overrideAttrs (prev: {
- buildInputs = prev.buildInputs ++ [ self.hydraJobs.mesonBuild.${system} ];
})
);
+ mesonBuildClang = forAllSystems (
+ system:
+ (nixpkgsFor.${system}.stdenvs.clangStdenvPackages.nix.override { buildWithMeson = true; })
+ .overrideAttrs
+ (prev: {
+ buildInputs = prev.buildInputs ++ [ self.hydraJobs.mesonBuild.${system} ];
+ })
+ );
# Perl bindings for various platforms.
perlBindings = forAllSystems (system: nixpkgsFor.${system}.native.nix.perl-bindings);
# Binary tarball for various platforms, containing a Nix store
# with the closure of 'nix' package.
- binaryTarball = forAllSystems (system: binaryTarball nixpkgsFor.${system}.native.nix nixpkgsFor.${system}.native);
+ binaryTarball = forAllSystems (
+ system: binaryTarball nixpkgsFor.${system}.native.nix nixpkgsFor.${system}.native
+ );
# docker image with Nix inside
dockerImage = lib.genAttrs linux64BitSystems (system: self.packages.${system}.dockerImage);
# API docs for Nix's unstable internal C++ interfaces.
- internal-api-docs = let
- nixpkgs = nixpkgsFor.x86_64-linux.native;
- inherit (nixpkgs) pkgs;
+ internal-api-docs =
+ let
+ nixpkgs = nixpkgsFor.x86_64-linux.native;
+ inherit (nixpkgs) pkgs;
- nix = pkgs.callPackage ./package.nix {
- inherit versionSuffix fileset officialRelease buildUnreleasedNotes;
- inherit (pkgs) build-release-notes;
- internalApiDocs = true;
- boehmgc = pkgs.boehmgc-nix;
- busybox-sandbox-shell = pkgs.busybox-sandbox-shell;
- };
- in
+ nix = pkgs.callPackage ./package.nix {
+ inherit
+ versionSuffix
+ fileset
+ officialRelease
+ buildUnreleasedNotes
+ ;
+ inherit (pkgs) build-release-notes;
+ internalApiDocs = true;
+ boehmgc = pkgs.boehmgc-nix;
+ busybox-sandbox-shell = pkgs.busybox-sandbox-shell;
+ };
+ in
nix.overrideAttrs (prev: {
# This Hydra job is just for the internal API docs.
# We don't need the build artifacts here.
@@ -268,199 +318,248 @@
# System tests.
tests = import ./tests/nixos { inherit lib nixpkgs nixpkgsFor; } // {
-
# Make sure that nix-env still produces the exact same result
# on a particular version of Nixpkgs.
evalNixpkgs =
with nixpkgsFor.x86_64-linux.native;
- runCommand "eval-nixos" { buildInputs = [ nix ]; }
- ''
- type -p nix-env
- # Note: we're filtering out nixos-install-tools because https://github.com/NixOS/nixpkgs/pull/153594#issuecomment-1020530593.
- time nix-env --store dummy:// -f ${nixpkgs-regression} -qaP --drv-path | sort | grep -v nixos-install-tools > packages
- [[ $(sha1sum < packages | cut -c1-40) = 402242fca90874112b34718b8199d844e8b03d12 ]]
- mkdir $out
- '';
+ runCommand "eval-nixos" { buildInputs = [ nix ]; } ''
+ type -p nix-env
+ # Note: we're filtering out nixos-install-tools because https://github.com/NixOS/nixpkgs/pull/153594#issuecomment-1020530593.
+ time nix-env --store dummy:// -f ${nixpkgs-regression} -qaP --drv-path | sort | grep -v nixos-install-tools > packages
+ [[ $(sha1sum < packages | cut -c1-40) = 402242fca90874112b34718b8199d844e8b03d12 ]]
+ mkdir $out
+ '';
- nixpkgsLibTests =
- forAllSystems (system:
- import (nixpkgs + "/lib/tests/release.nix")
- { pkgs = nixpkgsFor.${system}.native;
- nixVersions = [ self.packages.${system}.nix ];
- }
- );
+ nixpkgsLibTests = forAllSystems (
+ system:
+ import (nixpkgs + "/lib/tests/release.nix") {
+ pkgs = nixpkgsFor.${system}.native;
+ nixVersions = [ self.packages.${system}.nix ];
+ }
+ );
};
- pre-commit = builtins.mapAttrs (system: pre-commit-lib: pre-commit-lib.run {
- src = self;
- hooks = {
- no-commit-to-branch = {
- enable = true;
- settings.branch = ["main"];
+ pre-commit = builtins.mapAttrs (
+ system: pre-commit-lib:
+ pre-commit-lib.run {
+ src = self;
+ hooks = {
+ no-commit-to-branch = {
+ enable = true;
+ settings.branch = [ "main" ];
+ };
+ check-case-conflicts.enable = true;
+ check-executables-have-shebangs = {
+ enable = true;
+ stages = [ "commit" ];
+ };
+ check-shebang-scripts-are-executable = {
+ enable = true;
+ stages = [ "commit" ];
+ };
+ check-symlinks = {
+ enable = true;
+ excludes = [ "^tests/functional/lang/symlink-resolution/broken$" ];
+ };
+ check-merge-conflicts.enable = true;
+ end-of-file-fixer = {
+ enable = true;
+ excludes = [
+ "\\.drv$"
+ "^tests/functional/lang/"
+ ];
+ };
+ mixed-line-endings = {
+ enable = true;
+ excludes = [ "^tests/functional/lang/" ];
+ };
+ # TODO: Once the test suite is nicer, clean up and start
+ # enforcing trailing whitespace on tests that don't explicitly
+ # check for it.
+ trim-trailing-whitespace = {
+ enable = true;
+ stages = [ "commit" ];
+ excludes = [ "^tests/functional/lang/" ];
+ };
+ treefmt = {
+ enable = true;
+ settings.formatters =
+ let
+ pkgs = nixpkgsFor.${system}.native;
+ in
+ [ pkgs.nixfmt ];
+ };
};
- check-case-conflicts.enable = true;
- check-executables-have-shebangs = {
- enable = true;
- stages = [ "commit" ];
- };
- check-shebang-scripts-are-executable = {
- enable = true;
- stages = [ "commit" ];
- };
- check-symlinks = {
- enable = true;
- excludes = [ "^tests/functional/lang/symlink-resolution/broken$" ];
- };
- check-merge-conflicts.enable = true;
- end-of-file-fixer = {
- enable = true;
- excludes = [
- "\\.drv$"
- "^tests/functional/lang/"
- ];
- };
- mixed-line-endings = {
- enable = true;
- excludes = [ "^tests/functional/lang/" ];
- };
- # TODO: Once the test suite is nicer, clean up and start
- # enforcing trailing whitespace on tests that don't explicitly
- # check for it.
- trim-trailing-whitespace = {
- enable = true;
- stages = [ "commit" ];
- excludes = [ "^tests/functional/lang/" ];
- };
- treefmt = {
- enable = true;
- settings.formatters = [ ];
- };
- };
- }) pre-commit-hooks.lib;
+ }
+ ) pre-commit-hooks.lib;
};
- checks = forAllSystems (system: let
- rl-next-check = name: dir:
- let pkgs = nixpkgsFor.${system}.native;
- in pkgs.buildPackages.runCommand "test-${name}-release-notes" { } ''
- LANG=C.UTF-8 ${lib.getExe pkgs.build-release-notes} ${dir} >$out
- '';
- in {
- # FIXME(Qyriad): remove this when the migration to Meson has been completed.
- mesonBuild = self.hydraJobs.mesonBuild.${system};
- mesonBuildClang = self.hydraJobs.mesonBuildClang.${system};
- binaryTarball = self.hydraJobs.binaryTarball.${system};
- perlBindings = self.hydraJobs.perlBindings.${system};
- nixpkgsLibTests = self.hydraJobs.tests.nixpkgsLibTests.${system};
- rl-next = rl-next-check "rl-next" ./doc/manual/rl-next;
- rl-next-dev = rl-next-check "rl-next-dev" ./doc/manual/rl-next-dev;
- pre-commit = self.hydraJobs.pre-commit.${system};
- } // (lib.optionalAttrs (builtins.elem system linux64BitSystems)) {
- dockerImage = self.hydraJobs.dockerImage.${system};
- });
-
- packages = forAllSystems (system: rec {
- inherit (nixpkgsFor.${system}.native) nix;
- default = nix;
- } // (lib.optionalAttrs (builtins.elem system linux64BitSystems) {
- nix-static = nixpkgsFor.${system}.static.nix;
- dockerImage =
- let
- pkgs = nixpkgsFor.${system}.native;
- image = import ./docker.nix { inherit pkgs; tag = version; };
- in
- pkgs.runCommand
- "docker-image-tarball-${version}"
- { meta.description = "Docker image with Nix for ${system}"; }
- ''
- mkdir -p $out/nix-support
- image=$out/image.tar.gz
- ln -s ${image} $image
- echo "file binary-dist $image" >> $out/nix-support/hydra-build-products
+ checks = forAllSystems (
+ system:
+ let
+ rl-next-check =
+ name: dir:
+ let
+ pkgs = nixpkgsFor.${system}.native;
+ in
+ pkgs.buildPackages.runCommand "test-${name}-release-notes" { } ''
+ LANG=C.UTF-8 ${lib.getExe pkgs.build-release-notes} ${dir} >$out
'';
- } // builtins.listToAttrs (map
- (crossSystem: {
- name = "nix-${crossSystem}";
- value = nixpkgsFor.${system}.cross.${crossSystem}.nix;
- })
- crossSystems)
- // builtins.listToAttrs (map
- (stdenvName: {
- name = "nix-${stdenvName}";
- value = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages".nix;
- })
- stdenvs)));
+ in
+ {
+ # FIXME(Qyriad): remove this when the migration to Meson has been completed.
+ mesonBuild = self.hydraJobs.mesonBuild.${system};
+ mesonBuildClang = self.hydraJobs.mesonBuildClang.${system};
+ binaryTarball = self.hydraJobs.binaryTarball.${system};
+ perlBindings = self.hydraJobs.perlBindings.${system};
+ nixpkgsLibTests = self.hydraJobs.tests.nixpkgsLibTests.${system};
+ rl-next = rl-next-check "rl-next" ./doc/manual/rl-next;
+ rl-next-dev = rl-next-check "rl-next-dev" ./doc/manual/rl-next-dev;
+ pre-commit = self.hydraJobs.pre-commit.${system};
+ }
+ // (lib.optionalAttrs (builtins.elem system linux64BitSystems)) {
+ dockerImage = self.hydraJobs.dockerImage.${system};
+ }
+ );
- devShells = let
- makeShell = pkgs: stdenv:
- let
- nix = pkgs.callPackage ./package.nix {
- inherit stdenv versionSuffix fileset;
- boehmgc = pkgs.boehmgc-nix;
- busybox-sandbox-shell = pkgs.busybox-sandbox-shell or pkgs.default-busybox-sandbox;
- forDevShell = true;
- };
- pre-commit = self.hydraJobs.pre-commit.${pkgs.system} or {};
- in
+ packages = forAllSystems (
+ system:
+ rec {
+ inherit (nixpkgsFor.${system}.native) nix;
+ default = nix;
+ }
+ // (
+ lib.optionalAttrs (builtins.elem system linux64BitSystems) {
+ nix-static = nixpkgsFor.${system}.static.nix;
+ dockerImage =
+ let
+ pkgs = nixpkgsFor.${system}.native;
+ image = import ./docker.nix {
+ inherit pkgs;
+ tag = version;
+ };
+ in
+ pkgs.runCommand "docker-image-tarball-${version}"
+ { meta.description = "Docker image with Nix for ${system}"; }
+ ''
+ mkdir -p $out/nix-support
+ image=$out/image.tar.gz
+ ln -s ${image} $image
+ echo "file binary-dist $image" >> $out/nix-support/hydra-build-products
+ '';
+ }
+ // builtins.listToAttrs (
+ map (crossSystem: {
+ name = "nix-${crossSystem}";
+ value = nixpkgsFor.${system}.cross.${crossSystem}.nix;
+ }) crossSystems
+ )
+ // builtins.listToAttrs (
+ map (stdenvName: {
+ name = "nix-${stdenvName}";
+ value = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages".nix;
+ }) stdenvs
+ )
+ )
+ );
+
+ devShells =
+ let
+ makeShell =
+ pkgs: stdenv:
+ let
+ nix = pkgs.callPackage ./package.nix {
+ inherit stdenv versionSuffix fileset;
+ boehmgc = pkgs.boehmgc-nix;
+ busybox-sandbox-shell = pkgs.busybox-sandbox-shell or pkgs.default-busybox-sandbox;
+ forDevShell = true;
+ };
+ pre-commit = self.hydraJobs.pre-commit.${pkgs.system} or { };
+ in
(nix.override {
buildUnreleasedNotes = true;
officialRelease = false;
- }).overrideAttrs (prev: {
- # Required for clang-tidy checks
- buildInputs = prev.buildInputs
- ++ lib.optional (pre-commit ? enabledPackages) pre-commit.enabledPackages
- ++ lib.optionals (stdenv.cc.isClang) [ pkgs.llvmPackages.llvm pkgs.llvmPackages.clang-unwrapped.dev ];
- nativeBuildInputs = prev.nativeBuildInputs
- ++ lib.optional (stdenv.cc.isClang && !stdenv.buildPlatform.isDarwin) pkgs.buildPackages.bear
- # Required for clang-tidy checks
- ++ lib.optionals (stdenv.cc.isClang) [ pkgs.buildPackages.cmake pkgs.buildPackages.ninja pkgs.buildPackages.llvmPackages.llvm.dev ]
- ++ lib.optional
- (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform)
- # for some reason that seems accidental and was changed in
- # NixOS 24.05-pre, clang-tools is pinned to LLVM 14 when
- # default LLVM is newer.
- (pkgs.buildPackages.clang-tools.override { inherit (pkgs.buildPackages) llvmPackages; })
- ++ [
- # FIXME(Qyriad): remove once the migration to Meson is complete.
- pkgs.buildPackages.meson
- pkgs.buildPackages.ninja
+ }).overrideAttrs
+ (
+ prev:
+ {
+ # Required for clang-tidy checks
+ buildInputs =
+ prev.buildInputs
+ ++ lib.optional (pre-commit ? enabledPackages) pre-commit.enabledPackages
+ # Unfortunately `git-hooks.nix` can't propagate `treefmt`
+ # formatters into `enabledPackages` correctly.
+ ++ [ pkgs.nixfmt ]
+ ++ lib.optionals (stdenv.cc.isClang) [
+ pkgs.llvmPackages.llvm
+ pkgs.llvmPackages.clang-unwrapped.dev
+ ];
+ nativeBuildInputs =
+ prev.nativeBuildInputs
+ ++ lib.optional (stdenv.cc.isClang && !stdenv.buildPlatform.isDarwin) pkgs.buildPackages.bear
+ # Required for clang-tidy checks
+ ++ lib.optionals (stdenv.cc.isClang) [
+ pkgs.buildPackages.cmake
+ pkgs.buildPackages.ninja
+ pkgs.buildPackages.llvmPackages.llvm.dev
+ ]
+ ++
+ lib.optional (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform)
+ # for some reason that seems accidental and was changed in
+ # NixOS 24.05-pre, clang-tools is pinned to LLVM 14 when
+ # default LLVM is newer.
+ (pkgs.buildPackages.clang-tools.override { inherit (pkgs.buildPackages) llvmPackages; })
+ ++ [
+ # FIXME(Qyriad): remove once the migration to Meson is complete.
+ pkgs.buildPackages.meson
+ pkgs.buildPackages.ninja
- pkgs.buildPackages.clangbuildanalyzer
- ];
+ pkgs.buildPackages.clangbuildanalyzer
+ ];
- src = null;
+ src = null;
- installFlags = "sysconfdir=$(out)/etc";
- strictDeps = false;
+ installFlags = "sysconfdir=$(out)/etc";
+ strictDeps = false;
- shellHook = ''
- PATH=$prefix/bin:$PATH
- unset PYTHONPATH
- export MANPATH=$out/share/man:$MANPATH
+ shellHook = ''
+ PATH=$prefix/bin:$PATH
+ unset PYTHONPATH
+ export MANPATH=$out/share/man:$MANPATH
- # Make bash completion work.
- XDG_DATA_DIRS+=:$out/share
+ # Make bash completion work.
+ XDG_DATA_DIRS+=:$out/share
- ${lib.optionalString (pre-commit ? shellHook) pre-commit.shellHook}
- '';
- } // lib.optionalAttrs (stdenv.buildPlatform.isLinux && pkgs.glibcLocales != null) {
- # Required to make non-NixOS Linux not complain about missing locale files during configure in a dev shell
- LOCALE_ARCHIVE = "${lib.getLib pkgs.glibcLocales}/lib/locale/locale-archive";
- });
+ ${lib.optionalString (pre-commit ? shellHook) pre-commit.shellHook}
+ '';
+ }
+ // lib.optionalAttrs (stdenv.buildPlatform.isLinux && pkgs.glibcLocales != null) {
+ # Required to make non-NixOS Linux not complain about missing locale files during configure in a dev shell
+ LOCALE_ARCHIVE = "${lib.getLib pkgs.glibcLocales}/lib/locale/locale-archive";
+ }
+ );
in
- forAllSystems (system:
+ forAllSystems (
+ system:
let
- makeShells = prefix: pkgs:
- lib.mapAttrs'
- (k: v: lib.nameValuePair "${prefix}-${k}" v)
- (forAllStdenvs (stdenvName: makeShell pkgs pkgs.${stdenvName}));
+ makeShells =
+ prefix: pkgs:
+ lib.mapAttrs' (k: v: lib.nameValuePair "${prefix}-${k}" v) (
+ forAllStdenvs (stdenvName: makeShell pkgs pkgs.${stdenvName})
+ );
in
- (makeShells "native" nixpkgsFor.${system}.native) //
- (makeShells "static" nixpkgsFor.${system}.static) //
- (forAllCrossSystems (crossSystem: let pkgs = nixpkgsFor.${system}.cross.${crossSystem}; in makeShell pkgs pkgs.stdenv)) //
- {
- default = self.devShells.${system}.native-stdenvPackages;
- }
+ (makeShells "native" nixpkgsFor.${system}.native)
+ // (makeShells "static" nixpkgsFor.${system}.static)
+ // (forAllCrossSystems (
+ crossSystem:
+ let
+ pkgs = nixpkgsFor.${system}.cross.${crossSystem};
+ in
+ makeShell pkgs pkgs.stdenv
+ ))
+ // {
+ default = self.devShells.${system}.native-stdenvPackages;
+ }
);
- };
+ };
}
diff --git a/maintainers/build-release-notes.nix b/maintainers/build-release-notes.nix
index 9462e33d7..dd260cf1c 100644
--- a/maintainers/build-release-notes.nix
+++ b/maintainers/build-release-notes.nix
@@ -1,5 +1,8 @@
-{ lib, python3, writeShellScriptBin }:
-
+{
+ lib,
+ python3,
+ writeShellScriptBin,
+}:
writeShellScriptBin "build-release-notes" ''
exec ${lib.getExe (python3.withPackages (p: [ p.python-frontmatter ]))} \
${./build-release-notes.py} "$@"
diff --git a/misc/clangbuildanalyzer.nix b/misc/clangbuildanalyzer.nix
index a317e5144..cee8a0d77 100644
--- a/misc/clangbuildanalyzer.nix
+++ b/misc/clangbuildanalyzer.nix
@@ -1,6 +1,11 @@
# Upstreaming here, can be deleted once it's upstreamed:
# https://github.com/NixOS/nixpkgs/pull/297102
-{ stdenv, lib, cmake, fetchFromGitHub }:
+{
+ stdenv,
+ lib,
+ cmake,
+ fetchFromGitHub,
+}:
stdenv.mkDerivation (finalAttrs: {
pname = "clangbuildanalyzer";
version = "1.5.0";
@@ -12,9 +17,7 @@ stdenv.mkDerivation (finalAttrs: {
sha256 = "sha256-kmgdk634zM0W0OoRoP/RzepArSipa5bNqdVgdZO9gxo=";
};
- nativeBuildInputs = [
- cmake
- ];
+ nativeBuildInputs = [ cmake ];
meta = {
description = "Tool for analyzing Clang's -ftrace-time files";
diff --git a/nix-support/nixfmt.nix b/nix-support/nixfmt.nix
new file mode 100644
index 000000000..b7c9961e4
--- /dev/null
+++ b/nix-support/nixfmt.nix
@@ -0,0 +1,79 @@
+# Copy of `nixfmt-rfc-style` vendored from `nixpkgs` master:
+# https://github.com/NixOS/nixpkgs/blob/ab6071eb54cc9b66dda436111d4f569e4e56cbf4/pkgs/by-name/ni/nixfmt-rfc-style/package.nix
+{
+ haskell,
+ haskellPackages,
+ lib,
+ fetchpatch,
+}:
+let
+ inherit (haskell.lib.compose) overrideCabal justStaticExecutables;
+
+ overrides = {
+ version = "unstable-2024-03-01";
+
+ patches = [
+ (fetchpatch {
+ url = "https://github.com/serokell/nixfmt/commit/ca9c8975ed671112fdfce94f2e9e2ad3de480c9a.patch";
+ hash = "sha256-UOSAYahSKBsqPMVcQJ3H26Eg2xpPAsNOjYMI6g+WTYU=";
+ })
+ ];
+ };
+
+ raw-pkg = haskellPackages.callPackage (
+ {
+ mkDerivation,
+ base,
+ cmdargs,
+ directory,
+ fetchzip,
+ filepath,
+ lib,
+ megaparsec,
+ mtl,
+ parser-combinators,
+ safe-exceptions,
+ scientific,
+ text,
+ transformers,
+ unix,
+ }:
+ mkDerivation {
+ pname = "nixfmt";
+ version = "0.5.0";
+ src = fetchzip {
+ url = "https://github.com/piegamesde/nixfmt/archive/2b5ee820690bae64cb4003e46917ae43541e3e0b.tar.gz";
+ sha256 = "1i1jbc1q4gd7fpilwy6s3a583yl5l8d8rlmipygj61mpclg9ihqg";
+ };
+ isLibrary = true;
+ isExecutable = true;
+ libraryHaskellDepends = [
+ base
+ megaparsec
+ mtl
+ parser-combinators
+ scientific
+ text
+ transformers
+ ];
+ executableHaskellDepends = [
+ base
+ cmdargs
+ directory
+ filepath
+ safe-exceptions
+ text
+ unix
+ ];
+ jailbreak = true;
+ homepage = "https://github.com/serokell/nixfmt";
+ description = "An opinionated formatter for Nix";
+ license = lib.licenses.mpl20;
+ mainProgram = "nixfmt";
+ }
+ ) { };
+in
+lib.pipe raw-pkg [
+ (overrideCabal overrides)
+ justStaticExecutables
+]
diff --git a/package.nix b/package.nix
index 082627c49..45855b50c 100644
--- a/package.nix
+++ b/package.nix
@@ -40,9 +40,11 @@
util-linuxMinimal ? utillinuxMinimal,
utillinuxMinimal ? null,
xz,
-
busybox-sandbox-shell,
+ # Customization options
+ # =====================
+
pname ? "nix",
versionSuffix ? "",
officialRelease ? true,
@@ -61,19 +63,21 @@
__forDefaults ? {
canRunInstalled = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
},
-}: let
+}:
+let
inherit (__forDefaults) canRunInstalled;
version = lib.fileContents ./.version + versionSuffix;
aws-sdk-cpp-nix = aws-sdk-cpp.override {
- apis = [ "s3" "transfer" ];
+ apis = [
+ "s3"
+ "transfer"
+ ];
customMemoryManagement = false;
};
- testConfigureFlags = [
- "RAPIDCHECK_HEADERS=${lib.getDev rapidcheck}/extras/gtest/include"
- ];
+ testConfigureFlags = [ "RAPIDCHECK_HEADERS=${lib.getDev rapidcheck}/extras/gtest/include" ];
# The internal API docs need these for the build, but if we're not building
# Nix itself, then these don't need to be propagated.
@@ -95,48 +99,60 @@
./README.md
];
- topLevelBuildFiles = fileset.unions ([
- ./local.mk
- ./Makefile
- ./Makefile.config.in
- ./mk
- ] ++ lib.optionals buildWithMeson [
- ./meson.build
- ./meson.options
- ./meson
- ./scripts/meson.build
- ]);
+ topLevelBuildFiles = fileset.unions (
+ [
+ ./local.mk
+ ./Makefile
+ ./Makefile.config.in
+ ./mk
+ ]
+ ++ lib.optionals buildWithMeson [
+ ./meson.build
+ ./meson.options
+ ./meson
+ ./scripts/meson.build
+ ]
+ );
- functionalTestFiles = fileset.unions [
+ functionalTestFiles = fileset.unions [
./tests/functional
./tests/unit
(fileset.fileFilter (f: lib.strings.hasPrefix "nix-profile" f.name) ./scripts)
- ];
-
-in stdenv.mkDerivation (finalAttrs: {
+ ];
+in
+stdenv.mkDerivation (finalAttrs: {
inherit pname version;
src = fileset.toSource {
root = ./.;
- fileset = fileset.intersection baseFiles (fileset.unions ([
- configureFiles
- topLevelBuildFiles
- functionalTestFiles
- ] ++ lib.optionals (!finalAttrs.dontBuild || internalApiDocs) [
- ./boehmgc-coroutine-sp-fallback.diff
- ./doc
- ./misc
- ./precompiled-headers.h
- ./src
- ./COPYING
- ./scripts/local.mk
- ]));
+ fileset = fileset.intersection baseFiles (
+ fileset.unions (
+ [
+ configureFiles
+ topLevelBuildFiles
+ functionalTestFiles
+ ]
+ ++ lib.optionals (!finalAttrs.dontBuild || internalApiDocs) [
+ ./boehmgc-coroutine-sp-fallback.diff
+ ./doc
+ ./misc
+ ./precompiled-headers.h
+ ./src
+ ./COPYING
+ ./scripts/local.mk
+ ]
+ )
+ );
};
VERSION_SUFFIX = versionSuffix;
- outputs = [ "out" ]
- ++ lib.optionals (!finalAttrs.dontBuild) [ "dev" "doc" ];
+ outputs =
+ [ "out" ]
+ ++ lib.optionals (!finalAttrs.dontBuild) [
+ "dev"
+ "doc"
+ ];
dontBuild = false;
@@ -148,51 +164,59 @@ in stdenv.mkDerivation (finalAttrs: {
# We only include CMake so that Meson can locate toml11, which only ships CMake dependency metadata.
dontUseCmakeConfigure = true;
- nativeBuildInputs = [
- bison
- flex
- ] ++ [
- (lib.getBin lowdown)
- mdbook
- mdbook-linkcheck
- autoconf-archive
- ] ++ lib.optional (!buildWithMeson) autoreconfHook ++ [
- pkg-config
+ nativeBuildInputs =
+ [
+ bison
+ flex
+ ]
+ ++ [
+ (lib.getBin lowdown)
+ mdbook
+ mdbook-linkcheck
+ autoconf-archive
+ ]
+ ++ lib.optional (!buildWithMeson) autoreconfHook
+ ++ [
+ pkg-config
- # Tests
- git
- mercurial
- jq
- lsof
- ] ++ lib.optional stdenv.hostPlatform.isLinux util-linuxMinimal
+ # Tests
+ git
+ mercurial
+ jq
+ lsof
+ ]
+ ++ lib.optional stdenv.hostPlatform.isLinux util-linuxMinimal
++ lib.optional (!officialRelease && buildUnreleasedNotes) build-release-notes
++ lib.optional internalApiDocs doxygen
++ lib.optionals buildWithMeson [
meson
ninja
cmake
- ];
+ ];
- buildInputs = [
- curl
- bzip2
- xz
- brotli
- editline
- openssl
- sqlite
- libarchive
- boost
- lowdown
- libsodium
- toml11
- ]
- ++ lib.optionals stdenv.hostPlatform.isLinux [ libseccomp busybox-sandbox-shell ]
+ buildInputs =
+ [
+ curl
+ bzip2
+ xz
+ brotli
+ editline
+ openssl
+ sqlite
+ libarchive
+ boost
+ lowdown
+ libsodium
+ toml11
+ ]
+ ++ lib.optionals stdenv.hostPlatform.isLinux [
+ libseccomp
+ busybox-sandbox-shell
+ ]
++ lib.optional stdenv.hostPlatform.isx86_64 libcpuid
# There have been issues building these dependencies
++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) aws-sdk-cpp-nix
- ++ lib.optionals (finalAttrs.dontBuild) maybePropagatedInputs
- ;
+ ++ lib.optionals (finalAttrs.dontBuild) maybePropagatedInputs;
checkInputs = [
gtest
@@ -201,9 +225,7 @@ in stdenv.mkDerivation (finalAttrs: {
propagatedBuildInputs = lib.optionals (!finalAttrs.dontBuild) maybePropagatedInputs;
- disallowedReferences = [
- boost
- ];
+ disallowedReferences = [ boost ];
# Needed for Meson to find Boost.
# https://github.com/NixOS/nixpkgs/issues/86131.
@@ -212,45 +234,49 @@ in stdenv.mkDerivation (finalAttrs: {
BOOST_LIBRARYDIR = "${lib.getLib boost}/lib";
};
- preConfigure = lib.optionalString (!finalAttrs.dontBuild && !stdenv.hostPlatform.isStatic) ''
- # Copy libboost_context so we don't get all of Boost in our closure.
- # https://github.com/NixOS/nixpkgs/issues/45462
- mkdir -p $out/lib
- cp -pd ${boost}/lib/{libboost_context*,libboost_thread*,libboost_system*} $out/lib
- rm -f $out/lib/*.a
- '' + lib.optionalString (!finalAttrs.dontBuild && stdenv.hostPlatform.isLinux) ''
- chmod u+w $out/lib/*.so.*
- patchelf --set-rpath $out/lib:${stdenv.cc.cc.lib}/lib $out/lib/libboost_thread.so.*
- '' + lib.optionalString (!finalAttrs.dontBuild && stdenv.hostPlatform.isDarwin) ''
- for LIB in $out/lib/*.dylib; do
- chmod u+w $LIB
- install_name_tool -id $LIB $LIB
- install_name_tool -delete_rpath ${boost}/lib/ $LIB || true
- done
- install_name_tool -change ${boost}/lib/libboost_system.dylib $out/lib/libboost_system.dylib $out/lib/libboost_thread.dylib
- '' + ''
- # Workaround https://github.com/NixOS/nixpkgs/issues/294890.
- if [[ -n "''${doCheck:-}" ]]; then
- appendToVar configureFlags "--enable-tests"
- else
- appendToVar configureFlags "--disable-tests"
- fi
- '';
+ preConfigure =
+ lib.optionalString (!finalAttrs.dontBuild && !stdenv.hostPlatform.isStatic) ''
+ # Copy libboost_context so we don't get all of Boost in our closure.
+ # https://github.com/NixOS/nixpkgs/issues/45462
+ mkdir -p $out/lib
+ cp -pd ${boost}/lib/{libboost_context*,libboost_thread*,libboost_system*} $out/lib
+ rm -f $out/lib/*.a
+ ''
+ + lib.optionalString (!finalAttrs.dontBuild && stdenv.hostPlatform.isLinux) ''
+ chmod u+w $out/lib/*.so.*
+ patchelf --set-rpath $out/lib:${stdenv.cc.cc.lib}/lib $out/lib/libboost_thread.so.*
+ ''
+ + lib.optionalString (!finalAttrs.dontBuild && stdenv.hostPlatform.isDarwin) ''
+ for LIB in $out/lib/*.dylib; do
+ chmod u+w $LIB
+ install_name_tool -id $LIB $LIB
+ install_name_tool -delete_rpath ${boost}/lib/ $LIB || true
+ done
+ install_name_tool -change ${boost}/lib/libboost_system.dylib $out/lib/libboost_system.dylib $out/lib/libboost_thread.dylib
+ ''
+ + ''
+ # Workaround https://github.com/NixOS/nixpkgs/issues/294890.
+ if [[ -n "''${doCheck:-}" ]]; then
+ appendToVar configureFlags "--enable-tests"
+ else
+ appendToVar configureFlags "--disable-tests"
+ fi
+ '';
- configureFlags = lib.optionals stdenv.isLinux [
- "--with-boost=${boost}/lib"
- "--with-sandbox-shell=${busybox-sandbox-shell}/bin/busybox"
- ] ++ lib.optionals (stdenv.isLinux && !(stdenv.hostPlatform.isStatic && stdenv.system == "aarch64-linux")) [
- "LDFLAGS=-fuse-ld=gold"
- ]
+ configureFlags =
+ lib.optionals stdenv.isLinux [
+ "--with-boost=${boost}/lib"
+ "--with-sandbox-shell=${busybox-sandbox-shell}/bin/busybox"
+ ]
+ ++ lib.optionals (
+ stdenv.isLinux && !(stdenv.hostPlatform.isStatic && stdenv.system == "aarch64-linux")
+ ) [ "LDFLAGS=-fuse-ld=gold" ]
++ lib.optional stdenv.hostPlatform.isStatic "--enable-embedded-sandbox-shell"
++ lib.optionals (finalAttrs.doCheck || internalApiDocs) testConfigureFlags
++ lib.optional (!canRunInstalled) "--disable-doc-gen"
++ [ (lib.enableFeature internalApiDocs "internal-api-docs") ]
++ lib.optional (!forDevShell) "--sysconfdir=/etc"
- ++ [
- "TOML11_HEADERS=${lib.getDev toml11}/include"
- ];
+ ++ [ "TOML11_HEADERS=${lib.getDev toml11}/include" ];
mesonBuildType = lib.optional (buildWithMeson || forDevShell) "debugoptimized";
@@ -262,37 +288,37 @@ in stdenv.mkDerivation (finalAttrs: {
doCheck = true;
- mesonCheckFlags = lib.optionals (buildWithMeson || forDevShell) [
- "--suite=check"
- ];
+ mesonCheckFlags = lib.optionals (buildWithMeson || forDevShell) [ "--suite=check" ];
installFlags = "sysconfdir=$(out)/etc";
- postInstall = lib.optionalString (!finalAttrs.dontBuild) ''
- mkdir -p $doc/nix-support
- echo "doc manual $doc/share/doc/nix/manual" >> $doc/nix-support/hydra-build-products
- '' + lib.optionalString stdenv.hostPlatform.isStatic ''
- mkdir -p $out/nix-support
- echo "file binary-dist $out/bin/nix" >> $out/nix-support/hydra-build-products
- '' + lib.optionalString stdenv.isDarwin ''
- for lib in libnixutil.dylib libnixexpr.dylib; do
- install_name_tool \
- -change "${lib.getLib boost}/lib/libboost_context.dylib" \
- "$out/lib/libboost_context.dylib" \
- "$out/lib/$lib"
- done
- '' + lib.optionalString internalApiDocs ''
- mkdir -p $out/nix-support
- echo "doc internal-api-docs $out/share/doc/nix/internal-api/html" >> "$out/nix-support/hydra-build-products"
- '';
+ postInstall =
+ lib.optionalString (!finalAttrs.dontBuild) ''
+ mkdir -p $doc/nix-support
+ echo "doc manual $doc/share/doc/nix/manual" >> $doc/nix-support/hydra-build-products
+ ''
+ + lib.optionalString stdenv.hostPlatform.isStatic ''
+ mkdir -p $out/nix-support
+ echo "file binary-dist $out/bin/nix" >> $out/nix-support/hydra-build-products
+ ''
+ + lib.optionalString stdenv.isDarwin ''
+ for lib in libnixutil.dylib libnixexpr.dylib; do
+ install_name_tool \
+ -change "${lib.getLib boost}/lib/libboost_context.dylib" \
+ "$out/lib/libboost_context.dylib" \
+ "$out/lib/$lib"
+ done
+ ''
+ + lib.optionalString internalApiDocs ''
+ mkdir -p $out/nix-support
+ echo "doc internal-api-docs $out/share/doc/nix/internal-api/html" >> "$out/nix-support/hydra-build-products"
+ '';
doInstallCheck = finalAttrs.doCheck;
installCheckFlags = "sysconfdir=$(out)/etc";
installCheckTarget = "installcheck"; # work around buggy detection in stdenv
- mesonInstallCheckFlags = [
- "--suite=installcheck"
- ];
+ mesonInstallCheckFlags = [ "--suite=installcheck" ];
preInstallCheck = lib.optionalString stdenv.hostPlatform.isDarwin ''
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
@@ -310,12 +336,9 @@ in stdenv.mkDerivation (finalAttrs: {
strictDeps = true;
# strictoverflow is disabled because we trap on signed overflow instead
- hardeningDisable = [ "strictoverflow" ]
- ++ lib.optional stdenv.hostPlatform.isStatic "pie";
+ hardeningDisable = [ "strictoverflow" ] ++ lib.optional stdenv.hostPlatform.isStatic "pie";
meta.platforms = lib.platforms.unix;
- passthru.perl-bindings = pkgs.callPackage ./perl {
- inherit fileset stdenv;
- };
+ passthru.perl-bindings = pkgs.callPackage ./perl { inherit fileset stdenv; };
})
diff --git a/perl/default.nix b/perl/default.nix
index 4687976a1..8fe8c31f0 100644
--- a/perl/default.nix
+++ b/perl/default.nix
@@ -1,51 +1,64 @@
-{ lib, fileset
-, stdenv
-, perl, perlPackages
-, autoconf-archive, autoreconfHook, pkg-config
-, nix, curl, bzip2, xz, boost, libsodium, darwin
+{
+ lib,
+ fileset,
+ stdenv,
+ perl,
+ perlPackages,
+ autoconf-archive,
+ autoreconfHook,
+ pkg-config,
+ nix,
+ curl,
+ bzip2,
+ xz,
+ boost,
+ libsodium,
+ darwin,
}:
+perl.pkgs.toPerlModule (
+ stdenv.mkDerivation {
+ name = "nix-perl-${nix.version}";
-perl.pkgs.toPerlModule (stdenv.mkDerivation {
- name = "nix-perl-${nix.version}";
+ src = fileset.toSource {
+ root = ../.;
+ fileset = fileset.unions [
+ ../.version
+ ../m4
+ ../mk
+ ./MANIFEST
+ ./Makefile
+ ./Makefile.config.in
+ ./configure.ac
+ ./lib
+ ./local.mk
+ ];
+ };
- src = fileset.toSource {
- root = ../.;
- fileset = fileset.unions [
- ../.version
- ../m4
- ../mk
- ./MANIFEST
- ./Makefile
- ./Makefile.config.in
- ./configure.ac
- ./lib
- ./local.mk
- ];
- };
-
- nativeBuildInputs =
- [ autoconf-archive
+ nativeBuildInputs = [
+ autoconf-archive
autoreconfHook
pkg-config
];
- buildInputs =
- [ nix
- curl
- bzip2
- xz
- perl
- boost
- ]
- ++ lib.optional (stdenv.isLinux || stdenv.isDarwin) libsodium
- ++ lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.Security;
+ buildInputs =
+ [
+ nix
+ curl
+ bzip2
+ xz
+ perl
+ boost
+ ]
+ ++ lib.optional (stdenv.isLinux || stdenv.isDarwin) libsodium
+ ++ lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.Security;
- configureFlags = [
- "--with-dbi=${perlPackages.DBI}/${perl.libPrefix}"
- "--with-dbd-sqlite=${perlPackages.DBDSQLite}/${perl.libPrefix}"
- ];
+ configureFlags = [
+ "--with-dbi=${perlPackages.DBI}/${perl.libPrefix}"
+ "--with-dbd-sqlite=${perlPackages.DBDSQLite}/${perl.libPrefix}"
+ ];
- enableParallelBuilding = true;
+ enableParallelBuilding = true;
- postUnpack = "sourceRoot=$sourceRoot/perl";
-})
+ postUnpack = "sourceRoot=$sourceRoot/perl";
+ }
+)
diff --git a/src/libexpr/fetchurl.nix b/src/libexpr/fetchurl.nix
index 9d1b61d7f..b559e6386 100644
--- a/src/libexpr/fetchurl.nix
+++ b/src/libexpr/fetchurl.nix
@@ -1,43 +1,72 @@
-{ system ? "" # obsolete
-, url
-, hash ? "" # an SRI hash
-
-# Legacy hash specification
-, md5 ? "", sha1 ? "", sha256 ? "", sha512 ? ""
-, 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
-, unpack ? false
-, name ? baseNameOf (toString url)
-, impure ? false
+{
+ system ? "", # obsolete
+ url,
+ hash ? "", # an SRI hash
+ # Legacy hash specification
+ md5 ? "",
+ sha1 ? "",
+ sha256 ? "",
+ sha512 ? "",
+ 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,
+ unpack ? false,
+ name ? baseNameOf (toString url),
+ impure ? false,
}:
+derivation (
+ {
+ builder = "builtin:fetchurl";
-derivation ({
- builder = "builtin:fetchurl";
+ # New-style output content requirements.
+ outputHashMode = if unpack || executable then "recursive" else "flat";
- # New-style output content requirements.
- outputHashMode = if unpack || executable then "recursive" else "flat";
+ inherit
+ name
+ url
+ executable
+ unpack
+ ;
- inherit name url executable unpack;
+ system = "builtin";
- system = "builtin";
+ # No need to double the amount of network traffic
+ preferLocalBuild = true;
- # No need to double the amount of network traffic
- preferLocalBuild = true;
+ impureEnvVars = [
+ # We borrow these environment variables from the caller to allow
+ # easy proxy configuration. This is impure, but a fixed-output
+ # derivation like fetchurl is allowed to do so since its result is
+ # by definition pure.
+ "http_proxy"
+ "https_proxy"
+ "ftp_proxy"
+ "all_proxy"
+ "no_proxy"
+ ];
- impureEnvVars = [
- # We borrow these environment variables from the caller to allow
- # easy proxy configuration. This is impure, but a fixed-output
- # derivation like fetchurl is allowed to do so since its result is
- # by definition pure.
- "http_proxy" "https_proxy" "ftp_proxy" "all_proxy" "no_proxy"
- ];
-
- # To make "nix-prefetch-url" work.
- urls = [ url ];
-} // (if impure
- then { __impure = true; }
- else { inherit outputHashAlgo outputHash; }))
+ # To make "nix-prefetch-url" work.
+ urls = [ url ];
+ }
+ // (if impure then { __impure = true; } else { inherit outputHashAlgo outputHash; })
+)
diff --git a/src/libexpr/flake/call-flake.nix b/src/libexpr/flake/call-flake.nix
index 4beb0b0fe..570080d94 100644
--- a/src/libexpr/flake/call-flake.nix
+++ b/src/libexpr/flake/call-flake.nix
@@ -1,72 +1,69 @@
lockFileStr: rootSrc: rootSubdir:
-
let
-
lockFile = builtins.fromJSON lockFileStr;
- allNodes =
- builtins.mapAttrs
- (key: node:
- let
+ allNodes = builtins.mapAttrs (
+ key: node:
+ let
+ sourceInfo =
+ if key == lockFile.root then
+ rootSrc
+ else
+ fetchTree (node.info or { } // removeAttrs node.locked [ "dir" ]);
- sourceInfo =
- if key == lockFile.root
- then rootSrc
- else fetchTree (node.info or {} // removeAttrs node.locked ["dir"]);
+ subdir = if key == lockFile.root then rootSubdir else node.locked.dir or "";
- subdir = if key == lockFile.root then rootSubdir else node.locked.dir or "";
+ outPath = sourceInfo + ((if subdir == "" then "" else "/") + subdir);
- outPath = sourceInfo + ((if subdir == "" then "" else "/") + subdir);
+ flake = import (outPath + "/flake.nix");
- flake = import (outPath + "/flake.nix");
+ inputs = builtins.mapAttrs (inputName: inputSpec: allNodes.${resolveInput inputSpec}) (
+ node.inputs or { }
+ );
- inputs = builtins.mapAttrs
- (inputName: inputSpec: allNodes.${resolveInput inputSpec})
- (node.inputs or {});
+ # Resolve a input spec into a node name. An input spec is
+ # either a node name, or a 'follows' path from the root
+ # node.
+ resolveInput =
+ inputSpec: if builtins.isList inputSpec then getInputByPath lockFile.root inputSpec else inputSpec;
- # Resolve a input spec into a node name. An input spec is
- # either a node name, or a 'follows' path from the root
- # node.
- resolveInput = inputSpec:
- if builtins.isList inputSpec
- then getInputByPath lockFile.root inputSpec
- else inputSpec;
+ # Follow an input path (e.g. ["dwarffs" "nixpkgs"]) from the
+ # root node, returning the final node.
+ getInputByPath =
+ nodeName: path:
+ if path == [ ] then
+ nodeName
+ else
+ getInputByPath
+ # Since this could be a 'follows' input, call resolveInput.
+ (resolveInput lockFile.nodes.${nodeName}.inputs.${builtins.head path})
+ (builtins.tail path);
- # Follow an input path (e.g. ["dwarffs" "nixpkgs"]) from the
- # root node, returning the final node.
- getInputByPath = nodeName: path:
- if path == []
- then nodeName
- else
- getInputByPath
- # Since this could be a 'follows' input, call resolveInput.
- (resolveInput lockFile.nodes.${nodeName}.inputs.${builtins.head path})
- (builtins.tail path);
+ outputs = flake.outputs (inputs // { self = result; });
- outputs = flake.outputs (inputs // { self = result; });
+ result =
+ outputs
+ # We add the sourceInfo attribute for its metadata, as they are
+ # relevant metadata for the flake. However, the outPath of the
+ # sourceInfo does not necessarily match the outPath of the flake,
+ # as the flake may be in a subdirectory of a source.
+ # This is shadowed in the next //
+ // sourceInfo
+ // {
+ # This shadows the sourceInfo.outPath
+ inherit outPath;
- result =
- outputs
- # We add the sourceInfo attribute for its metadata, as they are
- # relevant metadata for the flake. However, the outPath of the
- # sourceInfo does not necessarily match the outPath of the flake,
- # as the flake may be in a subdirectory of a source.
- # This is shadowed in the next //
- // sourceInfo
- // {
- # This shadows the sourceInfo.outPath
- inherit outPath;
-
- inherit inputs; inherit outputs; inherit sourceInfo; _type = "flake";
- };
-
- in
- if node.flake or true then
- assert builtins.isFunction flake.outputs;
- result
- else
- sourceInfo
- )
- lockFile.nodes;
-
-in allNodes.${lockFile.root}
+ inherit inputs;
+ inherit outputs;
+ inherit sourceInfo;
+ _type = "flake";
+ };
+ in
+ if node.flake or true then
+ assert builtins.isFunction flake.outputs;
+ result
+ else
+ sourceInfo
+ ) lockFile.nodes;
+in
+allNodes.${lockFile.root}
diff --git a/src/libexpr/imported-drv-to-derivation.nix b/src/libexpr/imported-drv-to-derivation.nix
index 9467e6a22..e1b7719d1 100644
--- a/src/libexpr/imported-drv-to-derivation.nix
+++ b/src/libexpr/imported-drv-to-derivation.nix
@@ -1,21 +1,24 @@
-attrs @ { drvPath, outputs, name, ... }:
-
+attrs@{
+ drvPath,
+ outputs,
+ name,
+ ...
+}:
let
+ commonAttrs = (builtins.listToAttrs outputsList) // {
+ all = map (x: x.value) outputsList;
+ inherit drvPath name;
+ type = "derivation";
+ };
- commonAttrs = (builtins.listToAttrs outputsList) //
- { all = map (x: x.value) outputsList;
- inherit drvPath name;
- type = "derivation";
- };
-
- outputToAttrListElement = outputName:
- { name = outputName;
- value = commonAttrs // {
- outPath = builtins.getAttr outputName attrs;
- inherit outputName;
- };
+ outputToAttrListElement = outputName: {
+ name = outputName;
+ value = commonAttrs // {
+ outPath = builtins.getAttr outputName attrs;
+ inherit outputName;
};
+ };
outputsList = map outputToAttrListElement outputs;
-
-in (builtins.head outputsList).value
+in
+(builtins.head outputsList).value
diff --git a/src/libexpr/primops/derivation.nix b/src/libexpr/primops/derivation.nix
index c0fbe8082..6d3e282cb 100644
--- a/src/libexpr/primops/derivation.nix
+++ b/src/libexpr/primops/derivation.nix
@@ -1,27 +1,32 @@
-/* This is the implementation of the ‘derivation’ builtin function.
- It's actually a wrapper around the ‘derivationStrict’ primop. */
-
-drvAttrs @ { outputs ? [ "out" ], ... }:
-
+/*
+ This is the implementation of the ‘derivation’ builtin function.
+ It's actually a wrapper around the ‘derivationStrict’ primop.
+*/
+drvAttrs@{
+ outputs ? [ "out" ],
+ ...
+}:
let
-
strict = derivationStrict drvAttrs;
- commonAttrs = drvAttrs // (builtins.listToAttrs outputsList) //
- { all = map (x: x.value) outputsList;
+ commonAttrs =
+ drvAttrs
+ // (builtins.listToAttrs outputsList)
+ // {
+ all = map (x: x.value) outputsList;
inherit drvAttrs;
};
- outputToAttrListElement = outputName:
- { name = outputName;
- value = commonAttrs // {
- outPath = builtins.getAttr outputName strict;
- drvPath = strict.drvPath;
- type = "derivation";
- inherit outputName;
- };
+ outputToAttrListElement = outputName: {
+ name = outputName;
+ value = commonAttrs // {
+ outPath = builtins.getAttr outputName strict;
+ drvPath = strict.drvPath;
+ type = "derivation";
+ inherit outputName;
};
+ };
outputsList = map outputToAttrListElement outputs;
-
-in (builtins.head outputsList).value
+in
+(builtins.head outputsList).value
diff --git a/src/nix-channel/unpack-channel.nix b/src/nix-channel/unpack-channel.nix
index 10515bc8b..a87c50a90 100644
--- a/src/nix-channel/unpack-channel.nix
+++ b/src/nix-channel/unpack-channel.nix
@@ -1,5 +1,8 @@
-{ name, channelName, src }:
-
+{
+ name,
+ channelName,
+ src,
+}:
derivation {
builder = "builtin:unpack-channel";
diff --git a/src/nix-env/buildenv.nix b/src/nix-env/buildenv.nix
index 0bac4c44b..363d9ac79 100644
--- a/src/nix-env/buildenv.nix
+++ b/src/nix-env/buildenv.nix
@@ -1,5 +1,4 @@
{ derivations, manifest }:
-
derivation {
name = "user-environment";
system = "builtin";
@@ -8,13 +7,15 @@ derivation {
inherit manifest;
# !!! grmbl, need structured data for passing this in a clean way.
- derivations =
- map (d:
- [ (d.meta.active or "true")
- (d.meta.priority or 5)
- (builtins.length d.outputs)
- ] ++ map (output: builtins.getAttr output d) d.outputs)
- derivations;
+ derivations = map (
+ d:
+ [
+ (d.meta.active or "true")
+ (d.meta.priority or 5)
+ (builtins.length d.outputs)
+ ]
+ ++ map (output: builtins.getAttr output d) d.outputs
+ ) derivations;
# Building user environments remotely just causes huge amounts of
# network traffic, so don't do that.
diff --git a/tests/functional/lang/eval-fail-eol-1.err.exp b/tests/functional/lang/parse-fail-eol-1.err.exp
similarity index 72%
rename from tests/functional/lang/eval-fail-eol-1.err.exp
rename to tests/functional/lang/parse-fail-eol-1.err.exp
index 3f5a5c22c..f7f79b460 100644
--- a/tests/functional/lang/eval-fail-eol-1.err.exp
+++ b/tests/functional/lang/parse-fail-eol-1.err.exp
@@ -1,5 +1,5 @@
error: undefined variable 'invalid'
- at /pwd/lang/eval-fail-eol-1.nix:2:1:
+ at «stdin»:2:1:
1| # foo
2| invalid
| ^
diff --git a/tests/functional/lang/eval-fail-eol-1.nix b/tests/functional/lang/parse-fail-eol-1.nix
similarity index 100%
rename from tests/functional/lang/eval-fail-eol-1.nix
rename to tests/functional/lang/parse-fail-eol-1.nix
diff --git a/tests/functional/lang/eval-fail-eol-2.err.exp b/tests/functional/lang/parse-fail-eol-2.err.exp
similarity index 72%
rename from tests/functional/lang/eval-fail-eol-2.err.exp
rename to tests/functional/lang/parse-fail-eol-2.err.exp
index ff13e2d55..f7f79b460 100644
--- a/tests/functional/lang/eval-fail-eol-2.err.exp
+++ b/tests/functional/lang/parse-fail-eol-2.err.exp
@@ -1,5 +1,5 @@
error: undefined variable 'invalid'
- at /pwd/lang/eval-fail-eol-2.nix:2:1:
+ at «stdin»:2:1:
1| # foo
2| invalid
| ^
diff --git a/tests/functional/lang/eval-fail-eol-2.nix b/tests/functional/lang/parse-fail-eol-2.nix
similarity index 100%
rename from tests/functional/lang/eval-fail-eol-2.nix
rename to tests/functional/lang/parse-fail-eol-2.nix
diff --git a/tests/functional/lang/eval-fail-eol-3.err.exp b/tests/functional/lang/parse-fail-eol-3.err.exp
similarity index 72%
rename from tests/functional/lang/eval-fail-eol-3.err.exp
rename to tests/functional/lang/parse-fail-eol-3.err.exp
index ada3c5ecd..f7f79b460 100644
--- a/tests/functional/lang/eval-fail-eol-3.err.exp
+++ b/tests/functional/lang/parse-fail-eol-3.err.exp
@@ -1,5 +1,5 @@
error: undefined variable 'invalid'
- at /pwd/lang/eval-fail-eol-3.nix:2:1:
+ at «stdin»:2:1:
1| # foo
2| invalid
| ^
diff --git a/tests/functional/lang/eval-fail-eol-3.nix b/tests/functional/lang/parse-fail-eol-3.nix
similarity index 100%
rename from tests/functional/lang/eval-fail-eol-3.nix
rename to tests/functional/lang/parse-fail-eol-3.nix
diff --git a/tests/functional/lang/eval-fail-path-slash.err.exp b/tests/functional/lang/parse-fail-path-slash.err.exp
similarity index 77%
rename from tests/functional/lang/eval-fail-path-slash.err.exp
rename to tests/functional/lang/parse-fail-path-slash.err.exp
index e3531d352..0407543a1 100644
--- a/tests/functional/lang/eval-fail-path-slash.err.exp
+++ b/tests/functional/lang/parse-fail-path-slash.err.exp
@@ -1,5 +1,5 @@
error: path has a trailing slash
- at /pwd/lang/eval-fail-path-slash.nix:6:12:
+ at «stdin»:6:12:
5| # and https://nixos.org/nix-dev/2016-June/020829.html
6| /nix/store/
| ^
diff --git a/tests/functional/lang/eval-fail-path-slash.nix b/tests/functional/lang/parse-fail-path-slash.nix
similarity index 100%
rename from tests/functional/lang/eval-fail-path-slash.nix
rename to tests/functional/lang/parse-fail-path-slash.nix
diff --git a/tests/functional/lang/eval-fail-set.err.exp b/tests/functional/lang/parse-fail-set.err.exp
similarity index 65%
rename from tests/functional/lang/eval-fail-set.err.exp
rename to tests/functional/lang/parse-fail-set.err.exp
index 6dd646e11..2f77406a7 100644
--- a/tests/functional/lang/eval-fail-set.err.exp
+++ b/tests/functional/lang/parse-fail-set.err.exp
@@ -1,5 +1,5 @@
error: undefined variable 'x'
- at /pwd/lang/eval-fail-set.nix:1:3:
+ at «stdin»:1:3:
1| 8.x
| ^
2|
diff --git a/tests/functional/lang/eval-fail-set.nix b/tests/functional/lang/parse-fail-set.nix
similarity index 100%
rename from tests/functional/lang/eval-fail-set.nix
rename to tests/functional/lang/parse-fail-set.nix
diff --git a/treefmt.toml b/treefmt.toml
index 81df72cc2..0d8323d6e 100644
--- a/treefmt.toml
+++ b/treefmt.toml
@@ -1 +1,4 @@
-[formatter]
+[formatter.nix]
+command = "nixfmt"
+includes = ["*.nix"]
+excludes = ["tests/**"]