NixOS / NixOS/nixpkgs

starsector: discussion about settings.json

Open
#486,751 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0.kind: enhancement 2.status: stale 6.topic: games
Dominant language
Nix
Stars
26.2k
Forks
20.1k
PR merge metrics
PR metrics pending

Description

Hello! Starsector has a special settings file "settings.json" that has a lot of useful options, such as the option to force a specific resolution (it would be useful for me bacause I have two monitors, and starsector reads the possible resolutions from the wrong one).

However, in the nixpkgs version, this file is part of the derivation in /nix/store/.....-starsector-.../share/starsector/data/config/settings.json, thus impossible to edit.

I tried scratching a basic PR to allow settings to be passed as a derivation argument but I hit into some issues: The JSON used by starsector is far from standard. Not only it has comments, it also has java-style floats, with the 'f' suffix. So, I was not able to process into a nix attrset that could be modified and then converted back into a new settings.json file. I tried using some external tools such as jq and hjson, but the floats just break them.

Here is my non-functional code to illustrate the idea:

  installPhase =
    let
      sanitesedSettings = runCommandLocal "settings.json" { } ''
          # Filtering could happen here too
         cp "${src}/data/config/settings.json" $out
      '';

      defaultSettings = lib.pipe sanitesedSettings [
        builtins.readFile
        (s: lib.splitString "\r\n" s)
        (ss: lib.filter (s: (builtins.match "^[[:space:]]*#.*$" s) == null) ss) # Delete comment lines
        lib.concatLines
        builtins.fromJSON # errors here because it is not valid JSON
      ];

      # The idea would be to merge the defaultSettings above with a settings argument passed to the derivation
      settingsFile = writeText "settings.json" (builtins.toJSON (defaultSettings // settings));
    in
    '' ... '';

Have any of you thought about this? Do you have any ideas?

Pinging my fellow starsector maintaners: @bbigras @sigmasquadron

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Starsector package derivation and its bundled data/config/settings.json; review the non-functional Nix example in the issue and how the derivation currently installs this file. Determine a supported way to expose configurable settings despite comments and Java-style float suffixes, with completion demonstrated by an editable generated settings.json in the package.

Written by the indexing model from the issue text.

Assessment

Tech stack
json
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.