nix-community / nixpkgs-fmt

Nix code formatter for nixpkgs [maintainer=@zimbatm]
https://nix-community.github.io/nixpkgs-fmt/
Apache License 2.0
582 stars 32 forks source link

sample: Indenting all but the first line is a bit too much. #229

Closed aij closed 3 years ago

aij commented 3 years ago

I tried using nixpkgs-fmt on a test I was working on and it indented everything except for the first line an extra level, which seemed kind of ridiculous in the case of nixos/tests/ceph-*.nix. Below is a smaller example showing the same behavior, though to a much smaller extent since there are fewer lines for it to indent.

Input

import ./make-test-python.nix ({pkgs, lib, ...}:

let
  foo = 42;
  bar = 57;
in {
  baz = qux;
})

Output

import ./make-test-python.nix ({ pkgs, lib, ... }:

  let
    foo = 42;
    bar = 57;
  in
  {
    baz = qux;
  })

Desired output

import ./make-test-python.nix ({pkgs, lib, ...}:

let
  foo = 42;
  bar = 57;
in {
  baz = qux;
})
zimbatm commented 3 years ago

If we want to keep the code regular, this would be an additional exception to the rule-set.

I think the best option is to re-structure the nix code to make it more readable. Eg:

let
  my_fn = { pkgs, lib, ... }:
    let
      foo = 42;
      bar = 57;
    in
    {
      baz = qux;
    };
in
import ./make-test-python.nix my_fn
aij commented 3 years ago

Restructuring the code like that is not a good workaround to avoid the extra indentation. It would indent the whole file two extra levels instead of just one.

I'm not sure what the more general rule should be exactly, but it probably shouldn't be based on the number of lines.

FWIW, this pattern is not exactly uncommon in nixpkgs. Here's a few more examples (a few do indent the main expression):

