# Apparmor default profiles

**URL:** https://discourse.nixos.org/t/apparmor-default-profiles/16780
**Category:** Help
**Created:** [December 25, 2021, 1:19pm UTC](https://discourse.nixos.org/t/apparmor-default-profiles/16780 "2021-12-25T13:19:56Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![spacegreg](https://discourse.nixos.org/user_avatar/discourse.nixos.org/spacegreg/32/4726_2.png) [@spacegreg](https://discourse.nixos.org/u/spacegreg)
#### Post date: [December 25, 2021, 1:19pm UTC](https://discourse.nixos.org/t/apparmor-default-profiles/16780/1 "2021-12-25T13:19:56Z")

</div>

When trying to enable Apparmor on NixOS (I did some tinkering a while ago in Ubuntu), I got puzzled by the current state of affairs. With just `security.apparmor.enable = true` the profiles from `apparmor-profiles` aren’t loaded (`aa-status` shows only 4 ping profiles loaded; note that `apparmor-profiles` package is installed anyway). From what I understood, the only declarative loading method is to use `security.apparmor.policies.<name>` and paste the profile contents into `profiles` attribute. My questions:

1. What is meant by “policy”? Apparmor docs are quite vague on that term, option docs are somewhat confusing.
2. How can be profiles from `apparmor-profiles` (or any other package) loaded? Copying file contents e.g. via `lib.readFile` seems inefficient and inelegant to me.

P.S. @julm

---

<div class="post-metadata">

### Author: ![nixinator](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nixinator/32/3859_2.png) [@nixinator](https://discourse.nixos.org/u/nixinator)
#### Post date: [December 26, 2021, 1:17am UTC](https://discourse.nixos.org/t/apparmor-default-profiles/16780/2 "2021-12-26T01:17:04Z")

</div>

> [@spacegreg](#):
>
> security.apparmor.enable

> **[context:global lang:nix … - Sourcegraph](https://sourcegraph.com/search?q=context:global%2Blang:nix%2Bsecurity.apparmor.enable&patternType=literal)**
>
> Search across 2 million+ open source repositories for free. Powered by Sourcegraph Code Search.

doesn’t really yield many results…

there is a nixos test for it, but it not very self explanatory…

there seems to be some action here.

[https://sourcegraph.com/github.com/nixcon/nixcon-video-infra/-/blob/nixpkgs/nixos/modules/services/torrent/transmission.nix](https://sourcegraph.com/github.com/nixcon/nixcon-video-infra/-/blob/nixpkgs/nixos/modules/services/torrent/transmission.nix)

that might help you with some examples.

---

<div class="post-metadata">

### Author: ![spacegreg](https://discourse.nixos.org/user_avatar/discourse.nixos.org/spacegreg/32/4726_2.png) [@spacegreg](https://discourse.nixos.org/u/spacegreg)
#### Post date: [December 26, 2021, 10:33am UTC](https://discourse.nixos.org/t/apparmor-default-profiles/16780/3 "2021-12-26T10:33:30Z")

</div>

Thanks for reply! In case of transmission, they seem to directly write a profile in their config, while I would prefer more automatic solution.

---

<div class="post-metadata">

### Author: ![nixinator](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nixinator/32/3859_2.png) [@nixinator](https://discourse.nixos.org/u/nixinator)
#### Post date: [December 26, 2021, 10:37am UTC](https://discourse.nixos.org/t/apparmor-default-profiles/16780/4 "2021-12-26T10:37:52Z")

</div>

on a side note, in the new year , i’m thinking of starting a new site, called Nix bounties or something , where you can offer crypto or $$$ or amazon wish list or some other currency to incentivise fixes for financial gain.

Nix is now at a size where this might be actually be viable.

---

<div class="post-metadata">

### Author: ![julm](https://discourse.nixos.org/user_avatar/discourse.nixos.org/julm/32/9530_2.png) [@julm](https://discourse.nixos.org/u/julm)
#### Post date: [December 30, 2021, 9:33pm UTC](https://discourse.nixos.org/t/apparmor-default-profiles/16780/5 "2021-12-30T21:33:01Z")

</div>

@spacegreg, the only profiles from `apparmor-profiles` which have been adapted to NixOS so far are those in `abstractions/` and `tunables/`, see [nixos/modules/security/apparmor/includes.nix](https://github.com/NixOS/nixpkgs/blob/2acaef7a85356329f750819a0e7c3bb4a98c13fe/nixos/modules/security/apparmor/includes.nix), they’re commonly used with the `include` keyword in applications’ profiles (eg. `include <abstractions/base>`).

Most of the content of profiles should be written in Nixpkgs’ `pkgs/` in a `postInstall` defining an `apparmor` output. Those profiles use `include`s and `apparmorRulesFromClosure` as much as possible, and include a `local/` customization (eg. `include <local/bin.transmission-daemon>`) which will then be optionally created by NixOS to add rules to the profile if need be (in this example, by setting `security.apparmor.includes."local/bin.transmission-daemon"`).

Currently application profiles should be defined using `security.apparmor.policies."bin.transmission-daemon".profile` to include the profile from Nixpkgs (eg. `include "${pkgs.transmission.apparmor}/bin.transmission-daemon"`), but thinking about it, we should maybe load those profiles from `environment.systemPackages` like `.desktop` files, using `environment.pathsToLink` and `environment.extraSetup`.

The term `policies` in `security.apparmor.policies` does not really match something in AppArmor, I just needed a term to gather under the same name, the three options `enable`, `enforce` (whether to forbid or just report unallowed access), and `profile` (the rules for some executable paths).

---

<div class="post-metadata">

### Author: ![spacegreg](https://discourse.nixos.org/user_avatar/discourse.nixos.org/spacegreg/32/4726_2.png) [@spacegreg](https://discourse.nixos.org/u/spacegreg)
#### Post date: [January 15, 2022, 9:13pm UTC](https://discourse.nixos.org/t/apparmor-default-profiles/16780/6 "2022-01-15T21:13:25Z")

</div>

Thanks a lot for the answer! It makes a lot of things clearer. Seems that there’s a separate effort needed to bring ready-to-use apparmor profiles to more packages.

---

<div class="post-metadata">

### Author: ![daveman1010220](https://discourse.nixos.org/user_avatar/discourse.nixos.org/daveman1010220/32/490_2.png) [@daveman1010220](https://discourse.nixos.org/u/daveman1010220)
#### Post date: [November 25, 2024, 1:20am UTC](https://discourse.nixos.org/t/apparmor-default-profiles/16780/7 "2024-11-25T01:20:42Z")

</div>

Has the state of AppArmor in NixOS changed in recent years? I’ve been trying to get AppArmor to do something useful for days now, to no avail. The profiles packages seem to be invalid, in that they’re installed and the paths they are watching are not valid nix paths, so none of the profiles actually do anything. I tried modifying a few of them directly, embedding them in profile = ‘’ … ‘’; within my configuration, but the efforts have been futile. The profiles are complex and nest other profiles, so you end up down a rabbithole of profiles that need to be modified to understand nix paths, in order for anything remotely complex to function. Even aa-genprof doesn’t really work, as it doesn’t understand systemd journal. I’m currently trying to get it to work with auditd, since auditd is supposed to be readable by aa-genprof.

I’m all for putting in some work to get this working, but I’m a bit out of my depth. The complexity of AppArmor ramps up fast and getting anything working is quite difficult. The profile packages seem to be in a state that they should probably be removed until they do something useful, that includes both the apparmor-profiles option and the roddhjav AppArmor profiles. None of them really do anything.

A bit off-topic for this particular thread, but I ran into much the same sorts of dead-ends, attempting to get SeLinux to work on NixOS. Does anyone know of efforts to get either of these working?

---

<div class="post-metadata">

### Author: ![hexa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/hexa/32/1300_2.png) [@hexa](https://discourse.nixos.org/u/hexa)
#### Post date: [November 25, 2024, 1:55am UTC](https://discourse.nixos.org/t/apparmor-default-profiles/16780/8 "2024-11-25T01:55:33Z")

</div>

There is ongoing work on AppArmor that needs to be reviewed

> <https://github.com/NixOS/nixpkgs/pull/356796>
>
> \<!--
> ^ Please summarise the changes you have done and explain why they are nece…ssary here ^
> 
> For package updates please link to a changelog or describe changes, this helps your fellow maintainers discover breaking updates.
> For new packages please briefly describe the package or provide a link to its homepage.
> \--\>
> 
> AppArmor profiles are files written to \`/etc/apparmor.d/\<name\>\`. Previously, profiles were defined with a string and written to a store entry, then linked into the etc path. However, this makes little sense if one wants to use profiles that are already files in the nix store, e.g. when using rules from \`roddhjav-apparmor-rules\` (which is absolutely broken currently, but that is a different topic; PR for that coming eventually). This change in the module exposes an option \`security.apparmor.policies.\<name\>.path\` with which a path to a profile can be directly symlinked into the apparmor directory, without first reading and rewriting that file into nix store again. This should boost nixos eval times on systems using prebuilt apparmor rules and makes prebuilding/caching apparmor rulesets via nix possible.
> 
> AppArmor profiles always fall within a tristate of \`enable\`, \`disable\`, \`complain\`. It makes no sense to have two boolean options instead of a neat enum config for the tristate. Therefore, i added that tristate, removing the two bools in the process.
> 
> The apparmor nixos test breaks often. While testing this PR, i noticed the test failing on master/nixos-unstable too. Therefore, i included a fix to the nixos test.
> 
> Yes, the two removed bools are a breaking change. However, the path option addition is inert, it does not break definitions of apparmor policies defined via string.
> 
> \## Things done
> 
> 
> 
> \- Built on platform(s)
> - \[x\] x86\_64-linux
> - \[\] aarch64-linux
> - \[\] x86\_64-darwin
> - \[\] aarch64-darwin
> \- For non-Linux: Is sandboxing enabled in \`nix.conf\`? (See \[Nix manual\](https://nixos.org/manual/nix/stable/command-ref/conf-file.html))
> - \[\] \`sandbox = relaxed\`
> - \[\] \`sandbox = true\`
> \- \[x\] Tested, as applicable:
> - \[NixOS test(s)\](https://nixos.org/manual/nixos/unstable/index.html#sec-nixos-tests) (look inside \[nixos/tests\](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests))
> - and/or \[package tests\](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#package-tests)
> - or, for functions and "core" functionality, tests in \[lib/tests\](https://github.com/NixOS/nixpkgs/blob/master/lib/tests) or \[pkgs/test\](https://github.com/NixOS/nixpkgs/blob/master/pkgs/test)
> - made sure NixOS tests are \[linked\](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#linking-nixos-module-tests-to-a-package) to the relevant packages
> \- \[\] 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\](https://github.com/Mic92/nixpkgs-review#usage)
> \- \[\] Tested basic functionality of all binary files (usually in \`./result/bin/\`)
> \- \[25.05 Release Notes\](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2505.section.md) (or backporting \[24.11\](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2411.section.md) and \[25.05\](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2505.section.md) Release notes)
> - \[x\] (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
> \- \[x\] Fits \[CONTRIBUTING.md\](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md).
> 
> \<!--
> To help with the large amounts of pull requests, we would appreciate your
> reviews of other pull requests, especially simple package updates. Just leave a
> comment describing what you have tested in the relevant package/service.
> Reviewing helps to reduce the average time-to-merge for everyone.
> Thanks a lot if you do!
> 
> List of open PRs: https://github.com/NixOS/nixpkgs/pulls
> Reviewing guidelines: https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#reviewing-contributions
> \--\>
> 
> \---
> 
> Add a :+1: \[reaction\] to \[pull requests you find important\].
> 
> \[reaction\]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
> \[pull requests you find important\]: https://github.com/NixOS/nixpkgs/pulls?q=is%3Aopen+sort%3Areactions-%2B1-desc

The author (@Grimmauld) has published two posts about their plans for AppArmor on NixOS:

- [AppArmor and apparmor.d on NixOS - HedgeDoc](https://hedgedoc.grimmauld.de/s/hWcvJEniW#)
- [The Glob is dead, long live the alias! - AppArmor on NixOS Part 2 - HedgeDoc](https://hedgedoc.grimmauld.de/s/03eJUe0X3#)
