News for hackers. Stuff that matters.
Re:Systemd Home Directories by kbumsik on Monday February 10, 2020 @12:18AM (#22286589)
I don't understand why they are using JSON, especially systemd already use an INI-like config format extensively.

Maybe because they are not web devs so that they haven't had an annoying moment when they realize there is no proper way to add comments in package.json?

Re:Systemd Home Directories by viraptor on Monday February 10, 2020 @01:26AM (#22286850)
https://systemd.io/USER_RECORD/

> Why JSON?

> JSON is nicely extensible and widely used. In particular it’s easy to synthesize and process with numerous programming languages. It’s particularly popular in the web communities, which hopefully should make it easy to link user credential data from the web and from local systems more closely together.

Re:Systemd Home Directories by jmcs on Monday February 10, 2020 @07:59AM (#22288684)
> It’s particularly popular in the web communities, which hopefully should make it easy to link user credential data from the web and from local systems more closely together.

Was this written by a CSI or NCIS screenwriter?

Re:Systemd Home Directories by throwaway17_17 on Monday February 10, 2020 @09:06AM (#22289171)
I’m not asking rhetorically:

Is a closer coupling between ‘the Web’ and local systems (especially concerning login and personal id) really what anyone needs?

I don’t even think it’s what anyone really wants, but sure, let’s find a way to make some random server located somewhere run by some SaaS be responsible for negotiating rights to access our own hardware.

Re:Systemd Home Directories by GauntletWizard on Monday February 10, 2020 @05:20PM (#22294028)
https://news.ycombinator.com/item?id=22287174 was on the front page of HN in the last 24h. Yes, web access to hardware is a top priority, because for a large portion of everywhere compute hardware is leased by the hour.

It may not be the only way to access things, and I don't think the systemd maintainers will argue with you over the importance of single-box authentication robustness, only that compatibility is worthwhile and among the arbitrary formats there is a clear winner.

Re:Systemd Home Directories by throw0101a on Monday February 10, 2020 @01:20PM (#22291700)
> ... should make it easy to link user credential data from the web and from local systems more closely together.

Why would anyone want to do such a thing? This sounds like an anti-feature (non-goal?) to me.

Re:Systemd Home Directories by opless on Monday February 10, 2020 @06:54AM (#22288332)
I don’t understand it either.

JSON and YAML do not belong in *nix config files.

What else will systemd do next? Audio? Kernel functions? Send mail? Read news? Become a web browser?

Re:Systemd Home Directories by LessDmesg on Monday February 10, 2020 @07:53AM (#22288635)
Become Windows. That was Red Hat's plan all along. And then your personal data will end up on their cloud like with Win10.
Re:Systemd Home Directories by syshum on Monday February 10, 2020 @09:04AM (#22289161)
it took IBM 4 years before it ruined Weather Underground and injected its corporate cancer on the Apps and Sites

So I figure it will no later then 2023 before RedHat becomes IBM...

Re:Systemd Home Directories by catalogia on Monday February 10, 2020 @07:06PM (#22294770)
TIL IBM bought the Weather Channel a few short years after the Weather Channel bought Weather Underground.
Re:Systemd Home Directories by Spivak on Monday February 10, 2020 @09:56AM (#22289592)
I can agree with JSON being inappropriate in some circumstances but YAML is a super ergonomic config format.

It gives you lots of niceties when you editing a file by hand and then you can just output a JSON object if you're generating the config with code.

It's my favorite thing ever to do something like:

    - name: Configure $service.
      copy:
        dest: /path/to/config.yml
        content: >-
        ---
        {{ config_obj | to_nice_json }}
in Ansible.
Re:Systemd Home Directories by edejong on Monday February 10, 2020 @09:59AM (#22289618)
YAML is probably the least ergonomic configuration format available. [1] Even XML would be preferable, as at least most XML parsers are interchangable.

[1] https://www.arp242.net/yaml-config.html

Re:Systemd Home Directories by jrockway on Monday February 10, 2020 @10:50AM (#22290095)
I don't think YAML is the least ergonomic configuration format available. It has comments, unlike JSON.

YAML's super clever upgrading of strings into other types is irritating ("foo: yes" is type {foo boolean}). Indentation-based semantics are not for everyone, and I think most of us would not mind the "noise" of braces. Other than that it's pretty OK. It's easy to write code that reads and writes it. It's very easy to read. It's above average but not prefect for writing (again, braces are pretty okay, not sure why they went the indentation route).

I agree with the article you linked that a lot of YAML implementations in scripting languages do dumb things like letting you put code in the file, and they all parse their special features differently. A config format does not need to be portable; while all these implementations do different things, they follow a format that continues to allow something to parse the entire file. So you can write an auto-formatter in Javascript (prettier) even though a Go program (kubectl) is going to actually read the file, and it all works.

I have used many other formats for config files. They all suffer from their fair share of problems. TOML/INI handles nesting very poorly (making you retype the names of all parent keys). JSON doesn't let you write comments or trailing commas, so it's hard to work on in your editor (running prettier on save fixes the trailing commas though). Text protobuffers are great but people look at you weird when you use them.

XML is a travesty. It is hard to write and hard to parse. It does all sorts of confusing things that humans do not expect, so it's really more of a binary format for computers to use than a text format for humans to write. (Remember, the XML spec says:

    <foo>
       bar
    </foo>
is different from "<foo>bar</foo>" even though humans think they're the same.)

XPath querying is great, I love it. But we have "jq" now that works on JSON and YAML.

Anyway, I think YAML is basically a fine format for config files. Perfect? Nope. OK? Yup. I will happily read or write a YAML file in a computer program or by hand. It's pretty OK.

Re:Systemd Home Directories by throw0101a on Monday February 10, 2020 @01:23PM (#22291732)
> I don't think YAML is the least ergonomic configuration format available. It has comments, unlike JSON.

This is because JSON is not a configuration format but a machine-to-machine data exchange format. Using it for configurations is using it for something it was not designed to do.

And comments were left out of JSON on purpose:

> Comments were purposefully excluded from JSON. In 2012, Douglas Crockford described his design decision thus: "I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability." [27]

* https://en.wikipedia.org/wiki/JSON#Data_portability_issues

Re:Systemd Home Directories by 0xffff2 on Monday February 10, 2020 @11:33AM (#22290602)
> It's easy to write code that reads and writes it.

This is where you lose me. AFAICT, no two YAML parsers agree on what YAML is, so it's actually very hard to write code that reads and writes YAML because it has to be carefully tailored to work with whatever other YAML parsers are in your toolchain.

Re:Systemd Home Directories by jrockway on Monday February 10, 2020 @11:50AM (#22290776)
I agree that you won't end up with a compatible data structure in every language, but you can read it in and write out a semantically-identical document, which is nice.
Re:Systemd Home Directories by mangecoeur on Monday February 10, 2020 @09:25AM (#22289328)
AFAICT JSON user records are only about serializing data to disk and between systemd components, not to be used as configuration files.
Re:Systemd Home Directories by fctorial on Monday February 10, 2020 @07:22AM (#22288479)

    {
        ...
        "comment": "this is a comment",
        ...
    }
Re:Systemd Home Directories by laumars on Monday February 10, 2020 @07:50AM (#22288620)
Comments are meant to stand apart from code, which that doesn't. Also that would only work if your JSON doesn't have a schema or the importing tool is lazy (ie doesn't validate properties against an expected structure).
Re:Systemd Home Directories by RabbiPires on Monday February 10, 2020 @09:07AM (#22289181)
User editable files should _not_ be in JSON. TOML, YAML or heck, even INI (which is already in use by systemd anyway!) is better.
Re:Systemd Home Directories by switch007 on Monday February 10, 2020 @07:49AM (#22288612)
Is that a comment...or a key called "comment"? :p

Surely "#__comment__!11!!1#" would reduce the confusion !

Re:Systemd Home Directories by jolmg on Monday February 10, 2020 @06:31PM (#22294542)
Or you know, you can just do your language equivalent of:

  grep -Pv '^\s*#'
to remove comments, passing the output of that to the JSON parser. The extension could be modified to .cjson, .json.commented, or something.

Good thing JSON doesn't permit literal newlines in strings. Any valid JSON should be able to go through that comment filter without getting modified.

Re:Systemd Home Directories by catalogia on Monday February 10, 2020 @07:09PM (#22294780)
That's nice and all, but you'll still have trouble reinserting those comments when writing JSON. And if you don't have that, you have a config file which can only be read, not written. And if you accept that, then what was the point of using JSON in the first place?
Re:Systemd Home Directories by jolmg on Monday February 10, 2020 @07:20PM (#22294847)
> you'll still have trouble reinserting those comments when writing JSON.

Sure. I wouldn't even try.

> And if you don't have that, you have a config file which can only be read, not written.

Just like most config files.

> And if you accept that, then what was the point of using JSON in the first place?

To not define your own format and be able to use ready-made parsers.

It's not like I'm advocating for the use of JSON over other choices like YAML. I'm just replying to a comment about how to add comments to a JSON with a better alternative. If someone wants to use JSON over other choices for whatever reason and the only thing holding them back is the lack of comments, then this is a valid way to add comments, I believe.

If you use a string property, you can't split your comment among multiple lines. You could perhaps do an array of strings or something, but I think adding a simple commenting syntax like this is neater.

EDIT: Fixed double negative in penultimate paragraph.

Re:Systemd Home Directories by skywhopper on Monday February 10, 2020 @07:29AM (#22288513)
Yeah, that doesn’t scale very well...
Re:Systemd Home Directories by fctorial on Monday February 10, 2020 @08:15AM (#22288802)
Put cursor after "t" in "comment" and slap your keyboard.
Re:Systemd Home Directories by kbumsik on Tuesday February 11, 2020 @02:54AM (#22296840)
That is not a "proper" comment though.
Re:Systemd Home Directories by _pmf_ on Monday February 10, 2020 @10:15AM (#22289751)
Because having the inevitable dozens of "why JSON" discussions at the beginning is much less tiring than having tens of thousands of "why not JSON" discussions throughout the project history.