Skip to content

Add Nix flake (dev shell + package) - #63

Open
matevl wants to merge 1 commit into
NikolayIT:masterfrom
matevl:feat/nix-flake
Open

matevl wants to merge 1 commit into
NikolayIT:masterfrom
matevl:feat/nix-flake

Conversation

@matevl

@matevl matevl commented Oct 29, 2026 •

Copy link
Copy Markdown

Summary

Adds a Nix flake so the project can be built, run and developed on Nix/NixOS without installing the .NET SDK manually.

Changes

  • flake.nix: provides
    • devShells.default: .NET 10 SDK plus the native libraries Avalonia needs (fontconfig, X11, GL, ...)
    • packages.default: the app built with buildDotnetModule, with LD_LIBRARY_PATH wrapped automatically via runtimeDeps
    • meta.mainProgram, so nix run works
    • Desktop entry and scalable icon installed, so the app appears in launchers
    • bin/ratiomaster-net lowercase alias next to bin/RatioMaster.NET
  • deps.json: NuGet dependencies pinned for the offline Nix sandbox
  • flake.lock: pinned inputs
  • .envrc: use flake for direnv users
  • .gitignore: ignore Nix/direnv artifacts

Build notes

  • PublishSingleFile, EnableCompressionInSingleFile, PublishReadyToRun, PublishTrimmed and PublishAot are disabled through dotnetFlags for the Nix build only. Single-file compression requires a self-contained publish, which conflicts with using the Nix-provided runtime. The regular dotnet publish workflow is unchanged.
  • deps.json must not contain crossgen2/runtime packs: the Nix SDK already provides them, and duplicates break the build.

Usage

nix run github:NikolayIT/RatioMaster.NET   # run
nix build                                  # build into ./result
nix develop                                # dev shell

Updating NuGet dependencies

After changing package versions, regenerate deps.json:

nix shell nixpkgs#nuget-to-json nixpkgs#dotnetCorePackages.sdk_10_0 -c bash -c '
  dotnet restore src/RatioMaster.App/RatioMaster.App.csproj \
    --packages ./nuget-pkgs -p:NuGetAudit=false &&
  nuget-to-json ./nuget-pkgs > deps.json
'
rm -rf nuget-pkgs

If deps.json contains crossgen2 or runtime pack entries (e.g. microsoft.netcore.app.crossgen2.*), remove them.

Testing

  • nix build succeeds on x86_64-linux
  • nix run launches the app

Add a Nix flake providing a dev shell and a packaged build of the
Avalonia app using buildDotnetModule.

- NuGet dependencies are pinned in deps.json for the offline sandbox.
- Single-file, ReadyToRun, trimming and AOT publish options are
  disabled for the Nix build only, since they require a self-contained
  publish and conflict with the Nix-provided runtime.
- Install a desktop entry and icon.svg into the hicolor theme so the
  package shows up in application launchers.
- Expose a lowercase ratiomaster-net alias in bin/.
- Set meta.mainProgram so `nix run` works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant