Commit Graph

70 Commits

Author SHA1 Message Date
Cole Helbling
ccb779782c flake.nix: exclude armv6-linux, riscv64-linux, and FreeBSD from devShells
nixfmt-rfc-style is built with Haskell, and the packaged GHC compiler
does not support any of these platforms (currently?).

    error:
           … while checking flake output 'devShells'
             at /nix/store/p36amaznf46ic90fb2rw5c952mgj6mfi-source/flake.nix:123:7:
              122|
              123|       devShells = forAllSystems (system: { } // lib.optionalAttrs (system != "armv6l-linux" && system != "riscv64-linux") {
                 |       ^
              124|         /** A shell to get tooling for Nixpkgs development. See nixpkgs/shell.nix. */

           … while checking the derivation 'devShells.x86_64-freebsd.default'
             at /nix/store/p36amaznf46ic90fb2rw5c952mgj6mfi-source/flake.nix:125:9:
              124|         /** A shell to get tooling for Nixpkgs development. See nixpkgs/shell.nix. */
              125|         default = import ./shell.nix { inherit system; };
                 |         ^
              126|       });

           (stack trace truncated; use '--show-trace' to show the full, detailed trace)

           error: Package ‘ghc-9.6.6’ in /nix/store/8akjd9ngyzhzi1412nxmw26rnj93l3gp-source/pkgs/development/compilers/ghc/common-hadrian.nix:579 is not available on the requested hostPlatform:
             hostPlatform.config = "x86_64-unknown-freebsd"
             package.meta.platforms = [
               "aarch64-darwin"
               "aarch64-linux"
               "i686-linux"
               "x86_64-darwin"
               "x86_64-linux"
             ]
             package.meta.badPlatforms = [ ]
           , refusing to evaluate.
2024-10-16 08:46:44 -07:00
Cole Helbling
db1b484d98 flake.nix: exclude armv6-linux and riscv64-linux from checks
Otherwise, `nix flake check --all-systems --json` fails with:

    error:
           … while calling the 'head' builtin
             at /nix/store/0jy5khqx0rfw8avcq6z5zaxaj2ppz8d3-source/lib/attrsets.nix:1575:11:
             1574|         || pred here (elemAt values 1) (head values) then
             1575|           head values
                 |           ^
             1576|         else

           … while evaluating the attribute 'value'
             at /nix/store/0jy5khqx0rfw8avcq6z5zaxaj2ppz8d3-source/lib/modules.nix:816:9:
              815|     in warnDeprecation opt //
              816|       { value = addErrorContext "while evaluating the option `${showOption loc}':" value;
                 |         ^
              817|         inherit (res.defsFinal') highestPrio;

           … while evaluating the option `system.build.toplevel':

           … while evaluating definitions from `/nix/store/0jy5khqx0rfw8avcq6z5zaxaj2ppz8d3-source/nixos/modules/system/activation/top-level.nix':

           … while evaluating the option `system.systemBuilderArgs':

           … while evaluating definitions from `/nix/store/0jy5khqx0rfw8avcq6z5zaxaj2ppz8d3-source/nixos/modules/system/activation/activatable-system.nix':

           … while evaluating the option `system.activationScripts.etc.text':

           … while evaluating definitions from `/nix/store/0jy5khqx0rfw8avcq6z5zaxaj2ppz8d3-source/nixos/modules/system/etc/etc-activation.nix':

           … while evaluating definitions from `/nix/store/0jy5khqx0rfw8avcq6z5zaxaj2ppz8d3-source/nixos/modules/system/etc/etc.nix':

           … while evaluating the option `environment.etc.dbus-1.source':

           (stack trace truncated; use '--show-trace' to show the full, detailed trace)

           error: cannot bootstrap GHC on this platform ('riscv64-linux' with libc 'defaultLibc')
2024-10-16 08:34:44 -07:00
Aleksana
ae7e9609f2
flake.nix: Add doc comments (#343235) 2024-09-30 16:45:13 +08:00
Artturin
e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00
tilpner
0c24185366 nixos: set system.stateVersion from the nixpkgs release, not version
The nixpkgs/nixos version includes a suffix like "pre-git" or
"pre676716.6f16e67b4921", which does not match the conventional
"XX.YY" format of system.stateVersion.

Unifying the format to "XX.YY" allows for (stricter) validation (see #317858),
and the introduction in 3a5ff9a68c was
only concerned with silencing warnings, so the addition of the "pre.*"
suffix into stateVersion was probably unintentional.
2024-09-23 12:18:11 +02:00
Robert Hensing
d0542fe3cd flake.nix: Add doc comments 2024-09-20 12:47:19 +02:00
Tristan Ross
112cef0f1d
flake.nix: add pinned devshell 2024-08-09 19:25:59 -07:00
Tristan Ross
4bf6540ad3
flake.nix: remove power64 from from nixos check due to broken package 2024-06-17 16:40:39 -07:00
Tristan Ross
9ebed2c8ea
flake.nix: make checks friendly for non-x86_64-linux systems 2024-06-06 21:20:49 -07:00
Tristan Ross
8233812d54
flake.nix: make pure 2024-06-06 21:19:05 -07:00
Jade Lovelace
e456032add nixos/flake: put nixpkgs in NIX_PATH and system registry for flake configs
Currently there are a bunch of really wacky hacks required to get nixpkgs
path correctly set up under flake configs such that `nix run
nixpkgs#hello` and `nix run -f '<nixpkgs>' hello` hit the nixpkgs that
the system was built with. In particular you have to use specialArgs or
an anonymous module, and everyone has to include this hack in their
own configs.

We can do this for users automatically.

I have tested these manually with a basic config; I don't know if it is
even possible to write a nixos test for it since you can't really get a
string-with-context to yourself unless you are in a flake context.
2024-02-03 20:44:38 -08:00
Robert Hensing
47d6b21930
flake.nix: Add caveats 2023-12-30 11:25:54 +01:00
r-vdp
f8c13ee878
flake: add a test case for the nixosSystem to the flake checks 2023-12-29 01:17:03 +01:00
r-vdp
981754ba5c
flake: allow specifying the lib argument to nixosSystem
Some configs rely on being able to pass their own lib argument into
nixosSystem, for instance in order to add their own additional overlay
to nixpkgs.lib.
This was broken by 039f73f134.
2023-12-29 00:52:12 +01:00
Maximilian Bosch
b96ba988d6
flake: drop libVersionInfoOverlay
It's not really a pkgs overlay, but a lib overlay.
2023-12-10 13:25:43 +01:00
Maximilian Bosch
cb289a9256
flake: be backwards-compatible for --impure
We cannot pass `overlays = ...` to `nixpkgs` directly because by default
overlays from `~/.config/nixpkgs` are loaded in there. This doesn't
happen by default, but when using `--impure`.

Explicitly specifying that ignores these overlays. By using `pkgs.extend`
the old behavior can be kept and the new overlay can be applied.

Co-authored-by: Silvan Mosberger <contact@infinisil.com>
2023-12-10 13:25:25 +01:00
Maximilian Bosch
ede5720a0d
flake/version overlay: review fixes
* Improves the comments of `lib/flake-version-info.nix` and drops the
  `__`-prefix from the filename.
* `lib'` -> `lib0` in `nixpkgs/lib`.
* Drop the declaration of `trivial.version` in the overlay because this
  declaration already uses the final expressions of `versionSuffix` and
  `release` now.
* No need to fall back to `self.lastModified` anymore, this was a
  workaround for pre2.4 Nix.

Co-authored-by: Robert Hensing <robert@roberthensing.nl>
Co-authored-by: Silvan Mosberger <contact@infinisil.com>
2023-12-10 13:25:24 +01:00
Maximilian Bosch
bb7921d1d6
flake: also provide proper version info for lib's flake
This effectively means that

    nixpkgs$ nix eval ./lib#lib.trivial.version
    "23.11.20231020.ee0d6b5"

now gives meaningful results as well.

See https://github.com/NixOS/nixpkgs/pull/257100#discussion_r1352075369
for the discussion around this.
2023-12-09 11:45:45 +01:00
Maximilian Bosch
039f73f134
flake: fix lib.trivial.version when used from a flake
A lot of fetchers from Nix's own `libfetchers` also provide the
information that `lib.trivial` aims to expose with
`version`/`versionSuffix`/`revision`. In fact you don't even need a
`nixpkgs` channel to get a proper version suffix because of that!

Unfortunately this isn't used currently. When using the
nixpkgs flake, but not `nixpkgs.lib.nixosSystem` to build a NixOS
configuration, the version will always be `YY.MMpre-git`. One example is
e.g. `colmena` which evaluates configurations via
`import (npkgs.path + "/nixos/lib/eval-config.nix")`.

This patch ensures that the version suffix (i.e. the normalized last
modified date + git revision) is correctly exposed in `lib.trivial`.
Additionally, the change is injected into the following locations:

* `lib`: with that, something like

      $ nix eval nixpkgs#lib.trivial.version
      23.05.20230921.cf8bf79

  is working fine (i.e. rather than `23.05pre-git`).

* `legacyPackages` to make sure that e.g. `legacyPackages.<system>.nixos`
  has correct version info. This also applies to everything else using
  `pkgs.lib.trivial` for that purpose.

* `overlays.default` which can be applied to a `nixpkgs` and changes the
  previous `pkgs.lib` from said `nixpkgs` to also contain the correct
  `version`/`revision`/etc..

  This is useful for people using `nixpkgs` as flake input, but
  importing it manually with

      import inputs.nixpkgs { }

Co-authored-by: Linus Heckemann <git@sphalerite.org>
2023-12-09 11:45:44 +01:00
Robert Hensing
e5db80ae48 nixosModules.pkgsReadOnly: init 2023-05-10 15:55:09 +02:00
Robert Hensing
9f5958538d
Merge pull request #194763 from hercules-ci/flake-improve-nixosModules-notDetected-error-location-reporting
flake.nix: Improve nixosModules.notDetected error location reporting
2022-11-13 00:12:56 +01:00
Jörg Thalheim
49e5e47318
flake.nix: simplify forAllSystems (#190527) 2022-11-08 19:38:35 +01:00
Luc Perkins
16448f9e76 doc: use evaluating instead of iterating 2022-10-29 10:50:29 -07:00
Luc Perkins
0c738e2e18 doc: add code comment clarifying the meaning of legacyPackages 2022-10-29 10:50:29 -07:00
Robert Hensing
33c8c0fb00 flake.nix: Improve nixosModules.notDetected error location reporting
This is mostly equivalent, but `import` was hiding the location
from the module system, breaking error location reporting and
breaking `disabledModules` support for this module (unlikely).
2022-10-06 16:55:11 +02:00
Robert Hensing
82378f9c0c flake.nix: Format 2022-07-10 13:35:54 +02:00
Robert Hensing
62314ccc17 flake.lib.nixosSystem: Allow nixpkgs.system to be set instead 2022-07-10 13:35:54 +02:00
sternenseemann
168b926435 lib.systems: remove supported, replace with flakeExposed
Since the list only gates the platforms the nixpkgs flake exposes
packages to build on, the `hydra` label made little sense. It was also
only used for this purpose, so the `tier*` attributes were largely
unnecessary.

To reflect the intention more accurately, we expose
`lib.systems.flakeExposed` and use it to gate flake.nix's system list.
2022-05-23 15:27:30 +02:00
Naïm Favier
5ab62e17b5
nixos: move default module location logic to eval-config.nix 2022-01-27 22:13:35 +01:00
Robert Hensing
4acad300ac Revert "pkgs.path: Avoid copying when used via flake"
This reverts commit 813f9da8ab.
2022-01-27 12:53:30 +01:00
Robert Hensing
6b9ef93b98 Revert "flake.nix: Set nixpkgs.config.path"
This reverts commit 0b222173db.
2022-01-27 12:53:29 +01:00
Robert Hensing
0b222173db flake.nix: Set nixpkgs.config.path 2022-01-22 16:43:05 +01:00
Robert Hensing
813f9da8ab pkgs.path: Avoid copying when used via flake 2022-01-22 16:42:07 +01:00
Robert Hensing
98ae5a9298
Merge pull request #153211 from hercules-ci/minimal-nixos
Add minimal NixOS entrypoint
2022-01-20 14:42:46 +01:00
Robert Hensing
fbd038eca2 nixos/lib: init (experimental) 2022-01-07 01:21:07 +01:00
Robert Hensing
a2710255c9 flake.nix: Remove redundant module lambda 2021-12-17 14:49:31 +01:00
Robert Hensing
6510ec5acd nixos: Make system.build.vm a standard attribute based on vmVariant 2021-12-17 14:49:31 +01:00
Robert Hensing
a0ad8dcd35 flake.nix: lib.nixosSystem: Set system.build.vm* with lib.mkDefault
This will help anyone who imports the qemu module themselves, to
avoid a collision.
2021-12-17 14:12:47 +01:00
Robert Hensing
537db62345 flake.nix: Deduplicate vmConfig, vmWithBootloaderConfig 2021-12-17 14:04:03 +01:00
Jonas Chevalier
8377a7bca9
lib: add list of supported systems (#140428)
Adds the first 3 tiers of RFC0046 that are being used in flake.nix.
2021-10-05 11:14:47 +02:00
Maximilian Bosch
6797b92f8d
flake.nix: Only add _file-key if position of args.modules is actually known to the evaluator
This happens if the evaluator "loses" the position of an
attr-declaration[1] because of e.g. too many nested function-calls to
build the final attr-set.

While the actual issue should be fixed in Nix itself, this is IMHO a
fair workaround to unblock affected users[2].

[1] e14c245934 (commitcomment-53645936)
[2] It seems as everyone using `divnix/digga` or `flake-utils-plus`
    are affected:
    * https://github.com/divnix/digga/issues/87
2021-07-18 19:47:10 +02:00
Maximilian Bosch
e14c245934
flake/lib.nixosSystem: add _file-keys for error-location
When inlining a module with a problematic declaration, you usually get
get a not-so helpful error like this:

    $ cat flake.nix
    {
      description = "A very basic flake";
      inputs.nixpkgs.url = path:../.;
      outputs = { self, nixpkgs }: {
        nixosConfigurations.foo = nixpkgs.lib.nixosSystem {
          system = "x86_64-linux";
          modules = [
            ({ lib, ... }: { services.wrong = 2; })
            { services.nginx.enable = true; }
          ];
        };
      };
    }
    $ nixos-rebuild build --flake .#foo -L
    error: The option `services.wrong' does not exist. Definition values:
           - In `<unknown-file>': 2

While it's certainly possible to guess where this comes from, this is
IMHO fairly confusing for beginners (and kinda reminds me of the
infamous "infinite recursion at undefined position"-error).

The module-system determines the position of a declaration using the
`_file`-key: this is either `toString path` if `path` is e.g. a value
from `imports = [ ./foo.nix ]` or the file used as `NIXOS_CONFIG` in
`<nixpkgs/nixos>`.

However such a mechanism doesn't exist (yet) for inlined flake modules,
so I tried to implement this in a fairly basic way:

* For non-path declarations, the position of `modules` inside the
  `flake.nix` which declares these modules is determined by doing
  `unsafeGetAttrPos` on the `modules`-argument of `lib.nixosSystem`.

  So the `flake.nix` from above would now raise the following
  error-message:

        $ nixos-rebuild build --flake .#foo -L
        error: The option `services.wrong' does not exist. Definition values:
               - In `/nix/store/4vi3nhqjyma73ygs4f93q38qjkhkaxw8-source/flake.nix': 2

Co-authored-by: Cole Helbling <cole.e.helbling@outlook.com>
Co-authored-by: Silvan Mosberger <github@infinisil.com>
Co-authored-by: Robert Hensing <robert@roberthensing.nl>
2021-07-14 10:12:57 +02:00
Matthew Bauer
33b59b8940 flake.nix: add aarch64-darwin 2021-05-17 00:27:02 +09:00
Bjørn Forsman
72d906a0ea nixos: fix "nixos-rebuild build-vm-with-bootloader" for EFI systems
(The first version of this change, in commit 39fad297fd, broke
`nix-build -A nixosTests.installer.simpleUefiSystemdBoot`. This is the
2nd version, which hopefully does not break anything.)

`nixos-rebuild build-vm-with-bootloader` currently fails with the
default NixOS EFI configuration:

  $ cat >configuration.nix <<EOF
  {
    fileSystems."/".device = "/dev/sda1";
    boot.loader.systemd-boot.enable = true;
    boot.loader.efi.canTouchEfiVariables = true;
  }
  EOF

  $ nixos-rebuild build-vm-with-bootloader -I nixos-config=$PWD/configuration.nix -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-20.09.tar.gz
  [...]
  insmod: ERROR: could not insert module /nix/store/1ibmgfr13r8b6xyn4f0wj115819f359c-linux-5.4.83/lib/modules/5.4.83/kernel/fs/efivarfs/efivarfs.ko.xz: No such device
  mount: /sys/firmware/efi/efivars: mount point does not exist.
  [    1.908328] reboot: Power down
  builder for '/nix/store/dx2ycclyknvibrskwmii42sgyalagjxa-nixos-boot-disk.drv' failed with exit code 32
  [...]

Fix it by setting virtualisation.useEFIBoot = true when needed.

Before:
* release-20.03: successful build, unsuccessful run
* release-20.09 (and master): unsuccessful build

After:
* Successful build and run.

Fixes #107255
2021-01-08 19:36:10 +01:00
Maximilian Bosch
3743c42f23
flake.nix: allow inclusion of nixpkgs as path:/.../
When adding `nixpkgs` as flake-input using the `path`-fetcher, you
currently get the following error since neither `lastModifiedDate` nor
`lastModified` are stored in `flake.lock` for paths:

```
error: --- EvalError --------------------------------------------------------------------------- nix-build
at: (48:71) in file: /nix/store/147clg8svaxyj7pl80ra9kmmm72mdg94-source/flake.nix

    47|                   system.nixos.versionSuffix =
    48|                     ".${final.substring 0 8 (self.lastModifiedDate or self.lastModified)}.${self.shortRev or "dirty"}";
      |                                                                       ^
    49|                   system.nixos.revision = final.mkIf (self ? rev) self.rev;

attribute 'lastModified' missing
```

This patch adds the fallback-value `19700101` to `versionSuffix` if none
of `lastModified{,Date}` are set in the lockfile.
2020-10-13 12:05:19 +02:00
Cole Helbling
e26b348689
nixos-rebuild: add flake support for build-vm
This relies on users using `nixpkgs.lib.nixosSystem` to define their
system; otherwise, the `vm` and `vmWithBootLoader` attributes will not
exist.
2020-09-17 11:44:47 -07:00
Jörg Thalheim
55cd36a232
Merge pull request #92423 from Mic92/arm-flakes
flake.nix: add armv6l/armv7l systems
2020-07-28 10:02:22 +01:00
Fabian Möller
74430a81ff
flake.nix: use lib.extend
This preserves the nixosSystem function if another flake uses lib.extend
itself.
2020-07-23 17:36:45 +02:00
Jörg Thalheim
4c26d0ec5f
flake.nix: add armv6l/armv7l systems
We built at least armv7l on hydra, therefor nixpkgs should also expose it.
2020-07-06 07:52:01 +01:00
Eelco Dolstra
97fc8af29b
flake.nix: Remove edition field 2020-06-08 12:45:17 +02:00