example of common pattern ```nix $ rg 'make-test-python.nix.*:$' -A2 nixos/tests/croc.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/croc.nix-let nixos/tests/croc.nix- client = { pkgs, ... }: { -- nixos/tests/mumble.nix:import ./make-test-python.nix ({ pkgs, ...} : nixos/tests/mumble.nix- nixos/tests/mumble.nix-let -- nixos/tests/pleroma.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/pleroma.nix- let nixos/tests/pleroma.nix- send-toot = pkgs.writeScriptBin "send-toot" '' -- nixos/tests/xautolock.nix:import ./make-test-python.nix ({ pkgs, lib, ... }: nixos/tests/xautolock.nix- nixos/tests/xautolock.nix-with lib; -- nixos/tests/ncdns.nix:import ./make-test-python.nix ({ lib, pkgs, ... }: nixos/tests/ncdns.nix-let nixos/tests/ncdns.nix- fakeReply = pkgs.writeText "namecoin-reply.json" '' -- nixos/tests/pgmanage.nix:import ./make-test-python.nix ({ pkgs, ... } : nixos/tests/pgmanage.nix-let nixos/tests/pgmanage.nix- role = "test"; -- nixos/tests/rxe.nix:import ./make-test-python.nix ({ ... } : nixos/tests/rxe.nix- nixos/tests/rxe.nix-let -- nixos/tests/mongodb.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/mongodb.nix- let nixos/tests/mongodb.nix- testQuery = pkgs.writeScript "nixtest.js" '' -- nixos/tests/ecryptfs.nix:import ./make-test-python.nix ({ ... }: nixos/tests/ecryptfs.nix-{ nixos/tests/ecryptfs.nix- name = "ecryptfs"; -- nixos/tests/shiori.nix:import ./make-test-python.nix ({ pkgs, lib, ...}: nixos/tests/shiori.nix- nixos/tests/shiori.nix-{ -- nixos/tests/gerrit.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/gerrit.nix- nixos/tests/gerrit.nix-let -- nixos/tests/handbrake.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/handbrake.nix-let nixos/tests/handbrake.nix- # Download Big Buck Bunny example, licensed under CC Attribution 3.0. -- nixos/tests/docker-tools-cross.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/docker-tools-cross.nix-let nixos/tests/docker-tools-cross.nix- -- nixos/tests/solr.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/solr.nix- nixos/tests/solr.nix-{ -- nixos/tests/bazarr.nix:import ./make-test-python.nix ({ lib, ... }: nixos/tests/bazarr.nix- nixos/tests/bazarr.nix-with lib; -- nixos/tests/beanstalkd.nix:import ./make-test-python.nix ({ pkgs, lib, ... }: nixos/tests/beanstalkd.nix- nixos/tests/beanstalkd.nix-let -- nixos/tests/nat.nix:import ./make-test-python.nix ({ pkgs, lib, withFirewall, withConntrackHelpers ? false, ... }: nixos/tests/nat.nix- let nixos/tests/nat.nix- unit = if withFirewall then "firewall" else "nat"; -- nixos/tests/gitdaemon.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/gitdaemon.nix- nixos/tests/gitdaemon.nix-let -- nixos/tests/locate.nix:import ./make-test-python.nix ({ lib, pkgs, ... }: nixos/tests/locate.nix- let inherit (import ./ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey; nixos/tests/locate.nix- in { -- nixos/tests/minio.nix:import ./make-test-python.nix ({ pkgs, ...} : nixos/tests/minio.nix-let nixos/tests/minio.nix- accessKey = "BKIKJAA5BMMU2RHO6IBB"; -- nixos/tests/radarr.nix:import ./make-test-python.nix ({ lib, ... }: nixos/tests/radarr.nix- nixos/tests/radarr.nix-with lib; -- nixos/tests/morty.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/morty.nix- nixos/tests/morty.nix-{ -- nixos/tests/lidarr.nix:import ./make-test-python.nix ({ lib, ... }: nixos/tests/lidarr.nix- nixos/tests/lidarr.nix-with lib; -- nixos/tests/osrm-backend.nix:import ./make-test-python.nix ({ pkgs, lib, ... }: nixos/tests/osrm-backend.nix-let nixos/tests/osrm-backend.nix- port = 5000; -- nixos/tests/zigbee2mqtt.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/zigbee2mqtt.nix- nixos/tests/zigbee2mqtt.nix- { -- nixos/tests/xss-lock.nix:import ./make-test-python.nix ({ pkgs, lib, ... }: nixos/tests/xss-lock.nix- nixos/tests/xss-lock.nix-with lib; -- nixos/tests/hedgedoc.nix:import ./make-test-python.nix ({ pkgs, lib, ... }: nixos/tests/hedgedoc.nix-{ nixos/tests/hedgedoc.nix- name = "hedgedoc"; -- nixos/tests/loki.nix:import ./make-test-python.nix ({ lib, pkgs, ... }: nixos/tests/loki.nix- nixos/tests/loki.nix-{ -- nixos/tests/cassandra.nix:import ./make-test-python.nix ({ pkgs, lib, testPackage ? pkgs.cassandra, ... }: nixos/tests/cassandra.nix-let nixos/tests/cassandra.nix- clusterName = "NixOS Automated-Test Cluster"; -- nixos/tests/vault.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/vault.nix-{ nixos/tests/vault.nix- name = "vault"; -- nixos/tests/pam-u2f.nix:import ./make-test-python.nix ({ ... }: nixos/tests/pam-u2f.nix- nixos/tests/pam-u2f.nix-{ -- nixos/tests/zoneminder.nix:import ./make-test-python.nix ({ lib, ...}: nixos/tests/zoneminder.nix- nixos/tests/zoneminder.nix-{ -- nixos/tests/home-assistant.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/home-assistant.nix- nixos/tests/home-assistant.nix-let -- nixos/tests/google-oslogin/default.nix:import ../make-test-python.nix ({ pkgs, ... } : nixos/tests/google-oslogin/default.nix-let nixos/tests/google-oslogin/default.nix- inherit (import ./../ssh-keys.nix pkgs) -- nixos/tests/mediatomb.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/mediatomb.nix- nixos/tests/mediatomb.nix-{ -- nixos/tests/keepassxc.nix:import ./make-test-python.nix ({ pkgs, ...} : nixos/tests/keepassxc.nix- nixos/tests/keepassxc.nix-{ -- nixos/tests/robustirc-bridge.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/robustirc-bridge.nix- nixos/tests/robustirc-bridge.nix-{ -- nixos/tests/dokuwiki.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/dokuwiki.nix- nixos/tests/dokuwiki.nix-let -- nixos/tests/cage.nix:import ./make-test-python.nix ({ pkgs, ...} : nixos/tests/cage.nix- nixos/tests/cage.nix-{ -- nixos/tests/privoxy.nix:import ./make-test-python.nix ({ lib, pkgs, ... }: nixos/tests/privoxy.nix- nixos/tests/privoxy.nix-let -- nixos/tests/printing.nix:import ./make-test-python.nix ({pkgs, ... }: nixos/tests/printing.nix-let nixos/tests/printing.nix- printingServer = startWhenNeeded: { -- nixos/tests/fenics.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/fenics.nix- nixos/tests/fenics.nix-let -- nixos/tests/containers-reloadable.nix:import ./make-test-python.nix ({ pkgs, lib, ... }: nixos/tests/containers-reloadable.nix-let nixos/tests/containers-reloadable.nix- client_base = { -- nixos/tests/jackett.nix:import ./make-test-python.nix ({ lib, ... }: nixos/tests/jackett.nix- nixos/tests/jackett.nix-with lib; -- nixos/tests/samba-wsdd.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/samba-wsdd.nix- nixos/tests/samba-wsdd.nix-{ -- nixos/tests/enlightenment.nix:import ./make-test-python.nix ({ pkgs, ...} : nixos/tests/enlightenment.nix-{ nixos/tests/enlightenment.nix- name = "enlightenment"; -- nixos/tests/quagga.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/quagga.nix- let nixos/tests/quagga.nix- -- nixos/tests/vault-postgresql.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/vault-postgresql.nix-{ nixos/tests/vault-postgresql.nix- name = "vault-postgresql"; -- nixos/tests/borgbackup.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/borgbackup.nix- nixos/tests/borgbackup.nix-let -- nixos/tests/lxd.nix:import ./make-test-python.nix ({ pkgs, ...} : nixos/tests/lxd.nix- nixos/tests/lxd.nix-let -- nixos/tests/upnp.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/upnp.nix- nixos/tests/upnp.nix-let -- nixos/tests/knot.nix:import ./make-test-python.nix ({ pkgs, lib, ...} : nixos/tests/knot.nix-let nixos/tests/knot.nix- common = { -- nixos/tests/mpd.nix:import ./make-test-python.nix ({ pkgs, lib, ... }: nixos/tests/mpd.nix- let nixos/tests/mpd.nix- track = pkgs.fetchurl { -- nixos/tests/yabar.nix:import ./make-test-python.nix ({ pkgs, lib, ... }: nixos/tests/yabar.nix- nixos/tests/yabar.nix-with lib; -- nixos/tests/nfs/simple.nix:import ../make-test-python.nix ({ pkgs, version ? 4, ... }: nixos/tests/nfs/simple.nix- nixos/tests/nfs/simple.nix-let -- nixos/tests/nfs/kerberos.nix:import ../make-test-python.nix ({ pkgs, lib, ... }: nixos/tests/nfs/kerberos.nix- nixos/tests/nfs/kerberos.nix-with lib; -- nixos/tests/atd.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/atd.nix- nixos/tests/atd.nix-{ -- nixos/tests/grafana.nix:import ./make-test-python.nix ({ lib, pkgs, ... }: nixos/tests/grafana.nix- nixos/tests/grafana.nix-let -- nixos/tests/wireguard/basic.nix:import ../make-test-python.nix ({ pkgs, lib, ...} : nixos/tests/wireguard/basic.nix- let nixos/tests/wireguard/basic.nix- wg-snakeoil-keys = import ./snakeoil-keys.nix; -- nixos/tests/wordpress.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/wordpress.nix- nixos/tests/wordpress.nix-{ -- nixos/tests/ceph-single-node.nix:import ./make-test-python.nix ({pkgs, lib, ...}: nixos/tests/ceph-single-node.nix- nixos/tests/ceph-single-node.nix-let -- nixos/tests/bittorrent.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/bittorrent.nix- nixos/tests/bittorrent.nix-let -- nixos/tests/wireguard/wg-quick.nix:import ../make-test-python.nix ({ pkgs, lib, ... }: nixos/tests/wireguard/wg-quick.nix- let nixos/tests/wireguard/wg-quick.nix- wg-snakeoil-keys = import ./snakeoil-keys.nix; -- nixos/tests/mysql/mariadb-galera-rsync.nix:import ./../make-test-python.nix ({ pkgs, ...} : nixos/tests/mysql/mariadb-galera-rsync.nix- nixos/tests/mysql/mariadb-galera-rsync.nix-let -- nixos/tests/mysql/mysql-replication.nix:import ./../make-test-python.nix ({ pkgs, ...} : nixos/tests/mysql/mysql-replication.nix- nixos/tests/mysql/mysql-replication.nix-let -- nixos/tests/graphite.nix:import ./make-test-python.nix ({ pkgs, ... } : nixos/tests/graphite.nix-{ nixos/tests/graphite.nix- name = "graphite"; -- nixos/tests/mailcatcher.nix:import ./make-test-python.nix ({ lib, ... }: nixos/tests/mailcatcher.nix- nixos/tests/mailcatcher.nix-{ -- nixos/tests/tinc/default.nix:import ../make-test-python.nix ({ lib, ... }: nixos/tests/tinc/default.nix- let nixos/tests/tinc/default.nix- snakeoil-keys = import ./snakeoil-keys.nix; -- nixos/tests/n8n.nix:import ./make-test-python.nix ({ lib, ... }: nixos/tests/n8n.nix- nixos/tests/n8n.nix-with lib; -- nixos/tests/unbound.nix:import ./make-test-python.nix ({ pkgs, lib, ... }: nixos/tests/unbound.nix- let nixos/tests/unbound.nix- # common client configuration that we can just use for the multitude of -- nixos/tests/miniflux.nix:import ./make-test-python.nix ({ pkgs, lib, ... }: nixos/tests/miniflux.nix- nixos/tests/miniflux.nix-let -- nixos/tests/os-prober.nix:import ./make-test-python.nix ({pkgs, lib, ...}: nixos/tests/os-prober.nix-let nixos/tests/os-prober.nix- # A filesystem image with a (presumably) bootable debian -- nixos/tests/samba.nix:import ./make-test-python.nix ({ pkgs, ... }: nixos/tests/samba.nix- nixos/tests/samba.nix-{ -- nixos/tests/snapcast.nix:import ./make-test-python.nix ({ pkgs, ...} : nixos/tests/snapcast.nix- nixos/tests/snapcast.nix-let -- nixos/tests/fontconfig-default-fonts.nix:import ./make-test-python.nix ({ lib, ... }: nixos/tests/fontconfig-default-fonts.nix-{ nixos/tests/fontconfig-default-fonts.nix- name = "fontconfig-default-fonts"; -- nixos/tests/pam-oath-login.nix:import ./make-test-python.nix ({ ... }: nixos/tests/pam-oath-login.nix- nixos/tests/pam-oath-login.nix-let -- nixos/tests/web-servers/unit-php.nix:import ../make-test-python.nix ({pkgs, ...}: nixos/tests/web-servers/unit-php.nix- let nixos/tests/web-servers/unit-php.nix- testdir = pkgs.writeTextDir "www/info.php" "
Rizary commented 3 years ago

@aij I update your comment for better views by adding <details></details>. You can't remove if you don't like it, but I hope you don't mind.

For your concern, it's fair and we should think about it.