News for hackers. Stuff that matters.
Re:GNU Shepherd by georgyo on Saturday June 03, 2017 @05:00AM (#14475583)
A service file looks like this:

  (register-services
    (make <service>
          #:provides '(apache-2.0 apache httpd)
          #:requires '()
          #:start (...)
          #:stop (...)
          #:actions (make-actions
                     (reload-modules (...))
                     (restart (...)))))

It not horrible, but I'm Not a huge fan of that, but maybe it will get much better as it matures.
Re:GNU Shepherd by ymse on Saturday June 03, 2017 @10:27AM (#14476514)
Here is a complete (and simpler) example, taken from my ~/.config/shepherd/init.scm:

  (define xscreensaver (make <service>
                         #:provides '(xscreensaver)
                         #:start (make-forkexec-constructor
                                  (list "/run/setuid-programs/xscreensaver" "-nosplash"))
                         #:stop (make-kill-destructor)))
  (register-services xscreensaver)
Re:GNU Shepherd by coldtea on Saturday June 03, 2017 @01:44PM (#14477472)
Any reason for the fugly #: syntax? That's mandated by Guile?
Re:GNU Shepherd by Avshalom on Saturday June 03, 2017 @02:17PM (#14477642)
They're keyword arguments, I suspect the #: prefix was chose precisely because it is ugly so it'll almost never conflict with a name a programmer might actually want to give as an argument, Racket uses it too. http://docs.racket-lang.org/guide/keywords.html
Re:GNU Shepherd by rekado on Saturday June 03, 2017 @05:30PM (#14478597)
The # is extensible reader syntax. You can install your own readers for characters following the #. #\ is for the character reader, #: for keywords, etc.

Guix uses #~ for G-expressions, for example.

Re:GNU Shepherd by reirob on Saturday June 03, 2017 @08:50PM (#14479330)
Thanks for providing the link to the documentation in Racket. For people like me who don't know how to program in Scheme, this quote from the documentation might make it click (it is at the end of the page):

Despite their similarities, keywords are used in a different way than identifiers or symbols. Keywords are intended for use (unquoted) as special markers in argument lists and in certain syntactic forms. For run-time flags and enumerations, use symbols instead of keywords. The example below illustrates the distinct roles of keywords and symbols.

Examples:

    > (define dir (find-system-path 'temp-dir)) ; not '#:temp-dir
    > (with-output-to-file (build-path dir "stuff.txt")
        (lambda () (printf "example\n"))
        ; optional #:mode argument can be 'text or 'binary
        #:mode 'text
        ; optional #:exists argument can be 'replace, 'truncate, ...
        #:exists 'replace)
Re:GNU Shepherd by snakeanus on Saturday June 03, 2017 @06:29AM (#14475738)
I find it quite comfortable actually. Same goes for all of Guix.
Re:GNU Shepherd by agumonkey on Saturday June 03, 2017 @05:25AM (#14475615)
reminds me of emacs config file, john wiegley made a tiny dsl called use-package that made everything cuter by a few simplification here and there. A few iteration it became extremely nice to write and read.
Re:GNU Shepherd by rbanffy on Saturday June 03, 2017 @09:24AM (#14476271)
Remember the Emacs config file is not a configuration file: it is actually a program that's run as Emacs starts. You can do all sorts of interesting stuff (like installing missing packages, setting font size according to the screen, etc) on it.
Re:GNU Shepherd by agumonkey on Saturday June 03, 2017 @10:07AM (#14476447)
Well config vs program is a deep debate. Now J.Wiegley extension brings some resemblance of semantics because it has a few concepts and steps instead of free form imperative (setq ...)
Re:GNU Shepherd by mitchty on Saturday June 03, 2017 @02:40PM (#14477760)
I love use-package, has made my emacs init.el config file sooooo much more maintainable from its prior... lets just say mess.
Re:GNU Shepherd by agumonkey on Saturday June 03, 2017 @02:52PM (#14477838)
Some people, smart and famous, still use vanilla emacs config/loading mechanisms (ensuring lazy loading).

I now use req-package so I don't even have to download anything.

I do miss the old style of one file per "kind" though. Doesn't mean use-package is bad but somehow I like having a FS-level idea of my emacs config.

Re:GNU Shepherd by mitchty on Saturday June 03, 2017 @03:19PM (#14477966)
I'm one of those weirdos that sticks my config into org mode files too.

https://github.com/mitchty/dotfiles/blob/master/emacs.org

(actually i use org mode to compile all of my dot files based on predicates, i'm double plus weird here >.<)

I really rather like this way of working with things as it just sticks stuff into ~/.emacs.d/elpa. I can rsync that around if i need/want. And it even bootstraps itself if i'm opening things on a new system. I just like keeping each package in its own use-package declaration so I can have config+setup all in one spot.

Re:GNU Shepherd by agumonkey on Saturday June 03, 2017 @04:22PM (#14478289)
I planned to do that too. Having a readable.. even story tellable code instead of a too succint result of brain sweat.

I might try to make one from scratch using yours as an inspiration. Just to see how my mindset evolved along the years.

Re:GNU Shepherd by mitchty on Saturday June 03, 2017 @04:37PM (#14478354)
Go for it, its mostly inspired from nix in how I set it up. I can just run make and create dot files for whatever I need then rsync it over to where I need it.

Aka I can customize my dot files based on if i'm going to a bsd/mac/linux box with(out)/nix/perl/haskell/git/whatever and have an easy way to copy things over the top of things or not.

I declared dot file bankruptcy a few years ago and this is my "perpetual penultimate dot file solution" (yes I'm making a joke at my own expense with penultimate here).

But this new setup is easily the most sane I've found so far. Most dot file management uses softlinks which sucks for rsyncing, or some hokey templating language.

All mine amounts to is just a stupid .el file that holds predicate definitions that just controls via stupid elisp when an org babel block gets tangled out into a file. Its pretty simple and straightforward. Wonder if I should do some sort of show and tell for it or not.

Good luck! Hope it helps or inspires something better.

Re:GNU Shepherd by tmalsburg2 on Saturday June 03, 2017 @06:40AM (#14475768)
I'm curious. Why are you not a huge fan of it?
Re:GNU Shepherd by _wmd on Saturday June 03, 2017 @09:37AM (#14476315)
My first thought is how I'd parse, modify and write it back without losing user's comments, formatting, changes and suchlike. Is this some well understood format with libraries for common programming languages? If not, it is just likely to proliferate more crappy config management with chunks of regexes and suchlike

Elsewhere people are saying it's just Scheme. I'm sure I could find a parser for that in Python, and maybe if I'm really lucky that parser will record whitespace and comment nodes, and have a reverse transformation, but do I really want to be writing error prone 20-line AST visitors just to tweak an integer setting? (No, I most certainly do not, and I consider design decisions like this a massive code smell that'd ward me off any further investigation of a system)

edit: downvotes? Is this really such a difficult concept?

edit 2: so apparently the big whoopsie was insulting the religion that is LISP. Yes, using a turing complete language for config syntax causes pain. Nobody does this stuff in the real world for a reason. Deal with it, meanwhile go back to obsessing over novelty code-is-data academic exercises on your obsolete Symbolics machines, you'll cause less damage that way.

Re:GNU Shepherd by badsectoracula on Saturday June 03, 2017 @11:16AM (#14476755)
So, since nobody mentioned that, i'll ignore your edits and try to answer your original concern. Generally speaking, this is S-Expressions (as others have said) and S-Expressions are trivial to parse and edit - you can write a parser in C that converts this to a tree easily. Note that the comments and such are a problem regardless of the config syntax used but the solution is the same: instead of rewriting the file, edit it in-place (to do that a simple way is store the index range of each node's value in the code buffer when parsing it and when you modify the node's value update the buffer's contents - make sure you also update the other nodes' ranges if the value changes length in characters).

All these assuming you want to implement the thing yourself. Which is fine, S-Expressions are one of the easiest tree syntaxes to parse. But there are already libraries that can do this for you (including full Lisp/Scheme interpreters) and some of them can even 'pretty format' the code like the quoted snipped above.

So generally speaking this wont be a problem in practice.

Re:GNU Shepherd by cyphar on Saturday June 03, 2017 @10:01AM (#14476423)
It's Scheme s-expressions. Parsers for it have existed for it longer than C or Unix have existed (Scheme came out in 1970, First Edition Unix in 1971), let alone Lisp parsers which have existed for even longer.

EDIT: Complaining about downvotes and then going on a tirade about how Lisp users are cave-dwellers is not constructive. Personally I think your argument was a valid concern (and I just went to try to find a Scheme parser in Python to help you), but you're not helping your case.

Also, like it or not, but both of the most widely-used editors (emacs and vim) both have turing-complete "configuration" languages. By your statements, that would make the majority of programmers academic cave-dwellers (oh wait... :P).

Re:GNU Shepherd by eriknstr on Saturday June 03, 2017 @11:49AM (#14476921)
> both of the most widely-used editors (emacs and vim)

https://insights.stackoverflow.com/survey/2017#technology-mo...

If you include full-blown IDEs in your definition of editor (which I think you should), Visual Studio was the most widely used editor among all the 19,772 people that responded to this question in the Stack Overflow Developer survey 2017.

Notepad++ was the second-most popular editor.

Sublime Text was the third-most popular editor.

Vim was the fourth-most popular editor.

Visual Studio Code, IntelliJ, Atom, Eclipse, Android Studio, PHPStorm, Xcode, NetBeans and PyCharm followed.

Emacs was the 14th-most popular editor.

Re:GNU Shepherd by cyphar on Saturday June 03, 2017 @12:03PM (#14476984)
The point still stands if you substitute "both" with "two". I admit that I assumed Emacs and Vim were higher in the "leaderboard" (and I'm not sure StackOverflow is the best place to sample developers) but the point stands regardless.
Re:GNU Shepherd by kazinator on Saturday June 03, 2017 @10:56AM (#14476662)
> using a turing complete language for config syntax causes pain

That may sometimes be so, but only as a general consequence of "programming computers causes pain". You can do something complicated, which can have a bug; then someone comes along with a half-conceived thought like, "that solution shouldn't have been doble in the config language; therefore config language caused pain".

A non-computational config language also causes pain. Sometimes to the point that a Turing-complete language is used to generate a configuration. Then you have pains like "# this was generated ... don't touch!".

Re:GNU Shepherd by mcguire on Saturday June 03, 2017 @10:52AM (#14476639)
As others have pointed out, it's s-expressions (and possibly simply scheme) so reading and writing shouldn't be difficult. If it uses scheme comments, those will be a problem just as when transforming any programming language. I the other hand, if they syntax supports doc-strings, you're all set.

Add far as AST visitors, you're probably better off with XPath/XSLT tree transformations. (Anyone know of a suitable library?)

On the other hand, the don't-swim-upstream approach would be to use one of the best programming languages in existence, Scheme, you do your config management tasks directly, rather than an arm's-length parse, modify, write approach.

Re:GNU Shepherd by openasocket on Saturday June 03, 2017 @11:54AM (#14476945)
So you want to programmatically edit a config file, preserving formatting and comments, without using regexes, AST visitors, or XSLT? What's left? I seriously don't know of any other ways to manipulate data while preserving formatting and comments.
Re:GNU Shepherd by avar on Saturday June 03, 2017 @01:02PM (#14477258)
This isn't applicable to scheme as a config format, but some config formats are line based and have programmatic tools to manipulate them, e.g. the .ini-like format Git uses, try adding some comments to ~/.gitconfig and manipulating it with `git config --global <...>`, it'll all be preserved.

You will lose any comments like this though:

    [user]
        name = My Name ; that's my name!
Programming is hard in the face of arbitrary user data.
Re:GNU Shepherd by _wmd on Saturday June 03, 2017 @12:08PM (#14477004)

    $ cat my-config.xml
    <root>
        <!-- i am a comment -->
        <thing attr="foo">
            <!-- i am another comment -->
            <setting>value</setting>
        </thing>
    </root>
    
    $ cat c.py
    import lxml.etree
    
    doc = lxml.etree.fromstring(file('my-config.xml').read())
    for setting in doc.xpath('.//thing/setting'):
        setting.text = 'set without screwing up the file'
    print lxml.etree.tostring(doc)
    
    $ python c.py
    <root>
        <!-- i am a comment -->
        <thing attr="foo">
            <!-- i am another comment -->
            <setting>set without screwing up the file</setting>
        </thing>
    </root>
Re:GNU Shepherd by openasocket on Saturday June 03, 2017 @02:18PM (#14477645)
... but you just chewed someone out for suggesting XML. And you are doing tree walking here, you're just reducing some of the boilerplate with XPath. You can do the same thing with Scheme using car, cdr, cadr and friends.
Re:GNU Shepherd by _wmd on Saturday June 03, 2017 @02:34PM (#14477723)
The suggestion was to use XSLT to transform Scheme syntax
Re:GNU Shepherd by openasocket on Saturday June 03, 2017 @02:44PM (#14477787)
My mistake then. You can still use car, cdr, cadr etc. to accomplish more or less the same thing as XPath. S-expressions are a completely valid serialization format. You can't easily manipulate JSON or YAML data while preserving formatting and comments with any library I've used (though it is possible), that doesn't mean JSON and YAML are invalid.
Re:GNU Shepherd by mcguire on Sunday June 04, 2017 @09:06PM (#14484657)
XPath and a tree transformation? Works well.
Re:GNU Shepherd by hashkb on Saturday June 03, 2017 @09:54AM (#14476383)
You would just use Guile. That's the magic of the Lisp family.

Edit: downvotes are because you're sort of insulting Lisp (which is older than you and all your "best practices") with an ignorant complaint.

Re:GNU Shepherd by phkahler on Saturday June 03, 2017 @10:25AM (#14476503)
>> downvotes are because you're sort of insulting Lisp (which is older than you and all your "best practices") with an ignorant complaint.

I recognized it as lisp right away, but I share the complaint about the format. If you want to write a lisp program then do so. If you want to format something for human readability it's probably a good idea to do it differently. This is just a opinion of course, but I suspect it's not an uncommon one.

Re:GNU Shepherd by hashkb on Saturday June 03, 2017 @10:32AM (#14476534)
Maybe uncommon over all, but you should definitely expect the GNU project to use Guile for scripting needs. In this context, it's the obvious choice.

Furthermore, anything that tricks you into learning Scheme is a good thing. Like eating vegetables.

Re:GNU Shepherd by wtetzner on Sunday June 04, 2017 @07:28AM (#14480837)
Are you suggesting that Lisp programs aren't readable by humans?
Re:GNU Shepherd by _wmd on Saturday June 03, 2017 @10:32AM (#14476537)
So all I asked is whether it was possible to roundtrip an edit to one of these files from Python without writing an AST visitor, and without losing formatting and comments. I have absolutely no idea how this could be considered ignorant.

Ignorant of the cave-dwelling depths some would go to ensure the practicality of the arcane religious icon that is LISP as a massively overgeneral solution to a problem, at the cost of all downstream users who must now "just switch to Guile" or link against chunks of a C compiler just to introspect a config? Maybe, but I'm content with that.

Re:GNU Shepherd by orangeshark on Saturday June 03, 2017 @12:38PM (#14477140)
So the example you showed with XML uses XPath, what do you think that does? I am sure something similar can be created in python for editing lisp code as easily as this.
Re:GNU Shepherd by _wmd on Saturday June 03, 2017 @01:47PM (#14477481)
> My first thought is how I'd parse, modify and write it back without losing user's comments, formatting, changes and suchlike. Is this some well understood format with libraries for common programming languages? If not, it is just likely to proliferate more crappy config management with chunks of regexes and suchlike

> Elsewhere people are saying it's just Scheme. I'm sure I could find a parser for that in Python, and maybe if I'm really lucky that parser will record whitespace and comment nodes, and have a reverse transformation, but do I really want to be writing error prone 20-line AST visitors just to tweak an integer setting? (No, I most certainly do not, and I consider design decisions like this a massive code smell that'd ward me off any further investigation of a system)

XML satisfies all the above: no AST visitors, no custom parsing routines, no attempting to solve the halting problem in order to introspect a simple scalar value.

What you're saying is that the same is "possible" with Scheme. At least one followup comment (finally) described an algorithm that would actually allow machine-driven file changes, but we're still left with rather than a working out of the box solution, a description of an algorithm that "might someday work" and that's not the sort of thing I want to be dealing with while building business solutions on somebody else's dime, which drives my conclusion above: this config file syntax is not for me, and my original comment explained precisely why.

Re:GNU Shepherd by openasocket on Saturday June 03, 2017 @02:52PM (#14477836)
You're complaining that there isn't good tooling around the config file format for a project that is described as "in its early development stages" and provides "alpha releases". If you're talking about using this "while building business solutions on somebody else's dime" your getting way ahead of yourself. I'm sure they will expose a library for parsing and editing the config format before a general release.
[dead]
Re:GNU Shepherd by openasocket on Saturday June 03, 2017 @05:42PM (#14478652)
You're right, I can't find a python library with the exact functionality you want. But a solution does exist, you would just have to write it yourself. It takes about 200 lines of python, less if you use a parser generator. But if you don't want to do that (nothing wrong with that! Why do work when you don't have to, after all), well then you'll have to either ask someone else to do it for you or just not use this project, assuming this functionality is critical for you. Or you could use sed or a templating system, up to you.
Re:GNU Shepherd by _wmd on Saturday June 03, 2017 @06:07PM (#14478739)
I have little doubt it could be written, but at risk of going blue in the face, this was irrelevant to the original question ("what do you dislike about this syntax?"). Never mind, 'truth' has won out in the end regardless, and I note for future that the presence of Lisp on a CV is fair reason to pause and reconsider.
Re:GNU Shepherd by openasocket on Saturday June 03, 2017 @06:23PM (#14478804)
"My first thought is how I'd parse, modify and write it back without losing user's comments, formatting, changes and suchlike. Is this some well understood format with libraries for common programming languages?"

Sorry for trying to answer your question then...

Re:GNU Shepherd by michaelmrose on Saturday June 03, 2017 @03:12PM (#14477931)
Regarding edit 2: Using a non turing complete language results in hacks to attain the flexibility that would have been provided by the more powerful language.
Re:GNU Shepherd by Slackwise on Saturday June 03, 2017 @05:14PM (#14478537)
And that was kind of the whole point with GuixSD and Shepard.

Nix has limited "Nix-expressions" which resulted in a bunch of bash scripts to get around the limitations, and Systemd ends up requiring C services or bash scripts because it has a limited INI-like syntax. On the opposite end, GuixSD is entirely configured, packaged, and maintained with Guile.

Re:GNU Shepherd by michaelmrose on Saturday June 03, 2017 @03:09PM (#14477920)
My first question would be in what use case do you require the ability to alter via a program the same config file that you expect the user to be able to hand edit and never have a conflict?

It was my understanding that issue was best handled by having multiple files and having one take precedence over the other. Like having a global config that is pushed to the machine and allowing the user to locally override values set globally in the local config.

Another solution to multiple parties needing to define configuration for the same area without stomping all over each other would be to have a directory wherein all files contained therein are applicable. That way multiple people can maintain their own particular files but some precedence has to be established.

Even if you do need to do this I wouldn't think it would be that hard to modify lisp with lisp.

Re:GNU Shepherd by blowski on Saturday June 03, 2017 @11:02AM (#14476683)
I have no dog in this fight, but I downvoted because your subsequent edits are not at all constructive.
Re:GNU Shepherd by brians on Saturday June 03, 2017 @09:39AM (#14476321)
It's Guile s-expressions, so at least there's a good C reader and writer?
Re:GNU Shepherd by gkya on Saturday June 03, 2017 @09:52AM (#14476374)
That's a mere function call in a complete, standards based language.
Re:GNU Shepherd by rnhmjoj on Saturday June 03, 2017 @08:00AM (#14475993)
It may be stupid but that syntax makes me feel a little uneasy. The unmatched single quotes reminds me of TemplateHaskell.
Re:GNU Shepherd by brianon99 on Saturday June 03, 2017 @08:45AM (#14476148)
Single quote denotes a symbol in scheme. But this snippest is not strictly scheme. Perhaps it is SXML but I am not familiar with it.
Re:GNU Shepherd by orangeshark on Saturday June 03, 2017 @09:31AM (#14476298)
A single quote is actually shorthand for the quote special form

  'foo
  (quote foo)
  '(1 2 3)
  (quote (1 2 3))
It basically does not evaluate its arguments but returns whatever it is. So instead of the value of foo, it the symbol foo. The list example does not evaluate it either, it would normally try to apply the first element as a function, but instead we get the list of numbers.
Re:GNU Shepherd by rekado on Saturday June 03, 2017 @09:11AM (#14476232)
This is just Scheme. It's nothing to do with SXML.

#:foo is a keyword argument and '(apache httpd) is a quoted list containing the symbols apache and httpd.

Angled brackets have no special meaning, they are just part of the identifier.

Re:GNU Shepherd by cyphar on Saturday June 03, 2017 @08:49AM (#14476158)
While I don't write Scheme, I believe it is Scheme -- one of the goals of the GNU project is to have every GNU tool be configurable with Scheme (which is why GNU has a Scheme implementation as opposed to a Common LISP implementation).
Re:GNU Shepherd by the_why_of_y on Saturday June 03, 2017 @09:39AM (#14476322)
Not only does GNU have a Common Lisp implementation, in fact there are two:

GCL: https://www.gnu.org/software/gcl/

CLISP: http://clisp.org/

Re:GNU Shepherd by cyphar on Saturday June 03, 2017 @10:04AM (#14476435)
I've installed CLISP before, why didn't I know it was a GNU project? Fair enough, I stand corrected. :D
Re:GNU Shepherd by brians on Saturday June 03, 2017 @09:41AM (#14476328)
Well, they have GCL and CLisp too!
Re:GNU Shepherd by Ericson2314 on Saturday June 03, 2017 @10:00AM (#14476414)
Template Haskell (and Rust) gets this from Lisp, ultimately.
Re:GNU Shepherd by cyphar on Saturday June 03, 2017 @10:03AM (#14476432)
Rust's usage of single quotes comes from CS language theory (lifetimes are denoted using quotes) which I believe comes from the normal usage of quotes in possessive words (James', Amanda's). I don't think LISP's usage comes from the same place (it means something very different semantically).
Re:GNU Shepherd by steveklabnik on Saturday June 03, 2017 @10:47AM (#14476606)
OCaml's usually what I see cited as the reason for Rust adopting the syntax.
Re:GNU Shepherd by mcguire on Saturday June 03, 2017 @11:11AM (#14476732)
... where it's a type variable.

I think we can blame the use for lifetimes entirely on the Rusties.

Re:GNU Shepherd by steveklabnik on Saturday June 03, 2017 @11:58AM (#14476960)
Lifetimes are also types, or more specifically, generic type parameters.
Re:GNU Shepherd by cyphar on Saturday June 03, 2017 @12:14PM (#14477027)
I believe the community name is Rustacean[1].

[1]: http://www.rustaceans.org/

Re:GNU Shepherd by Jtsummers on Saturday June 03, 2017 @10:41AM (#14476564)
Lisp's quote (or ') comes from the word quote and the context:

  (quote something)
Meaning: take whatever follows and leave it alone. Do not interpret it. If it's a list it stays a list (one of the main uses for this). The single quote ' is shorthand for that. It's meant to be an easier way to create a literal list (and other things) without escaping all the parts of a list that might be misinterpreted as symbols to evaluate (to values or functions).
Re:GNU Shepherd by rsync on Saturday June 03, 2017 @12:34PM (#14477120)
"A service file looks like this:"

Am I correct that the equivalent to this service file, in the world of systemd, is a binary file ?

Re:GNU Shepherd by to3m on Saturday June 03, 2017 @12:39PM (#14477154)
Re:GNU Shepherd by majewsky on Saturday June 03, 2017 @01:17PM (#14477346)
Maybe an example is easier to read than a manpage. Here's nginx.service from Arch Linux: https://git.archlinux.org/svntogit/packages.git/tree/trunk/s...
Re:GNU Shepherd by BenjiWiebe on Saturday June 03, 2017 @03:01PM (#14477882)
And I personally love it. When writing my own servers/daemons I can very quickly and easily write a new service file for it.
Re:GNU Shepherd by subway on Saturday June 03, 2017 @12:36PM (#14477134)
You are incorrect. Systems uses plaintext 'ini'-ish files.
Re:GNU Shepherd by rurban on Saturday June 03, 2017 @05:14AM (#14475598)
Much better than XML. A proper and simple language, not just a stupid bloated datastructure, with the ability to naturally define logic in the deps.
Re:GNU Shepherd by sigzero on Saturday June 03, 2017 @11:30AM (#14476821)
It's pretty close to "horrible" though.