Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/samba: migrate to structural settings (RFC42) #302681

Merged
merged 8 commits into from
Sep 6, 2024

Conversation

anthonyroussel
Copy link
Member

@anthonyroussel anthonyroussel commented Apr 8, 2024

Description of changes

See RFC42

  • Migrated services.samba.extraConfig to services.samba.settings
  • Renamed services.samba.enableNmbd to nmbd.enable
  • Renamed services.samba.enableWinbind to winbindd.enable
  • Added services.samba.smbd.enable
    • This option will disable the smbd daemon
    • Required to continue the work on samba-ad-dc SystemD service
  • Split SystemD configuration and sync it with upstream

Also see #302645

TODO / Work in progress:

  • Improve new module documentation
  • Fix SystemD services dependencies

Also planned later:

  • Lint module with nixfmt-rfc-style (in another PR)
  • Remove with lib; (in another PR)
  • Migrate enable options to mkEnableOption, and maybe disable them by default (in another PR)
  • Add samba-ad-dc support and ensureDomain provisioner (in another PR)

This PR is a requirement to start the work on Samba AD DC NixOS module.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: documentation This PR adds or changes documentation 8.has: changelog 8.has: module (update) This PR changes an existing module in `nixos/` labels Apr 8, 2024
@anthonyroussel anthonyroussel marked this pull request as draft April 8, 2024 21:48
@anthonyroussel
Copy link
Member Author

anthonyroussel commented Apr 8, 2024

@ofborg test samba

nixos/tests/samba.nix Outdated Show resolved Hide resolved
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Apr 8, 2024
This was referenced Apr 10, 2024
@anthonyroussel anthonyroussel force-pushed the samba-rfc0042 branch 2 times, most recently from 3adf657 to 7d780cc Compare April 12, 2024 12:50
@anthonyroussel anthonyroussel marked this pull request as ready for review April 12, 2024 12:50
@ofborg ofborg bot added 10.rebuild-darwin: 1-10 and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin labels Apr 12, 2024
@anthonyroussel anthonyroussel force-pushed the samba-rfc0042 branch 2 times, most recently from ed753ae to eaf3910 Compare April 30, 2024 20:16
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label May 3, 2024
@anthonyroussel anthonyroussel removed the 2.status: merge conflict This PR has merge conflicts with the target branch label May 8, 2024
@anthonyroussel
Copy link
Member Author

Fixed merge conflict

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label May 22, 2024
@anthonyroussel anthonyroussel removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jun 6, 2024
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/4040

@anthonyroussel
Copy link
Member Author

Rebased against master branch and fixed merge conflict

nixos/doc/manual/release-notes/rl-2411.section.md Outdated Show resolved Hide resolved
nixos/modules/services/network-filesystems/samba.nix Outdated Show resolved Hide resolved
nixos/modules/services/network-filesystems/samba.nix Outdated Show resolved Hide resolved
nixos/modules/services/network-filesystems/samba.nix Outdated Show resolved Hide resolved
nixos/doc/manual/release-notes/rl-2411.section.md Outdated Show resolved Hide resolved
nixos/modules/services/network-filesystems/samba.nix Outdated Show resolved Hide resolved
nixos/modules/services/network-filesystems/samba.nix Outdated Show resolved Hide resolved
nixos/modules/services/network-filesystems/samba.nix Outdated Show resolved Hide resolved
nixos/modules/services/network-filesystems/samba.nix Outdated Show resolved Hide resolved
@anthonyroussel
Copy link
Member Author

Hello @trofi, I noticed that you've recently modified the Samba package.

So I thought you might be interested in reviewing this pull request to migrate the NixOS Samba module to RFC42 :)

@bachp bachp merged commit 88dbefd into NixOS:master Sep 6, 2024
26 of 27 checks passed
@anthonyroussel anthonyroussel deleted the samba-rfc0042 branch September 6, 2024 15:54
@misuzu
Copy link
Contributor

misuzu commented Sep 11, 2024

Looks like the global section must be always on top and after this change it can end up after shares declarations (if they have a name starting with uppercase letter) which breaks everything... It seems the global options are only applied for the shares after the global section, this might even be a security issue.

@dotlambda dotlambda mentioned this pull request Sep 11, 2024
13 tasks
@anthonyroussel
Copy link
Member Author

anthonyroussel commented Sep 11, 2024

@misuzu Hello, thank you for pointing this out.

The smb.conf documentation does not mention anything about the section ordering, especially regarding the special global section.

But yes indeed, you're right, I was able to reproduce the issue you mentioned with the following configuration:

  services.samba = {
    enable = true;
    openFirewall = true;
    settings = {
      global = {
        "guest ok" = true;
      };
      "public" = {
        "path" = "/public";
        "browseable" = "yes";
        "comment" = "Public samba share.";
      };
      "Shared" = {
        "path" = "/shared";
        "browseable" = "yes";
        "comment" = "Shared samba share.";
      };
    };
  };
};

In this configuration, the public share will allow guest access, while the Shared share won't.

I see a few possible ways to address this issue:

  • Split the settings into globalSettings and shareSettings, ensuring that globalSettings appears first in the configuration file and shareSettings after.
  • Use a customized version of pkgs.formats.iniWithGlobalSection to automatically place the global section (and its [global] header) at the top of the configuration file.
  • Revert the PR and restore the previous behavior (no RFC42).

Does anyone have any other ideas?

Unfortunately, I’m not available to work on this today.
Does anyone have any thoughts on whether we should consider reverting my PR, or we wait for me to work on a fix to be merged in a few days?

@bachp
Copy link
Member

bachp commented Sep 11, 2024

@anthonyroussel

There is no need to split the section from a user perspective. We can also do this via somthing along the lines of:

  globalSettings = { global = cfg.settings.global; };
  shareSettings = builtins.removeAttrs cfg.settings [ "global" ];

However I'm not sure how to tell formats.ini to put this two attrsets in the right order.

@bachp
Copy link
Member

bachp commented Sep 11, 2024

@misuzu @anthonyroussel

I think I found a solution in #341257

I just ran the samba module test but did not try yet with the above reproducer if it really fixes the issue. and tired with the above config and with the changes the order is restored.

joegilkes added a commit to joegilkes/nixos-config that referenced this pull request Sep 12, 2024

restartTriggers = [ configFile ];
};
settingsFormat = pkgs.formats.ini { };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Samba settings aren't strict INI so this breaks things - specifically configuring extensions like fruit:appl = yes for enabling the Darwin compatibility layer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Thank you for the feedback.

Could you provide an example where this configuration isn’t working as expected, please?

To configure fruit:appl = yes for vfs_fruit, you can use this syntax:

services.samba.settings.global."fruit:appl" = "yes";

@brookst
Copy link

brookst commented Sep 20, 2024

Hi. I've update the NixOS Wiki article: https://nixos.wiki/index.php?title=Samba&diff=13441&oldid=13357
I think that updates the snippets to be compatible with these changes. Perhaps someone with more familiarity ought to look over that article to see if any info has gone out-of-date.

Cheers!

@bachp
Copy link
Member

bachp commented Sep 20, 2024

Thank you @brookst.

There is also https://wiki.nixos.org/wiki/Samba which is linked from the official nixos.org page. Maybe it makes sense to update there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants